Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 1 | #!/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 | |
| 13 | NAME="openolt" |
| 14 | PATH="/broadcom:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" |
| 15 | APPDIR="/broadcom" |
| 16 | #APPBIN="/broadcom/openolt" |
| 17 | APPBIN="openolt" |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 18 | APPARGS="" |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 19 | USER="root" |
| 20 | GROUP="root" |
| 21 | |
Orhan Kupusoglu | 1fd7707 | 2021-03-23 08:13:25 -0700 | [diff] [blame^] | 22 | # ------------------------------------------------------------------------------ |
Thiyagarajan Subramani | 03bc66f | 2020-04-01 15:58:53 +0530 | [diff] [blame] | 23 | # 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 Kupusoglu | 1fd7707 | 2021-03-23 08:13:25 -0700 | [diff] [blame^] | 28 | # ------------------------------------------------------------------------------ |
| 29 | GRPC_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 | |
| 33 | GRPC_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 | |
| 38 | GRPC_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 | |
| 43 | GRPC_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 | |
| 48 | GRPC_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 | |
| 53 | GRPC_TLS_OPTION_Z='' # INSECURE |
| 54 | |
| 55 | # choose one of the above six options with the last letter |
| 56 | GRPC_TLS_OPTION=$GRPC_TLS_OPTION_Z |
| 57 | |
| 58 | [ $GRPC_TLS_OPTION ] && APPARGS="$APPARGS --enable-tls $GRPC_TLS_OPTION" |
| 59 | # ------------------------------------------------------------------------------ |
Thiyagarajan Subramani | 03bc66f | 2020-04-01 15:58:53 +0530 | [diff] [blame] | 60 | |
Girish Gowdra | d4aeca5 | 2020-06-11 11:27:29 -0700 | [diff] [blame] | 61 | # Include functions |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 62 | set -e |
| 63 | . /lib/lsb/init-functions |
| 64 | |
| 65 | start() { |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 66 | printf "Starting '$NAME'... " |
| 67 | export USER=$USER |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 68 | 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 |
| 73 | killtree() { |
| 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 | |
| 82 | stop() { |
| 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 Kupusoglu | 1fd7707 | 2021-03-23 08:13:25 -0700 | [diff] [blame^] | 88 | done |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 89 | [ -z `cat /var/run/$NAME.pid 2>/dev/null` ] || rm /var/run/$NAME.pid |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 90 | printf "done\n" |
| 91 | } |
| 92 | |
| 93 | status() { |
| 94 | status_of_proc -p /var/run/$NAME.pid $APPDIR/$APPBIN $NAME && exit 0 || exit $? |
| 95 | } |
| 96 | |
| 97 | case "$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 | ;; |
| 115 | esac |
| 116 | |
| 117 | exit 0 |