-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sh
executable file
·52 lines (45 loc) · 1.27 KB
/
init.sh
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
#!/bin/bash
#
#---------------------
# /etc/init.d/wittypi
#---------------------
#-----------------------------------------------------------------------
### BEGIN INIT INFO
# Provides: wittypi
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Witty Pi 2 initialize script
# Description: This service is used to manage Witty Pi 2 service
### END INIT INFO
#-----------------------------------------------------------------------
case "$1" in
start)
echo "Starting Witty Pi 2 Daemon..."
sudo /opt/wittyPi/daemon.sh &
sleep 1
daemonPid=$(ps --ppid $! -o pid=)
echo $daemonPid > /var/run/wittypi_daemon.pid
;;
stop)
echo "Stopping Witty Pi 2 Daemon..."
daemonPid=$(cat /var/run/wittypi_daemon.pid)
kill -9 $daemonPid
;;
restart)
echo "Stopping Witty Pi 2 Daemon..."
daemonPid=$(cat /var/run/wittypi_daemon.pid)
kill -9 $daemonPid
echo "Restarting Witty Pi 2 Daemon ..."
sudo /opt/wittyPi/daemon.sh &
sleep 1
daemonPid=$(ps --ppid $! -o pid=)
echo $daemonPid > /var/run/wittypi_daemon.pid
;;
*)
echo "Usage: /etc/init.d/wittypi start|stop|restart"
exit 1
;;
esac
exit 0