blob: 69823c24ef36c0e2a3829cfe8e2ad3b053cb812d [file] [log] [blame]
Shad Ansarid0eaf752018-08-16 00:26:12 +00001#!/bin/sh
2
3### BEGIN INIT INFO
4# Provides: openolt
5# Required-Start: $all
6# Required-Stop: $network $local_fs $syslog
7# Default-Start: 2 3 4 5
8# Default-Stop: 0 1 6
9# Short-Description: Openolt
10# Description: Openolt start-stop-daemon - Debian
11### END INIT INFO
12
13NAME="openolt"
14PATH="/broadcom:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
15APPDIR="/broadcom"
16#APPBIN="/broadcom/openolt"
17APPBIN="openolt"
Jason Huangfd78f662019-06-05 20:25:01 +080018APPARGS=""
Shad Ansarid0eaf752018-08-16 00:26:12 +000019USER="root"
20GROUP="root"
21
22# Include functions
23set -e
24. /lib/lsb/init-functions
25
26start() {
Shad Ansarid0eaf752018-08-16 00:26:12 +000027 printf "Starting '$NAME'... "
Jason Huangfd78f662019-06-05 20:25:01 +080028 sleep 60
Thiyagarajan Subramani1f1280b2019-08-13 18:41:19 +080029 rm -f /var/log/$NAME.log
30 touch /var/log/$NAME.log
Shad Ansarid0eaf752018-08-16 00:26:12 +000031 start-stop-daemon --verbose --start --chuid "$USER:$GROUP" --background --no-close --make-pidfile --pidfile /var/run/$NAME.pid --chdir "$APPDIR" --exec "$APPBIN" -- $APPARGS < /dev/tty1 >> /var/log/$NAME.log 2>&1 || true
32 printf "done\n"
33}
34
35#We need this function to ensure the whole process tree will be killed
36killtree() {
37 local _pid=$1
38 local _sig=${2-TERM}
39 for _child in $(ps -o pid --no-headers --ppid ${_pid}); do
40 killtree ${_child} ${_sig}
41 done
42 kill -${_sig} ${_pid}
43}
44
45stop() {
46 printf "Stopping '$NAME'... "
47 [ -z `cat /var/run/$NAME.pid 2>/dev/null` ] || \
48 while test -d /proc/$(cat /var/run/$NAME.pid); do
49 killtree $(cat /var/run/$NAME.pid) 15
50 sleep 0.5
51 done
52 [ -z `cat /var/run/$NAME.pid 2>/dev/null` ] || rm /var/run/$NAME.pid
Thiyagarajan Subramani1f1280b2019-08-13 18:41:19 +080053 rm -f /var/log/$NAME.log
Shad Ansarid0eaf752018-08-16 00:26:12 +000054 printf "done\n"
55}
56
57status() {
58 status_of_proc -p /var/run/$NAME.pid $APPDIR/$APPBIN $NAME && exit 0 || exit $?
59}
60
61case "$1" in
62 start)
63 start
64 ;;
65 stop)
66 stop
67 ;;
68 restart)
69 stop
70 start
71 ;;
72 status)
73 status
74 ;;
75 *)
76 echo "Usage: $NAME {start|stop|restart|status}" >&2
77 exit 1
78 ;;
79esac
80
81exit 0