try +1
[nikiroo-utils.git] / fanfix.sysv
CommitLineData
d9cb7150
NR
1#!/bin/sh
2#
3# fanfix This starts the Fanfix remote service.
4#
d9cb7150
NR
5# description: Starts the Fanfix remote service
6#
7### BEGIN INIT INFO
57f21783 8# Default-Start: 3 4 5
d9cb7150
NR
9# Short-Description: Fanfix service
10# Description: Starts the Fanfix remote service
11### END INIT INFO
12
13ENABLED=true
14USER=fanfix
15
16JAR=/path/to/fanfix.jar
17PINCODE="my password"
18PORT=12000
19
20FPID=/tmp/fanfix.pid
21OUT=/var/log/fanfix
22ERR=/var/log/fanfix.err
23
24if [ "$ENABLED" != true ]; then
25 [ "$1" != status ]
26 exit $?
27fi
28
29if [ ! -e "$JAR" ]; then
30 echo "Canot find main jar file: $JAR" >&2
31 exit 4
32fi
33
34case "$1" in
35start)
36 if sh "$0" status --quiet; then
37 echo "Fanfix is already running." >&2
38 false
39 else
57f21783
NR
40 [ -e "$OUT" ] && mv "$OUT" "$OUT".previous
41 [ -e "$ERR" ] && mv "$ERR" "$ERR".previous
d9cb7150
NR
42 sudo -u "$USER" -- java -jar "$JAR" --server "$PINCODE" "$PORT" > "$OUT" 2> "$ERR" &
43 echo $! > "$FPID"
44 fi
45
46 sleep 0.1
47 sh "$0" status --quiet
48;;
49stop)
50 if sh "$0" status --quiet; then
51 sudo -u "$USER" -- java -jar "$JAR" --stop-server "$PINCODE" "$PORT"
52 fi
53
54 i=1
55 while [ $i -lt 100 ]; do
56 if sh "$0" status --quiet; then
57 echo -n . >&2
58 sleep 1
59 fi
60 i=`expr $i + 1`
61 done
62 echo >&2
63
64 if sh "$0" status --quiet; then
65 echo "Process not responding, killing it..." >&2
66 kill "`cat "$FPID"`"
67 sleep 10
68 kill -9 "`cat "$FPID"`" 2>/dev/null
69 fi
70
48587cad 71 rm -f "$FPID"
d9cb7150
NR
72;;
73restart)
74 sh "$0" stop
75 sh "$0" start
76;;
77status)
78 if [ -e "$FPID" ]; then
79 if [ "$2" = "--quiet" ]; then
80 ps "`cat "$FPID"`" >/dev/null
81 else
82 ps "`cat "$FPID"`" >/dev/null \
83 && echo service is running >&2
84 fi
85 else
86 false
87 fi
88;;
89*)
90 echo $"Usage: $0 {start|stop|status|restart}" >&2
91 false
92;;
93esac
94