blob: 1db4fbb55a7b2e0ef0252c4aa557ebf809098429 [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"
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000018APPARGS=""
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'... "
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000028 # TODO: If openolt agent has a way to figure out progamatically
29 # if the BAL is ready, the below timer may not be needed.
30 sleep 120
31 rm -f /var/log/$NAME.log
32 touch /var/log/$NAME.log
Shad Ansarid0eaf752018-08-16 00:26:12 +000033 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
34 printf "done\n"
35}
36
37#We need this function to ensure the whole process tree will be killed
38killtree() {
39 local _pid=$1
40 local _sig=${2-TERM}
41 for _child in $(ps -o pid --no-headers --ppid ${_pid}); do
42 killtree ${_child} ${_sig}
43 done
44 kill -${_sig} ${_pid}
45}
46
47stop() {
48 printf "Stopping '$NAME'... "
49 [ -z `cat /var/run/$NAME.pid 2>/dev/null` ] || \
50 while test -d /proc/$(cat /var/run/$NAME.pid); do
51 killtree $(cat /var/run/$NAME.pid) 15
52 sleep 0.5
53 done
54 [ -z `cat /var/run/$NAME.pid 2>/dev/null` ] || rm /var/run/$NAME.pid
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000055 rm -f /var/log/$NAME.log
Shad Ansarid0eaf752018-08-16 00:26:12 +000056 printf "done\n"
57}
58
59status() {
60 status_of_proc -p /var/run/$NAME.pid $APPDIR/$APPBIN $NAME && exit 0 || exit $?
61}
62
63case "$1" in
64 start)
65 start
66 ;;
67 stop)
68 stop
69 ;;
70 restart)
71 stop
72 start
73 ;;
74 status)
75 status
76 ;;
77 *)
78 echo "Usage: $NAME {start|stop|restart|status}" >&2
79 exit 1
80 ;;
81esac
82
83exit 0