blob: 7637c6d8a5994532690679fd5a99e8745d76a91e [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"
Girish Gowdra3a439762020-01-28 15:21:31 +053017APPARGS="-pcie -d"
Shad Ansarid0eaf752018-08-16 00:26:12 +000018USER="root"
19GROUP="root"
20
Girish Gowdra3a439762020-01-28 15:21:31 +053021# Include functions
Shad Ansarid0eaf752018-08-16 00:26:12 +000022set -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'... "
Girish Gowdra3a439762020-01-28 15:21:31 +053029 touch /var/log/$NAME.log
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000030 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$APPDIR
Jason Huang09b73ea2020-01-08 17:52:05 +080031 export USER=$USER
Girish Gowdraab7ea552020-01-07 13:25:15 +053032 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 +080033 sleep 2 && [ -z `pidof $NAME 2>/dev/null` ] || pidof $NAME > /var/run/$NAME.pid
Shad Ansarid0eaf752018-08-16 00:26:12 +000034 printf "done\n"
35}
36
37#We need this function to ensure the whole process tree will be killed
38killtree() {
39 local _pid=$1
40 local _sig=${2-TERM}
41 for _child in $(ps -o pid --no-headers --ppid ${_pid}); do
42 killtree ${_child} ${_sig}
43 done
44 kill -${_sig} ${_pid}
45}
46
47stop() {
48 printf "Stopping '$NAME'... "
Jason Huang09b73ea2020-01-08 17:52:05 +080049 [ -z "`pidof $NAME`" ] ||
50 for p in "`pidof $NAME`";do
51 killtree $p 15
52 sleep 0.5
53 done
54 rm -f /var/run/$NAME.pid
Shad Ansarid0eaf752018-08-16 00:26:12 +000055 printf "done\n"
56}
57
58status() {
Jason Huang09b73ea2020-01-08 17:52:05 +080059 status_of_proc -p /var/run/$NAME.pid $APPDIR/$APPBIN $NAME && exit 0 || exit $?
Shad Ansarid0eaf752018-08-16 00:26:12 +000060}
61
62case "$1" in
63 start)
64 start
65 ;;
66 stop)
67 stop
68 ;;
69 restart)
70 stop
71 start
72 ;;
73 status)
74 status
75 ;;
76 *)
77 echo "Usage: $NAME {start|stop|restart|status}" >&2
78 exit 1
79 ;;
80esac
81
82exit 0