blob: 27dfa0ce4d9f342f91a02e9769ea1ae0721a90cf [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
Orhan Kupusoglu1fd77072021-03-23 08:13:25 -070022# ------------------------------------------------------------------------------
Thiyagarajan Subramani03bc66f2020-04-01 15:58:53 +053023# If OLT is used in inband mode, inband interface name will be copied
24# to /etc/default/openolt file. Here inband interface is passed as argument
25# while running openolt service
26[ -r /etc/default/openolt ] && . /etc/default/openolt
27[ -z "gRPC_interface" ] || APPARGS="--interface $gRPC_interface"
Orhan Kupusoglu1fd77072021-03-23 08:13:25 -070028# ------------------------------------------------------------------------------
29GRPC_TLS_OPTION_A='GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE'
30# Server does not request client certificate.
31# The certificate presented by the client is not checked by the server at all. (A client may present a self signed or signed certificate or not present a certificate at all and any of those option would be accepted)
32
33GRPC_TLS_OPTION_B='GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_BUT_DONT_VERIFY'
34# Server requests client certificate but does not enforce that the client presents a certificate.
35# If the client presents a certificate, the client authentication is left to the application (the necessary metadata will be available to the application via authentication context properties, see grpc_auth_context).
36# The client's key certificate pair must be valid for the SSL connection to be established.
37
38GRPC_TLS_OPTION_C='GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_AND_VERIFY'
39# Server requests client certificate but does not enforce that the client presents a certificate.
40# If the client presents a certificate, the client authentication is done by the gRPC framework. (For a successful connection the client needs to either present a certificate that can be verified against the root certificate configured by the server or not present a certificate at all)
41# The client's key certificate pair must be valid for the SSL connection to be established.
42
43GRPC_TLS_OPTION_D='GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_BUT_DONT_VERIFY'
44# Server requests client certificate and enforces that the client presents a certificate.
45# If the client presents a certificate, the client authentication is left to the application (the necessary metadata will be available to the application via authentication context properties, see grpc_auth_context).
46# The client's key certificate pair must be valid for the SSL connection to be established.
47
48GRPC_TLS_OPTION_E='GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY'
49# Server requests client certificate and enforces that the client presents a certificate.
50# The certificate presented by the client is verified by the gRPC framework. (For a successful connection the client needs to present a certificate that can be verified against the root certificate configured by the server)
51# The client's key certificate pair must be valid for the SSL connection to be established.
52
53GRPC_TLS_OPTION_Z='' # INSECURE
54
55# choose one of the above six options with the last letter
56GRPC_TLS_OPTION=$GRPC_TLS_OPTION_Z
57
58[ $GRPC_TLS_OPTION ] && APPARGS="$APPARGS --enable-tls $GRPC_TLS_OPTION"
59# ------------------------------------------------------------------------------
Thiyagarajan Subramani03bc66f2020-04-01 15:58:53 +053060
Girish Gowdrad4aeca52020-06-11 11:27:29 -070061# Include functions
Shad Ansarid0eaf752018-08-16 00:26:12 +000062set -e
63. /lib/lsb/init-functions
64
65start() {
Jason Huang09b73ea2020-01-08 17:52:05 +080066 printf "Starting '$NAME'... "
67 export USER=$USER
Shad Ansarid0eaf752018-08-16 00:26:12 +000068 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
69 printf "done\n"
70}
71
72#We need this function to ensure the whole process tree will be killed
73killtree() {
74 local _pid=$1
75 local _sig=${2-TERM}
76 for _child in $(ps -o pid --no-headers --ppid ${_pid}); do
77 killtree ${_child} ${_sig}
78 done
79 kill -${_sig} ${_pid}
80}
81
82stop() {
83 printf "Stopping '$NAME'... "
84 [ -z `cat /var/run/$NAME.pid 2>/dev/null` ] || \
85 while test -d /proc/$(cat /var/run/$NAME.pid); do
86 killtree $(cat /var/run/$NAME.pid) 15
87 sleep 0.5
Orhan Kupusoglu1fd77072021-03-23 08:13:25 -070088 done
Shad Ansarid0eaf752018-08-16 00:26:12 +000089 [ -z `cat /var/run/$NAME.pid 2>/dev/null` ] || rm /var/run/$NAME.pid
Shad Ansarid0eaf752018-08-16 00:26:12 +000090 printf "done\n"
91}
92
93status() {
94 status_of_proc -p /var/run/$NAME.pid $APPDIR/$APPBIN $NAME && exit 0 || exit $?
95}
96
97case "$1" in
98 start)
99 start
100 ;;
101 stop)
102 stop
103 ;;
104 restart)
105 stop
106 start
107 ;;
108 status)
109 status
110 ;;
111 *)
112 echo "Usage: $NAME {start|stop|restart|status}" >&2
113 exit 1
114 ;;
115esac
116
117exit 0