blob: 14ef7a5ae9bcfd5e9ad5db2288b37d3f5bc6d309 [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() {
Shad Ansarid0eaf752018-08-16 00:26:12 +000027 printf "Starting '$NAME'... "
Jason Huang313ae312019-06-18 17:54:15 +080028 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$APPDIR
29 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 +000030 printf "done\n"
31}
32
33#We need this function to ensure the whole process tree will be killed
34killtree() {
35 local _pid=$1
36 local _sig=${2-TERM}
37 for _child in $(ps -o pid --no-headers --ppid ${_pid}); do
38 killtree ${_child} ${_sig}
39 done
40 kill -${_sig} ${_pid}
41}
42
43stop() {
44 printf "Stopping '$NAME'... "
Jason Huang313ae312019-06-18 17:54:15 +080045 [ -z `cat /tmp/$PID_FILE 2>/dev/null` ] || \
46 while test -d /proc/$(cat /tmp/$PID_FILE); do
47 killtree $(cat /tmp/$PID_FILE) 15
Shad Ansarid0eaf752018-08-16 00:26:12 +000048 sleep 0.5
49 done
Jason Huang313ae312019-06-18 17:54:15 +080050 [ -z `cat /tmp/$PID_FILE 2>/dev/null` ] || rm /tmp/$PID_FILE
Shad Ansarid0eaf752018-08-16 00:26:12 +000051 printf "done\n"
52}
53
54status() {
Jason Huang313ae312019-06-18 17:54:15 +080055 status_of_proc -p /tmp/$PID_FILE $APPDIR/$APPBIN $NAME && exit 0 || exit $?
Shad Ansarid0eaf752018-08-16 00:26:12 +000056}
57
58case "$1" in
59 start)
60 start
61 ;;
62 stop)
63 stop
64 ;;
65 restart)
66 stop
67 start
68 ;;
69 status)
70 status
71 ;;
72 *)
73 echo "Usage: $NAME {start|stop|restart|status}" >&2
74 exit 1
75 ;;
76esac
77
78exit 0