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
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000013NAME="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"
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000016APPBIN="dev_mgmt_daemon"
17APPARGS="-pcie -syslog"
18PID_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 Subramani89fffc02019-05-13 21:33:20 +000027 /opt/bcm68620/svk_init.sh
28 sleep 10
Shad Ansarid0eaf752018-08-16 00:26:12 +000029 printf "Starting '$NAME'... "
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000030 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'... "
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000047 [ -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
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000052 [ -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() {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000057 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