blob: 3fc9d780f5ee34694b3117ca3865e7599fd5c740 [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
13NAME="bal_core_dist"
14PATH="/broadcom:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
15APPDIR="/broadcom"
16#APPBIN="/broadcom/bal_core_dist"
17APPBIN="bal_core_dist"
18APPARGS="-C :55001"
19USER="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