terminusd docs :: shutdown guard
Shutdown Guard

Complete control of when shutdowns can be performed.

The Shutdown Guard works by executing your custom commands to determine whether system-wide shutdown, reboot, and halt actions will be disabled and enabled. Even from root.

It is meant to prevent accidental reboots by deterministically preventing them using your decisions about your environment.

oneshot Guard Scripts

  • Runs your command every shutdown_guard_interval seconds.
  • After shutdown_guard_threshold consecutive non-zero exits, system-wide shutdowns are disabled
  • When your guard command returns 0 again, system-wide shutdowns are re-enabled

persist mode

  • Starts your guard command and attaches to it to monitor STDIO.
  • If your guard script exits, Shutdown Guard will restart it automatically.
  • Your guard script controls enabling/disabled system-wide reboots by emitting directives to stdout.
shutdown_guard_disable_shutdown 1
shutdown_guard_disable_shutdown 0

Guard keys in [main]

  • shutdown_guard_enabled
  • shutdown_guard_command
  • shutdown_guard_type (oneshot or persist)
  • shutdown_guard_interval
  • shutdown_guard_threshold
  • shutdown_guard_run_as_user
  • shutdown_guard_run_as_group
  • shutdown_guard_run_env

Example persist mode Shutdown Guard

The included example persistent Shutdown Guard script monitors an IP address for availability, and disables shutdowns when it's not responding, enabling them again when it returns.
Please note that the example script is pinging a specific IP address that may not exist on your network, and may result in terminusd disabling shutdowns/reboots on your system. You can use terminusctl to enable/disable both the guard and shutdowns if this occurs.
[main]
shutdown_guard_enabled = true
shutdown_guard_type = persist
shutdown_guard_command = /usr/libexec/terminusd/examples/example-persistent-shutdown-guard.sh
shutdown_guard_run_as_user = root
shutdown_guard_run_as_group = root