Created
April 23, 2026 04:43
-
-
Save soopyc/acb70c1e8dfa0931609d5ba174a66cf3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Service] | |
| ExecStart=/opt/ss-monitor.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [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