#!/bin/sh # # fanfix This starts the Fanfix remote service. # # description: Starts the Fanfix remote service # ### BEGIN INIT INFO # Default-Start: 3 4 5 # 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 [ -e "$OUT" ] && mv "$OUT" "$OUT".previous [ -e "$ERR" ] && mv "$ERR" "$ERR".previous 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 -f "$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