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 | |
Jason Huang | fd78f66 | 2019-06-05 20:25:01 +0800 | [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" |
Jason Huang | fd78f66 | 2019-06-05 20:25:01 +0800 | [diff] [blame] | 16 | APPBIN="dev_mgmt_daemon" |
Jason Huang | 313ae31 | 2019-06-18 17:54:15 +0800 | [diff] [blame] | 17 | APPARGS="-pcie -syslog" |
Jason Huang | fd78f66 | 2019-06-05 20:25:01 +0800 | [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 | 1f1280b | 2019-08-13 18:41:19 +0800 | [diff] [blame] | 27 | /opt/bcm68620/svk_init.sh |
Girish Gowdra | 022ba68 | 2019-10-10 15:13:23 +0530 | [diff] [blame] | 28 | sleep 10 |
Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame] | 29 | printf "Starting '$NAME'... " |
Jason Huang | 313ae31 | 2019-06-18 17:54:15 +0800 | [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'... " |
Jason Huang | 313ae31 | 2019-06-18 17:54:15 +0800 | [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 |
Jason Huang | 313ae31 | 2019-06-18 17:54:15 +0800 | [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() { |
Jason Huang | 313ae31 | 2019-06-18 17:54:15 +0800 | [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 |