Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | ### BEGIN INIT INFO |
| 4 | # Provides: bal_core_dist |
| 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" |
| 17 | APPARGS="-pcie -syslog" |
| 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'... " |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 30 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$APPDIR |
| 31 | start-stop-daemon --verbose --start --chuid "$USER:$GROUP" --background --no-close --chdir "$APPDIR" --exec "$APPBIN" -- $APPARGS 2>&1 || true |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 32 | printf "done\n" |
| 33 | } |
| 34 | |
| 35 | #We need this function to ensure the whole process tree will be killed |
| 36 | killtree() { |
| 37 | local _pid=$1 |
| 38 | local _sig=${2-TERM} |
| 39 | for _child in $(ps -o pid --no-headers --ppid ${_pid}); do |
| 40 | killtree ${_child} ${_sig} |
| 41 | done |
| 42 | kill -${_sig} ${_pid} |
| 43 | } |
| 44 | |
| 45 | stop() { |
| 46 | printf "Stopping '$NAME'... " |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 47 | [ -z `cat /tmp/$PID_FILE 2>/dev/null` ] || \ |
| 48 | while test -d /proc/$(cat /tmp/$PID_FILE); do |
| 49 | killtree $(cat /tmp/$PID_FILE) 15 |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 50 | sleep 0.5 |
| 51 | done |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 52 | [ -z `cat /tmp/$PID_FILE 2>/dev/null` ] || rm /tmp/$PID_FILE |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 53 | printf "done\n" |
| 54 | } |
| 55 | |
| 56 | status() { |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 57 | 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] | 58 | } |
| 59 | |
| 60 | case "$1" in |
| 61 | start) |
| 62 | start |
| 63 | ;; |
| 64 | stop) |
| 65 | stop |
| 66 | ;; |
| 67 | restart) |
| 68 | stop |
| 69 | start |
| 70 | ;; |
| 71 | status) |
| 72 | status |
| 73 | ;; |
| 74 | *) |
| 75 | echo "Usage: $NAME {start|stop|restart|status}" >&2 |
| 76 | exit 1 |
| 77 | ;; |
| 78 | esac |
| 79 | |
| 80 | exit 0 |