blob: e9a448b45595dcbe951607a132c73304dd15e4af [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
Girish Gowdrad4aeca52020-06-11 11:27:29 -070028# Include functions
Shad Ansarid0eaf752018-08-16 00:26:12 +000029set -e
30. /lib/lsb/init-functions
31
32start() {
Jason Huang09b73ea2020-01-08 17:52:05 +080033 printf "Starting '$NAME'... "
34 export USER=$USER
Shad Ansarid0eaf752018-08-16 00:26:12 +000035 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
36 printf "done\n"
37}
38
39#We need this function to ensure the whole process tree will be killed
40killtree() {
41 local _pid=$1
42 local _sig=${2-TERM}
43 for _child in $(ps -o pid --no-headers --ppid ${_pid}); do
44 killtree ${_child} ${_sig}
45 done
46 kill -${_sig} ${_pid}
47}
48
49stop() {
50 printf "Stopping '$NAME'... "
51 [ -z `cat /var/run/$NAME.pid 2>/dev/null` ] || \
52 while test -d /proc/$(cat /var/run/$NAME.pid); do
53 killtree $(cat /var/run/$NAME.pid) 15
54 sleep 0.5
55 done
56 [ -z `cat /var/run/$NAME.pid 2>/dev/null` ] || rm /var/run/$NAME.pid
Shad Ansarid0eaf752018-08-16 00:26:12 +000057 printf "done\n"
58}
59
60status() {
61 status_of_proc -p /var/run/$NAME.pid $APPDIR/$APPBIN $NAME && exit 0 || exit $?
62}
63
64case "$1" in
65 start)
66 start
67 ;;
68 stop)
69 stop
70 ;;
71 restart)
72 stop
73 start
74 ;;
75 status)
76 status
77 ;;
78 *)
79 echo "Usage: $NAME {start|stop|restart|status}" >&2
80 exit 1
81 ;;
82esac
83
84exit 0