Keep the site alive
Write the script every small team ends up with: check that services are up, restart what's down, log what happened, warn when the disk is filling up — then schedule it.
Design the script
Write the steps in plain words before writing Bash. For each service: is it active? If not, restart it and log that you did. Then check disk usage on the root filesystem and log a warning above a threshold. Finally, make sure every line written to the log starts with a timestamp, so the team can read what happened overnight.
- Strict mode at the top: set -euo pipefail.
- A log function that prefixes the date and appends with tee -a.
- A loop over nginx app using systemctl is-active --quiet.
- Disk check: df --output=pcent / | tail -1 | tr -dc '0-9'.
- Exit 0 when healthy, non-zero when something needed fixing.
Make the log path and the disk threshold variables at the top of the script so they're easy to change.