Skip to content

Instantly share code, notes, and snippets.

@soopyc
Created April 23, 2026 04:43
Show Gist options
  • Select an option

  • Save soopyc/acb70c1e8dfa0931609d5ba174a66cf3 to your computer and use it in GitHub Desktop.

Select an option

Save soopyc/acb70c1e8dfa0931609d5ba174a66cf3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euxo pipefail
# constants definition
LOGFILE="/var/log/ss-monitor.log"
TARGET_SERVICE="shadowsocks-libev"
log() {
printf '[%s] %s\n' "$(date -Is)" "$@" >> $LOGFILE
}
getprop() {
systemctl show "$TARGET_SERVICE" -P "$1"
}
# check systemd for process status
pid="$(getprop 'MainPID')"
if test "$pid" -eq 0; then # according to systemd docs 0 means dead.
# service has died, gather some more data
diedat="$(getprop 'ExecMainExitTimestamp')"
log "ERRO: service $TARGET_SERVICE has died at ${diedat}."
else
# service is running, all good
log "INFO: service $TARGET_SERVICE is running. (pid: ${pid})"
fi
[Service]
ExecStart=/opt/ss-monitor.sh
[Timer]
OnCalendar=*:*:0/30
Persistent=true
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment