Shad Ansari | d0eaf75 | 2018-08-16 00:26:12 +0000 | [diff] [blame^] | 1 | #!/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 | |
| 13 | NAME="bal_core_dist" |
| 14 | PATH="/broadcom:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" |
| 15 | APPDIR="/broadcom" |
| 16 | #APPBIN="/broadcom/bal_core_dist" |
| 17 | APPBIN="bal_core_dist" |
| 18 | APPARGS="-C :55001" |
| 19 | USER="root" |
| 20 | GROUP="root" |
| 21 | |
| 22 | # Include functions |
| 23 | set -e |
| 24 | . /lib/lsb/init-functions |
| 25 | |
| 26 | start() { |
| 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 |
| 34 | killtree() { |
| 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 | |
| 43 | stop() { |
| 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 | |
| 54 | status() { |
| 55 | status_of_proc -p /var/run/$NAME.pid $APPDIR/$APPBIN $NAME && exit 0 || exit $? |
| 56 | } |
| 57 | |
| 58 | case "$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 | ;; |
| 76 | esac |
| 77 | |
| 78 | exit 0 |