blob: 63c61a767b399ba061f7da8bad8a04843a2bf10d [file] [log] [blame]
Shad Ansarid0eaf752018-08-16 00:26:12 +00001#!/bin/sh
2
3### BEGIN INIT INFO
Girish Gowdraab7ea552020-01-07 13:25:15 +05304# Provides: dev_mgmt_daemon
Shad Ansarid0eaf752018-08-16 00:26:12 +00005# 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"
Jason Huang09b73ea2020-01-08 17:52:05 +080017APPARGS="-pcie -syslog"
Shad Ansarid0eaf752018-08-16 00:26:12 +000018USER="root"
19GROUP="root"
20
21# Include functions
22set -e
23. /lib/lsb/init-functions
24
25start() {
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000026 /opt/bcm68620/svk_init.sh
27 sleep 10
Shad Ansarid0eaf752018-08-16 00:26:12 +000028 printf "Starting '$NAME'... "
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000029 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$APPDIR
Jason Huang09b73ea2020-01-08 17:52:05 +080030 export USER=$USER
Girish Gowdraab7ea552020-01-07 13:25:15 +053031 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
Jason Huang09b73ea2020-01-08 17:52:05 +080032 sleep 2 && [ -z `pidof $NAME 2>/dev/null` ] || pidof $NAME > /var/run/$NAME.pid
Shad Ansarid0eaf752018-08-16 00:26:12 +000033 printf "done\n"
34}
35
36#We need this function to ensure the whole process tree will be killed
37killtree() {
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
46stop() {
47 printf "Stopping '$NAME'... "
Jason Huang09b73ea2020-01-08 17:52:05 +080048 [ -z "`pidof $NAME`" ] ||
49 for p in "`pidof $NAME`";do
50 killtree $p 15
51 sleep 0.5
52 done
53 rm -f /var/run/$NAME.pid
Shad Ansarid0eaf752018-08-16 00:26:12 +000054 printf "done\n"
55}
56
57status() {
Jason Huang09b73ea2020-01-08 17:52:05 +080058 status_of_proc -p /var/run/$NAME.pid $APPDIR/$APPBIN $NAME && exit 0 || exit $?
Shad Ansarid0eaf752018-08-16 00:26:12 +000059}
60
61case "$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 ;;
79esac
80
81exit 0