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` |
Thiyagarajan Subramani | 3e8bfd9 | 2021-04-26 15:07:14 +0530 | [diff] [blame] | 22 | PRODUCT_NAME= |
| 23 | |
Thiyagarajan Subramani | a2c2c5a | 2021-05-18 14:47:52 +0530 | [diff] [blame] | 24 | # RLT-3200G-W - wait for onlp driver to load |
Thiyagarajan Subramani | 3e8bfd9 | 2021-04-26 15:07:14 +0530 | [diff] [blame] | 25 | if [ "$OLT_MODEL" = "Default string" ]; then |
| 26 | RETRY_COUNT=0 |
| 27 | while [ -z "$PRODUCT_NAME" ] |
| 28 | do |
| 29 | PRODUCT_NAME=$(onlpd -s | grep Part | awk '{print $3}') |
| 30 | echo "RETRY_COUNT=$RETRY_COUNT, product name=$PRODUCT_NAME" |
| 31 | sleep 1 |
| 32 | RETRY_COUNT=$((RETRY_COUNT+1)) |
| 33 | done |
| 34 | OLT_MODEL=$PRODUCT_NAME |
| 35 | fi |
| 36 | |
Thiyagarajan Subramani | 3e8bfd9 | 2021-04-26 15:07:14 +0530 | [diff] [blame] | 37 | APPARGS="-pcie -d" |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 38 | |
Girish Gowdra | 3a43976 | 2020-01-28 15:21:31 +0530 | [diff] [blame] | 39 | # Include functions |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 40 | set -e |
| 41 | . /lib/lsb/init-functions |
| 42 | |
| 43 | start() { |
Thiyagarajan Subramani | 3e8bfd9 | 2021-04-26 15:07:14 +0530 | [diff] [blame] | 44 | if [ "$OLT_MODEL" = "ASGvOLT64" ] || [ "$OLT_MODEL" = "ASXvOLT16" ]; then |
| 45 | /opt/bcm68620/svk_init.sh |
Thiyagarajan Subramani | 4e62e17 | 2021-06-25 17:31:30 +0530 | [diff] [blame] | 46 | elif [ "$OLT_MODEL" = "RLT-3200G" ] || [ "$OLT_MODEL" = "RLT-1600G" ] || [ "$OLT_MODEL" = "RLT-1600X" ]; then |
Thiyagarajan Subramani | 3e8bfd9 | 2021-04-26 15:07:14 +0530 | [diff] [blame] | 47 | /opt/bcm68650/svk_init.sh |
| 48 | fi |
| 49 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 50 | sleep 10 |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 51 | printf "Starting '$NAME'... " |
Girish Gowdra | 3a43976 | 2020-01-28 15:21:31 +0530 | [diff] [blame] | 52 | touch /var/log/$NAME.log |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 53 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$APPDIR |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 54 | export USER=$USER |
Girish Gowdra | ab7ea55 | 2020-01-07 13:25:15 +0530 | [diff] [blame] | 55 | 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] | 56 | 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] | 57 | printf "done\n" |
| 58 | } |
| 59 | |
| 60 | #We need this function to ensure the whole process tree will be killed |
| 61 | killtree() { |
| 62 | local _pid=$1 |
| 63 | local _sig=${2-TERM} |
| 64 | for _child in $(ps -o pid --no-headers --ppid ${_pid}); do |
| 65 | killtree ${_child} ${_sig} |
| 66 | done |
| 67 | kill -${_sig} ${_pid} |
| 68 | } |
| 69 | |
| 70 | stop() { |
| 71 | printf "Stopping '$NAME'... " |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 72 | [ -z "`pidof $NAME`" ] || |
| 73 | for p in "`pidof $NAME`";do |
| 74 | killtree $p 15 |
| 75 | sleep 0.5 |
| 76 | done |
| 77 | rm -f /var/run/$NAME.pid |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 78 | printf "done\n" |
| 79 | } |
| 80 | |
| 81 | status() { |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 82 | 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] | 83 | } |
| 84 | |
| 85 | case "$1" in |
| 86 | start) |
| 87 | start |
| 88 | ;; |
| 89 | stop) |
| 90 | stop |
| 91 | ;; |
| 92 | restart) |
| 93 | stop |
| 94 | start |
| 95 | ;; |
| 96 | status) |
| 97 | status |
| 98 | ;; |
| 99 | *) |
| 100 | echo "Usage: $NAME {start|stop|restart|status}" >&2 |
| 101 | exit 1 |
| 102 | ;; |
| 103 | esac |
| 104 | |
| 105 | exit 0 |