diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-08-04 21:50:05 +0200 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-08-04 21:50:05 +0200 |
commit | 87a99d61b7bc1f428ce5917d353cbe3d815a2a1b (patch) | |
tree | adfb2641787e1c30a028c3c349beae479b8a7fc7 /fics_autorun.sh | |
parent | 2561f872639827671fc9be08578b483c421a679c (diff) |
Autorun script -- initial revision
Diffstat (limited to 'fics_autorun.sh')
-rwxr-xr-x | fics_autorun.sh | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/fics_autorun.sh b/fics_autorun.sh new file mode 100755 index 0000000..a3b4863 --- /dev/null +++ b/fics_autorun.sh @@ -0,0 +1,51 @@ +#!/bin/sh +# SPDX-FileCopyrightText: 2024 Markus Uhlin <maxxe@rpblc.net> +# SPDX-License-Identifier: ISC +# +# This script is suitable to run as a cron job for the dedicated chess +# user. + +# You need to change these variables if FICS was built with a +# non-standard home location. +FICS_LOCKFILE=/home/chess/config/fics.pid +FICS_PROG=/home/chess/bin/fics + +run_fics() +{ + if [ -x ${FICS_PROG} ]; then + ${FICS_PROG} -d || exit 1 + exit 0 + else + echo "cannot find the program" + exit 1 + fi +} + +if [ -r $FICS_LOCKFILE ]; then + PID="$(cat $FICS_LOCKFILE)" + + case "$PID" in + ""|*[!0-9]*) + echo "pid not numeric" + exit 1 + ;; + *) + ;; + esac + + if [ ${#PID} -gt 20 ]; then + echo "pid too long" + exit 1 + fi + + if ps -p "$PID" > /dev/null; then + # already running (good) + exit 0 + else + echo "$PID not running. restarting..." + rm -f $FICS_LOCKFILE + run_fics + fi +else + run_fics +fi |