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.
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
| Name | What it does | Options | Default |
|---|---|---|---|
| mode | default report | report, fix | report |
| services | comma-separated service names, for example nginx,sshd,cron; default empty = every failed service | ||
| wait | default 10; seconds to wait after a restart before checking again | 10 | |
| attempts | restart attempts per service in fix mode; default 1 | 1 |
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
- Run it first with the mode set to report on one test account or small group. Nothing is changed in that mode.
- Read the log and confirm the planned changes are what you expect.
- Run your chosen settings on the same test target and confirm the result.
- Check the exit code: 0 = OK, 1 = needs attention, 2 = error (see log), 9 = this copy is past its Valid until date.
- 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
| Version | Date | Changes |
|---|---|---|
| 1.0.0 | November 2026 | First release. |