blob: 89918979252a455e04e09819bcb1111f020d4d18 (
plain)
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
|
#!/bin/sh
# Start/stop/restart sickrage.
# rc.sickrage created by Jeremy Brent Hansen for Slackware
# Set program name in case you want to run sick{beard|rage|gear|etc}
PROG=${PROG:-sickrage}
# Source SickRage configuration
if [ -f /etc/${PROG}.conf ]; then
. /etc/${PROG}.conf
fi
# Ensure all required variables are set in conf file
# Edit conf file in /etc/sickrage.conf for any changes
for var in USERNAME HOMEDIR DATADIR PIDFILE PORT; do
if [ -z "${!var}" ]; then
echo "/etc/${PROG}.conf is missing some or all required variables ($var)."
echo "Please check the file and try again."
exit 1
fi
done
# Check if the pid file exists
check() {
if [ -e $PIDFILE ]; then
STATUS=running
else
STATUS=stopped
fi
}
status() {
if [ $STATUS == "running" ]; then
echo "${PROG} currently running or not shut down properly."
echo "PIDfile: $PIDFILE already exists."
elif [ $STATUS == "stopped" ]; then
echo "${PROG} not started."
echo "PIDfile: $PIDFILE does not exist."
else
echo "Status unknown."
fi
}
start() {
if [ $STATUS == "running" ]; then
echo "$PROG already running or not shut down properly."
else
echo -n "Starting ${PROG}: "
su $USERNAME -s /bin/sh -c "python ${HOMEDIR}/SickBeard.py --daemon --pidfile=${PIDFILE} --datadir=${DATADIR} --port=${PORT} &> /dev/null"
if (( $? == 0 )); then
echo "Startup Successful"
else
echo "Startup Failed. Please try running the following to see the errors."
echo "su $USERNAME -s /bin/sh -c \"python ${HOMEDIR}/SickBeard.py --daemon --pidfile=${PIDFILE} --datadir=${DATADIR} --port=${PORT}\""
fi
fi
}
stop() {
if [ $STATUS == "stopped" ]; then
echo "${PROG} doesn't seem to be running. Please try running"
echo "$0 start"
else
if [ "$EUID" -ne 0 ];then
echo "Please run as root"
exit 1
fi
PID=$(cat $PIDFILE)
echo -n $"Shutting down ${PROG}: "
curl -f http://localhost:${PORT}/home/shutdown/?pid=${PID} &> /dev/null
if [ $? -gt 0 ]; then
echo "Normal Shutdown Failed - Attempting to kill the process."
echo $?
sleep 7
kill -9 $PID
else
echo "Shutdown Successful"
fi
fi
}
case "$1" in
start)
check
start
;;
stop)
check
stop
;;
restart)
check
stop
start
;;
status)
check
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
|