forked from VentureKing/Deeper-Thought-2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
deeper.init
80 lines (72 loc) · 1.23 KB
/
deeper.init
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
#!/bin/sh
### BEGIN INIT INFO
# Provides: deeper
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Deeper Thought at boot time
# Description: Start Deeper Thought at boot time
### END INIT INFO
# Make sure user is root
if [ "$(id -u)" != "0" ]; then
echo "Access denied: Must be root"
exit 1
fi
is_running() {
testrun=$(ps -ef | grep "/usr/bin/deeper" | grep -v "grep" | grep -v "SCREEN" | wc -l)
if [ $testrun -eq "0" ];
then
return 1
else
return 0
fi
}
start() {
if (is_running); then
echo "Deeper Thought is already running"
return 1
else
echo "Starting Deeper Thought"
screen -dmS deeper /usr/bin/deeper
return 0
fi
}
stop() {
if (is_running); then
echo "Stopping Deeper Thought"
kill -2 $(pidof deeper)
return 0
else
echo "Deeper Thought is already stopped"
return 1
fi
}
status() {
if (is_running);
then
echo "Deeper Thought is Running"
else
echo "Deeper Thought is stopped"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
*)
echo "Usage: sudo /etc/init.d/deeper {start|stop|restart|status}"
exit 1
;;
esac
exit 0