While automating web-server recovery, you write a Bash script that creates an override file for nginx.service on an Ubuntu 22.04 host. The script must guarantee that nginx automatically restarts any time the process exits with a non-zero status or is terminated by a signal, but should leave the service stopped after a clean, manual shutdown. Which single systemd directive should the script place in the [Service] section of the override file to meet this requirement?
The directive Restart=on-failure tells systemd to restart the unit whenever it terminates abnormally-such as a crash, unclean exit code, timeout, or signal-but not when it is stopped intentionally with normal exit status. This exactly satisfies the requirement. RestartSec=0 only sets the delay before a configured restart occurs; it does nothing if a restart policy is not enabled. Type=forking controls how systemd decides that a daemon has finished starting and has no effect on restart behavior. WantedBy=multi-user.target belongs in the [Install] section and is used to enable a unit at boot, not to determine what happens after failures at runtime.