-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDaemon2.cpp
49 lines (45 loc) · 1.15 KB
/
Daemon2.cpp
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
#!/bin/sh
### BEGIN INIT INFO
# Provides: barahl0bot
# Required-Start: $local_fs $network $named $time $syslog
# Required-Stop: $local_fs $network $named $time $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: start barahl0bot bot
### END INIT INFO
SCRIPT=/home/fut33v/barahl0bot/start.sh
WORKINGDIR=/home/fut33v/barahl0bot/
RUNAS=fut33v
PIDFILE=/home/fut33v/barahl0bot/barahl0bot.pid
start() {
if [ -f $PIDFILE ] && kill -0 $(cat $PIDFILE); then
echo 'Service already running' >&2
return 1
fi
echo 'Starting service…' >&2
su -c "start-stop-daemon --start --quiet --background --make-pidfile --no-close --chuid $RUNAS --pidfile $PIDFILE --chdir $WORKINGDIR --exec $SCRIPT"
echo 'Service started' >&2
}
stop() {
if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
echo 'Service not running' >&2
return 1
fi
echo 'Stopping service…' >&2
kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
echo 'Service stopped' >&2
}
case "$1" in
start)
start
;;
stop)
stop
;;
retart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart|uninstall}"
esac