View difference between Paste ID: DxrF2hWw and CCLTUwmq
SHOW: | | - or go back to the newest paste.
1
#!/bin/sh
2
 
3
### BEGIN INIT INFO
4
# Provides:          exampledaemon
5
# Required-Start:    $local_fs $network $syslog
6
# Required-Stop:     $local_fs $network $syslog
7
# Default-Start:     2 3 4 5
8
# Default-Stop:      0 1 6
9
# Short-Description: Example
10
# Description:       Example start-stop-daemon - Debian
11
### END INIT INFO
12
 
13
NAME="Auto-Subliminal"
14
PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
15
APPDIR="/home/user/auto-subliminal"
16
APPBIN="/usr/bin/python"
17
APPARGS="/home/user/auto-subliminal/AutoSubliminal.py -c/home/user/auto-subliminal/config.properties -d -l"
18
USER="user"
19
GROUP="user"
20
# Include functions
21
set -e
22
. /lib/lsb/init-functions
23
 
24
start() {
25
  printf "Starting '$NAME'... "
26
  start-stop-daemon --start --chuid "$USER:$GROUP" --background --make-pidfile --pidfile /var/run/$NAME.pid --chdir "$APPDIR" --exec "$APPBIN" -- $APPARGS || true
27
  printf "done\n"
28
}
29
 
30
#We need this function to ensure the whole process tree will be killed
31
killtree() {
32
    local _pid=$1
33
    local _sig=${2-TERM}
34
    for _child in $(ps -o pid --no-headers --ppid ${_pid}); do
35
        killtree ${_child} ${_sig}
36
    done
37
    kill -${_sig} ${_pid}
38
}
39
 
40
stop() {
41
  printf "Stopping '$NAME'... "
42
  [ -z `cat /var/run/$NAME.pid 2>/dev/null` ] || \
43
  while test -d /proc/$(cat /var/run/$NAME.pid); do
44
    killtree $(cat /var/run/$NAME.pid) 15
45
    sleep 0.5
46
  done
47
  [ -z `cat /var/run/$NAME.pid 2>/dev/null` ] || rm /var/run/$NAME.pid
48
  printf "done\n"
49
}
50
 
51
status() {
52
  status_of_proc -p /var/run/$NAME.pid "" $NAME && exit 0 || exit $?
53
}
54
 
55
case "$1" in
56
  start)
57
    start
58
    ;;
59
  stop)
60
    stop
61
    ;;
62
  restart)
63
    stop
64
    start
65
    ;;
66
  status)
67
    status
68
    ;;
69
  *)
70
    echo "Usage: $NAME {start|stop|restart|status}" >&2
71
    exit 1
72
    ;;
73
esac
74
 
75
exit 0