blob: ef80b24d0db3fde82725be779ef232b3ee9210ab [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
Thiyagarajan Subramani03bc66f2020-04-01 15:58:53 +053022# If OLT is used in inband mode, inband interface name will be copied
23# to /etc/default/openolt file. Here inband interface is passed as argument
24# while running openolt service
25[ -r /etc/default/openolt ] && . /etc/default/openolt
26[ -z "gRPC_interface" ] || APPARGS="--interface $gRPC_interface"
27
Shad Ansarid0eaf752018-08-16 00:26:12 +000028# Include functions
29set -e
30. /lib/lsb/init-functions
31
32start() {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000033 rm -f /var/log/$NAME.log
Jason Huang09b73ea2020-01-08 17:52:05 +080034 printf "Starting '$NAME'... "
35 export USER=$USER
Shad Ansarid0eaf752018-08-16 00:26:12 +000036 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
37 printf "done\n"
38}
39
40#We need this function to ensure the whole process tree will be killed
41killtree() {
42 local _pid=$1
43 local _sig=${2-TERM}
44 for _child in $(ps -o pid --no-headers --ppid ${_pid}); do
45 killtree ${_child} ${_sig}
46 done
47 kill -${_sig} ${_pid}
48}
49
50stop() {
51 printf "Stopping '$NAME'... "
52 [ -z `cat /var/run/$NAME.pid 2>/dev/null` ] || \
53 while test -d /proc/$(cat /var/run/$NAME.pid); do
54 killtree $(cat /var/run/$NAME.pid) 15
55 sleep 0.5
56 done
57 [ -z `cat /var/run/$NAME.pid 2>/dev/null` ] || rm /var/run/$NAME.pid
Shad Ansarid0eaf752018-08-16 00:26:12 +000058 printf "done\n"
59}
60
61status() {
62 status_of_proc -p /var/run/$NAME.pid $APPDIR/$APPBIN $NAME && exit 0 || exit $?
63}
64
65case "$1" in
66 start)
67 start
68 ;;
69 stop)
70 stop
71 ;;
72 restart)
73 stop
74 start
75 ;;
76 status)
77 status
78 ;;
79 *)
80 echo "Usage: $NAME {start|stop|restart|status}" >&2
81 exit 1
82 ;;
83esac
84
85exit 0