blob: 0fd80d85caeec5dcc969889df93b13a7c9a0ff31 [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"
17APPARGS="-d -pcie"
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() {
27 touch /var/log/$NAME.log
28 printf "Starting '$NAME'... "
29 start-stop-daemon --verbose --start --chuid "$USER:$GROUP" --background --no-close --make-pidfile --pidfile /var/run/$NAME.pid --chdir "$APPDIR" --exec "$APPBIN" -- $APPARGS < /dev/tty1 >> /var/log/$NAME.log 2>&1 || true
30 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'... "
45 [ -z `cat /var/run/$NAME.pid 2>/dev/null` ] || \
46 while test -d /proc/$(cat /var/run/$NAME.pid); do
47 killtree $(cat /var/run/$NAME.pid) 15
48 sleep 0.5
49 done
50 [ -z `cat /var/run/$NAME.pid 2>/dev/null` ] || rm /var/run/$NAME.pid
51 printf "done\n"
52}
53
54status() {
55 status_of_proc -p /var/run/$NAME.pid $APPDIR/$APPBIN $NAME && exit 0 || exit $?
56}
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