Library / Linux

LINUX-003 · Script

Check and Recover Services

Checks the systemd services you list (or every failed service) and, in fix mode, attempts to restart the ones that are not running, then reports which recovered and which are still down.

Version 1.0.0Language bashUpdated November 2026

What it does

Masked services are reported but never started. Services that are disabled but listed in --services are started in fix mode; they are not enabled, so they will not start on the next boot unless you enable them. The last journal lines of each service that stays down are logged.

Requirements

A Linux distribution that uses systemd. Run as root. No prompts.

How to run it

  • Run from: an admin workstation or scheduled task with the Microsoft modules installed and app sign-in configured
  • This is an admin script for your Linux tenant, not a per-device endpoint script
  • User interaction: none with app-only sign-in
  • Schedule: run on demand, or weekly for reports

Settings

NameWhat it doesOptionsDefault
modedefault reportreport, fixreport
servicescomma-separated service names, for example nginx,sshd,cron; default empty = every failed service
waitdefault 10; seconds to wait after a restart before checking again10
attemptsrestart attempts per service in fix mode; default 11

Exit codes

  • 0 = All checked services are running, or all were recovered
  • 1 = One or more services are down (report mode), missing, or did not recover
  • 2 = Script error

Testing steps

  1. Run it first with the mode set to report on one test account or small group. Nothing is changed in that mode.
  2. Read the log and confirm the planned changes are what you expect.
  3. Run your chosen settings on the same test target and confirm the result.
  4. Check the exit code: 0 = OK, 1 = needs attention, 2 = error (see log), 9 = this copy is past its Valid until date.
  5. Roll out to a small group next, then everyone.

Rollback steps

Report mode changes nothing. Fix mode only restarts services that were already down; to undo, stop the service again with systemctl stop NAME. It never enables, disables or unmasks a service.

Version and change log

VersionDateChanges
1.0.0November 2026First release.