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