From: Niki Roo Date: Sun, 26 Nov 2017 18:02:56 +0000 (+0100) Subject: SystemV service file for remote fanfix X-Git-Tag: fanfix-1.6.3~29 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=d9cb7150e5cda17e47d286cb81d462dbc2cad9e8;p=fanfix.git SystemV service file for remote fanfix --- diff --git a/fanfix.sysv b/fanfix.sysv new file mode 100755 index 0000000..2956d89 --- /dev/null +++ b/fanfix.sysv @@ -0,0 +1,92 @@ +#!/bin/sh +# +# fanfix This starts the Fanfix remote service. +# +# chkconfig: 2345 10 90 +# description: Starts the Fanfix remote service +# +### BEGIN INIT INFO +# Short-Description: Fanfix service +# Description: Starts the Fanfix remote service +### END INIT INFO + +ENABLED=true +USER=fanfix + +JAR=/path/to/fanfix.jar +PINCODE="my password" +PORT=12000 + +FPID=/tmp/fanfix.pid +OUT=/var/log/fanfix +ERR=/var/log/fanfix.err + +if [ "$ENABLED" != true ]; then + [ "$1" != status ] + exit $? +fi + +if [ ! -e "$JAR" ]; then + echo "Canot find main jar file: $JAR" >&2 + exit 4 +fi + +case "$1" in +start) + if sh "$0" status --quiet; then + echo "Fanfix is already running." >&2 + false + else + sudo -u "$USER" -- java -jar "$JAR" --server "$PINCODE" "$PORT" > "$OUT" 2> "$ERR" & + echo $! > "$FPID" + fi + + sleep 0.1 + sh "$0" status --quiet +;; +stop) + if sh "$0" status --quiet; then + sudo -u "$USER" -- java -jar "$JAR" --stop-server "$PINCODE" "$PORT" + fi + + i=1 + while [ $i -lt 100 ]; do + if sh "$0" status --quiet; then + echo -n . >&2 + sleep 1 + fi + i=`expr $i + 1` + done + echo >&2 + + if sh "$0" status --quiet; then + echo "Process not responding, killing it..." >&2 + kill "`cat "$FPID"`" + sleep 10 + kill -9 "`cat "$FPID"`" 2>/dev/null + fi + + rm "$FPID" +;; +restart) + sh "$0" stop + sh "$0" start +;; +status) + if [ -e "$FPID" ]; then + if [ "$2" = "--quiet" ]; then + ps "`cat "$FPID"`" >/dev/null + else + ps "`cat "$FPID"`" >/dev/null \ + && echo service is running >&2 + fi + else + false + fi +;; +*) + echo $"Usage: $0 {start|stop|status|restart}" >&2 + false +;; +esac +