--tag -> --search-tag
[nikiroo-utils.git] / fanfix.sysv
1 #!/bin/sh
2 #
3 # fanfix This starts the Fanfix remote service.
4 #
5 # description: Starts the Fanfix remote service
6 #
7 ### BEGIN INIT INFO
8 # Default-Start: 3 4 5
9 # Short-Description: Fanfix service
10 # Description: Starts the Fanfix remote service
11 ### END INIT INFO
12
13 ENABLED=true
14 USER=fanfix
15
16 JAR=/path/to/fanfix.jar
17 PINCODE="my password"
18 PORT=12000
19
20 FPID=/tmp/fanfix.pid
21 OUT=/var/log/fanfix
22 ERR=/var/log/fanfix.err
23
24 if [ "$ENABLED" != true ]; then
25 [ "$1" != status ]
26 exit $?
27 fi
28
29 if [ ! -e "$JAR" ]; then
30 echo "Canot find main jar file: $JAR" >&2
31 exit 4
32 fi
33
34 case "$1" in
35 start)
36 if sh "$0" status --quiet; then
37 echo "Fanfix is already running." >&2
38 false
39 else
40 [ -e "$OUT" ] && mv "$OUT" "$OUT".previous
41 [ -e "$ERR" ] && mv "$ERR" "$ERR".previous
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 ;;
49 stop)
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
71 rm -f "$FPID"
72 ;;
73 restart)
74 sh "$0" stop
75 sh "$0" start
76 ;;
77 status)
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 ;;
93 esac
94