forked from anandslab/AtoMiC-ToolKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nzbget.initd
executable file
·119 lines (108 loc) · 2.75 KB
/
nzbget.initd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/sh
### BEGIN INIT INFO
# Default-Start: 2 3 4 5
# Provides: nzbget
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start the nzbget processes
# Description: starts and stops nzbget
# Author: Jens
# Version: 1.0
### END INIT INFO
NAME=nzbget
DESC=NZBGet
# User to run the daemon
NZBGET_USER=nzb
# Group to run the daemon
NZBGET_GROUP=nzb
# Path to configfile
NZBGET_CONF=/etc/nzbget.conf
# nzbget executable
NZBGET_BIN=/usr/local/bin/nzbget
# Setting schuduling priority
# -20 to 19 (most to least, default 0)
# if you don't want your nzbget to slow down anything else use 19
# more info: man nice
NZBGET_NICE=15
# Setting I/O scheduling class and priority
# Classes: idle, best-effort, realtime (default best-effort)
# Priorities 0-7 (default 4)
# more info: man ionice
NZBGET_IOSCHED="best-effort:4"
# Usually MainDir/nzbget.lock
# Check LockFile setting in your nzbget.conf
PID_FILE=/var/lock/nzbget.lock
#######################################################################
##
### NO MODIFICATIONS PAST THIS LINE
##
#######################################################################
RETVAL=0
set -e
. /lib/lsb/init-functions
PATH=${PATH}:/sbin
if [ -e $PID_FILE ]; then
PID=`cat $PID_FILE`
if ! kill -0 $PID > /dev/null 2>&1; then
echo "Removing stale $PID_FILE"
rm $PID_FILE
fi
fi
do_start()
{
start-stop-daemon --start --quiet --iosched ${NZBGET_IOSCHED} --nicelevel ${NZBGET_NICE} --chuid ${NZBGET_USER}:${NZBGET_GROUP} --exec ${NZBGET_BIN} -- -D -c ${NZBGET_CONF}
RETVAL="$?"
return "$RETVAL"
}
do_stop()
{
start-stop-daemon --stop --pidfile $PID_FILE --retry=TERM/15/KILL/5
RETVAL="$?"
return "$RETVAL"
}
case "$1" in
start)
log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) log_end_msg 0 ;;
2) log_end_msg 1 ;;
esac
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) log_end_msg 0 ;;
2) log_end_msg 1 ;;
esac
;;
restart)
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
status)
status_of_proc -p $PID_FILE "$NZBGET_BIN" "$NAME" && exit 0 || exit $?
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|restart|status}" >&2
exit 3
;;
esac
exit $RETVAL