fix content type for cover
[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
d9cb7150 15JAR=/path/to/fanfix.jar
d9cb7150
NR
16
17FPID=/tmp/fanfix.pid
18OUT=/var/log/fanfix
19ERR=/var/log/fanfix.err
20
21if [ "$ENABLED" != true ]; then
22 [ "$1" != status ]
23 exit $?
24fi
25
26if [ ! -e "$JAR" ]; then
27 echo "Canot find main jar file: $JAR" >&2
28 exit 4
29fi
30
31case "$1" in
32start)
33 if sh "$0" status --quiet; then
34 echo "Fanfix is already running." >&2
35 false
36 else
57f21783
NR
37 [ -e "$OUT" ] && mv "$OUT" "$OUT".previous
38 [ -e "$ERR" ] && mv "$ERR" "$ERR".previous
59be4dd3 39 sudo -u "$USER" -- java -jar "$JAR" --server > "$OUT" 2> "$ERR" &
d9cb7150
NR
40 echo $! > "$FPID"
41 fi
42
43 sleep 0.1
44 sh "$0" status --quiet
45;;
46stop)
47 if sh "$0" status --quiet; then
59be4dd3 48 sudo -u "$USER" -- java -jar "$JAR" --stop-server
d9cb7150
NR
49 fi
50
51 i=1
52 while [ $i -lt 100 ]; do
53 if sh "$0" status --quiet; then
54 echo -n . >&2
55 sleep 1
56 fi
57 i=`expr $i + 1`
58 done
59 echo >&2
60
61 if sh "$0" status --quiet; then
62 echo "Process not responding, killing it..." >&2
63 kill "`cat "$FPID"`"
64 sleep 10
65 kill -9 "`cat "$FPID"`" 2>/dev/null
66 fi
67
48587cad 68 rm -f "$FPID"
d9cb7150
NR
69;;
70restart)
71 sh "$0" stop
72 sh "$0" start
73;;
74status)
75 if [ -e "$FPID" ]; then
76 if [ "$2" = "--quiet" ]; then
77 ps "`cat "$FPID"`" >/dev/null
78 else
79 ps "`cat "$FPID"`" >/dev/null \
80 && echo service is running >&2
81 fi
82 else
83 false
84 fi
85;;
86*)
87 echo $"Usage: $0 {start|stop|status|restart}" >&2
88 false
89;;
90esac
91