blob: 9e5a5a36d8258aae7cca796a4f29da955f7a8b49 [file] [log] [blame]
Shad Ansarid0eaf752018-08-16 00:26:12 +00001#!/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 Huangfd78f662019-06-05 20:25:01 +080013NAME="dev_mgmt_daemon"
Shad Ansarid0eaf752018-08-16 00:26:12 +000014PATH="/broadcom:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
15APPDIR="/broadcom"
Jason Huangfd78f662019-06-05 20:25:01 +080016APPBIN="dev_mgmt_daemon"
Jason Huang313ae312019-06-18 17:54:15 +080017APPARGS="-pcie -syslog"
Jason Huangfd78f662019-06-05 20:25:01 +080018PID_FILE="root_dev_mgmt_pid"
Shad Ansarid0eaf752018-08-16 00:26:12 +000019USER="root"
20GROUP="root"
21
22# Include functions
23set -e
24. /lib/lsb/init-functions
25
26start() {
Thiyagarajan Subramani1f1280b2019-08-13 18:41:19 +080027 /opt/bcm68620/svk_init.sh
Girish Gowdra022ba682019-10-10 15:13:23 +053028 sleep 10
Shad Ansarid0eaf752018-08-16 00:26:12 +000029 printf "Starting '$NAME'... "
Jason Huang313ae312019-06-18 17:54:15 +080030 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 Ansarid0eaf752018-08-16 00:26:12 +000032 printf "done\n"
33}
34
35#We need this function to ensure the whole process tree will be killed
36killtree() {
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
45stop() {
46 printf "Stopping '$NAME'... "
Jason Huang313ae312019-06-18 17:54:15 +080047 [ -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 Ansarid0eaf752018-08-16 00:26:12 +000050 sleep 0.5
51 done
Jason Huang313ae312019-06-18 17:54:15 +080052 [ -z `cat /tmp/$PID_FILE 2>/dev/null` ] || rm /tmp/$PID_FILE
Shad Ansarid0eaf752018-08-16 00:26:12 +000053 printf "done\n"
54}
55
56status() {
Jason Huang313ae312019-06-18 17:54:15 +080057 status_of_proc -p /tmp/$PID_FILE $APPDIR/$APPBIN $NAME && exit 0 || exit $?
Shad Ansarid0eaf752018-08-16 00:26:12 +000058}
59
60case "$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 ;;
78esac
79
80exit 0