Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dhowdy
Created August 16, 2018 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhowdy/d3258c3240b5d9a77126a0e6d34b395a to your computer and use it in GitHub Desktop.
Save dhowdy/d3258c3240b5d9a77126a0e6d34b395a to your computer and use it in GitHub Desktop.
Simple systemd watchdog
cat <<EOF > /lib/systemd/system/[[[name]]].service
[Unit]
Description=[[[The Service to watch]]]
After=local-fs.target
[Service]
Type=simple
PIDFile=/var/run/[[[name]]].pid
ExecStart=/opt/[[[script.sh]]]
Restart=always
RestartSec=1
StartLimitInterval=0
StartLimitBurst=0
[Install]
WantedBy=default.target
EOF
cat <<EOF > /opt/[[[script.sh]]]
#!/bin/bash
/path/to/executable with args
EOF
service [[[name]]] stop
systemctl daemon-reload
systemctl enable [[[name]]].service
service [[[name]]] start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment