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" |
Girish Gowdra | 3a43976 | 2020-01-28 15:21:31 +0530 | [diff] [blame] | 17 | APPARGS="-pcie -d" |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 18 | USER="root" |
| 19 | GROUP="root" |
| 20 | |
Girish Gowdra | 3a43976 | 2020-01-28 15:21:31 +0530 | [diff] [blame] | 21 | # Include functions |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 22 | set -e |
| 23 | . /lib/lsb/init-functions |
| 24 | |
| 25 | start() { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 26 | /opt/bcm68620/svk_init.sh |
| 27 | sleep 10 |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 28 | printf "Starting '$NAME'... " |
Girish Gowdra | 3a43976 | 2020-01-28 15:21:31 +0530 | [diff] [blame] | 29 | touch /var/log/$NAME.log |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 30 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$APPDIR |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 31 | export USER=$USER |
Girish Gowdra | ab7ea55 | 2020-01-07 13:25:15 +0530 | [diff] [blame] | 32 | 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] | 33 | 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] | 34 | printf "done\n" |
| 35 | } |
| 36 | |
| 37 | #We need this function to ensure the whole process tree will be killed |
| 38 | killtree() { |
| 39 | local _pid=$1 |
| 40 | local _sig=${2-TERM} |
| 41 | for _child in $(ps -o pid --no-headers --ppid ${_pid}); do |
| 42 | killtree ${_child} ${_sig} |
| 43 | done |
| 44 | kill -${_sig} ${_pid} |
| 45 | } |
| 46 | |
| 47 | stop() { |
| 48 | printf "Stopping '$NAME'... " |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 49 | [ -z "`pidof $NAME`" ] || |
| 50 | for p in "`pidof $NAME`";do |
| 51 | killtree $p 15 |
| 52 | sleep 0.5 |
| 53 | done |
| 54 | rm -f /var/run/$NAME.pid |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 55 | printf "done\n" |
| 56 | } |
| 57 | |
| 58 | status() { |
Jason Huang | 09b73ea | 2020-01-08 17:52:05 +0800 | [diff] [blame] | 59 | 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] | 60 | } |
| 61 | |
| 62 | case "$1" in |
| 63 | start) |
| 64 | start |
| 65 | ;; |
| 66 | stop) |
| 67 | stop |
| 68 | ;; |
| 69 | restart) |
| 70 | stop |
| 71 | start |
| 72 | ;; |
| 73 | status) |
| 74 | status |
| 75 | ;; |
| 76 | *) |
| 77 | echo "Usage: $NAME {start|stop|restart|status}" >&2 |
| 78 | exit 1 |
| 79 | ;; |
| 80 | esac |
| 81 | |
| 82 | exit 0 |