Makefile (better Android Studio support)
[fanfix.git] / fanfix.sysv
1 #!/bin/sh
2 #
3 # fanfix This starts the Fanfix remote service.
4 #
5 # chkconfig: 2345 10 90
6 # description: Starts the Fanfix remote service
7 #
8 ### BEGIN INIT INFO
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 sudo -u "$USER" -- java -jar "$JAR" --server "$PINCODE" "$PORT" > "$OUT" 2> "$ERR" &
41 echo $! > "$FPID"
42 fi
43
44 sleep 0.1
45 sh "$0" status --quiet
46 ;;
47 stop)
48 if sh "$0" status --quiet; then
49 sudo -u "$USER" -- java -jar "$JAR" --stop-server "$PINCODE" "$PORT"
50 fi
51
52 i=1
53 while [ $i -lt 100 ]; do
54 if sh "$0" status --quiet; then
55 echo -n . >&2
56 sleep 1
57 fi
58 i=`expr $i + 1`
59 done
60 echo >&2
61
62 if sh "$0" status --quiet; then
63 echo "Process not responding, killing it..." >&2
64 kill "`cat "$FPID"`"
65 sleep 10
66 kill -9 "`cat "$FPID"`" 2>/dev/null
67 fi
68
69 rm -f "$FPID"
70 ;;
71 restart)
72 sh "$0" stop
73 sh "$0" start
74 ;;
75 status)
76 if [ -e "$FPID" ]; then
77 if [ "$2" = "--quiet" ]; then
78 ps "`cat "$FPID"`" >/dev/null
79 else
80 ps "`cat "$FPID"`" >/dev/null \
81 && echo service is running >&2
82 fi
83 else
84 false
85 fi
86 ;;
87 *)
88 echo $"Usage: $0 {start|stop|status|restart}" >&2
89 false
90 ;;
91 esac
92