I have made a daemon service in linux server. It is running well. The service file is stargate.service (in /etc/systemd/system).
[Unit] Description=stargate [Service] Type=simple PIDFile=/app/stargate/stargate.pid ExecStart=/app/stargate/stargate.sh start ExecReload=/app/stargate/stargate.sh restart ExecStop=/app/stargate/stargate.sh stop [Install] Alias=stargate WantedBy=default.target
If by some reasons, the daemon service is die and stop. Do you know how to make the system automatically restart the daemon service ? How to make the daemon service starts if server get rebooted?
Advertisement
Answer
To respawn your service when it fails, add the following to the [Service]
block:
[Service] Restart=on-failure RestartSec=3
If you wish to always restart when your service is killed use Restart=always
The RestartSec
value is the delay between restart attempts.
See more info here: https://www.freedesktop.org/software/systemd/man/systemd.service.html