Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | ### BEGIN INIT INFO |
Girish Gowdra | ab7ea55 | 2020-01-07 13:25:15 +0530 | [diff] [blame] | 4 | # Provides: dev_mgmt_daemon |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 5 | # Required-Start: $local_fs $network $syslog |
| 6 | # Required-Stop: $network $local_fs $syslog |
| 7 | # Default-Start: 2 3 4 5 |
| 8 | # Default-Stop: 0 1 6 |
| 9 | # Short-Description: Broadcom BAL core daemon |
| 10 | # Description: Broadcom BAL core daemon |
| 11 | ### END INIT INFO |
| 12 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 13 | NAME="dev_mgmt_daemon" |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 14 | PATH="/broadcom:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" |
| 15 | APPDIR="/broadcom" |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 16 | APPBIN="dev_mgmt_daemon" |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 17 | USER="root" |
| 18 | GROUP="root" |
Jason Huang | dc83ba7 | 2020-11-16 22:08:43 +0800 | [diff] [blame^] | 19 | PORT_SPEED_FILE="$APPDIR/port_speed.soc" |
| 20 | TOPOLOGY_CONFIG_FILE="$APPDIR/topology_config.ini" |
| 21 | OLT_MODEL=`cat /sys/devices/virtual/dmi/id/board_name` |
| 22 | if [ $OLT_MODEL = "ASXvOLT16" ]; then |
| 23 | Port_100G_SPEED=`cat $PORT_SPEED_FILE | awk -F "port_speed_for_100 " '{print $2}'` |
| 24 | [ $Port_100G_SPEED = "10000" ] && TOPOLOGY_CONFIG_FILE="$APPDIR/topology_config_16_ports.ini" |
| 25 | APPARGS="-pcie -d -port_100g_speed $Port_100G_SPEED -topology_config_file $TOPOLOGY_CONFIG_FILE" |
| 26 | elif [ $OLT_MODEL = "ASGvOLT64" ]; then |
| 27 | Port_100G_SPEED=`cat $PORT_SPEED_FILE | awk -F "port_speed_for_100 " '{print $2}'` |
| 28 | [ $Port_100G_SPEED = "10000" ] && TOPOLOGY_CONFIG_FILE="$APPDIR/topology_config_16_ports.ini" |
| 29 | Port_25G_SPEED=`cat $PORT_SPEED_FILE | awk -F "port_speed_for_25 " '{print $2}'` |
| 30 | APPARGS="-pcie -d -port_100g_speed $Port_100G_SPEED -pcie -port_25g_speed $Port_25G_SPEED -topology_config_file $TOPOLOGY_CONFIG_FILE" |
| 31 | else |
| 32 | Port_100G_SPEED="100000" |
| 33 | Port_25G_SPEED="25000" |
| 34 | APPARGS="-pcie -d -port_100g_speed $Port_100G_SPEED -pcie -port_25g_speed $Port_25G_SPEED -topology_config_file $TOPOLOGY_CONFIG_FILE" |
| 35 | fi |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 36 | |
Girish Gowdra | 3a43976 | 2020-01-28 15:21:31 +0530 | [diff] [blame] | 37 | # Include functions |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 38 | set -e |
| 39 | . /lib/lsb/init-functions |
| 40 | |
| 41 | start() { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 42 | /opt/bcm68620/svk_init.sh |
| 43 | sleep 10 |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 44 | printf "Starting '$NAME'... " |
Girish Gowdra | 3a43976 | 2020-01-28 15:21:31 +0530 | [diff] [blame] | 45 | touch /var/log/$NAME.log |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 46 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$APPDIR |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 47 | export USER=$USER |
Girish Gowdra | ab7ea55 | 2020-01-07 13:25:15 +0530 | [diff] [blame] | 48 | start-stop-daemon --verbose --start --chuid "$USER:$GROUP" --background --no-close --chdir "$APPDIR" --exec "$APPBIN" -- $APPARGS < /dev/tty1 >> /var/log/$NAME.log 2>&1 || true |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 49 | sleep 2 && [ -z `pidof $NAME 2>/dev/null` ] || pidof $NAME > /var/run/$NAME.pid |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 50 | printf "done\n" |
| 51 | } |
| 52 | |
| 53 | #We need this function to ensure the whole process tree will be killed |
| 54 | killtree() { |
| 55 | local _pid=$1 |
| 56 | local _sig=${2-TERM} |
| 57 | for _child in $(ps -o pid --no-headers --ppid ${_pid}); do |
| 58 | killtree ${_child} ${_sig} |
| 59 | done |
| 60 | kill -${_sig} ${_pid} |
| 61 | } |
| 62 | |
| 63 | stop() { |
| 64 | printf "Stopping '$NAME'... " |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 65 | [ -z "`pidof $NAME`" ] || |
| 66 | for p in "`pidof $NAME`";do |
| 67 | killtree $p 15 |
| 68 | sleep 0.5 |
| 69 | done |
| 70 | rm -f /var/run/$NAME.pid |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 71 | printf "done\n" |
| 72 | } |
| 73 | |
| 74 | status() { |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 75 | status_of_proc -p /var/run/$NAME.pid $APPDIR/$APPBIN $NAME && exit 0 || exit $? |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | case "$1" in |
| 79 | start) |
| 80 | start |
| 81 | ;; |
| 82 | stop) |
| 83 | stop |
| 84 | ;; |
| 85 | restart) |
| 86 | stop |
| 87 | start |
| 88 | ;; |
| 89 | status) |
| 90 | status |
| 91 | ;; |
| 92 | *) |
| 93 | echo "Usage: $NAME {start|stop|restart|status}" >&2 |
| 94 | exit 1 |
| 95 | ;; |
| 96 | esac |
| 97 | |
| 98 | exit 0 |