iso8583.init 1.52 KB
#!/bin/sh

### BEGIN INIT INFO
# Provides:          iso8583-bjb-bphtb
# Required-Start:    cron 
# Required-Stop:     cron 
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6 
# Short-Description: ISO 8583 Forwarder BJB BPHTB 
# Description:       BJB BPHTB ISO 8583 Forwarder
### END INIT INFO

BIN="/home/bphtb/bin/start"
PID="/home/bphtb/tmp/iso8583-bphtb.pid"
DESC="ISO8583 Forwarder BPHTB BJB"
USER="bphtb"
GROUP="bphtb"

CONF="/home/bphtb/bjb-bphtb/production.ini"
# /home/samsat-banten/iso8583-web/env/bin/iso8583 \
#    /home/samsat-banten/iso8583-web/iso8583.ini \
#    $@


. /lib/lsb/init-functions

killtree() {
    local _pid=$1
    local _sig=${2-TERM}
    for _child in $(ps -o pid --no-headers --ppid ${_pid}); do
        killtree ${_child} ${_sig}
    done
    kill -${_sig} ${_pid}
}

case $1 in
  start)
    log_begin_msg "Starting $DESC"
    [ -z `cat $PID 2>/dev/null` ] && \
      /sbin/start-stop-daemon --start --chuid "$USER:$GROUP" --background \
        --make-pidfile $PID --pidfile $PID --exec $BIN || true
    log_end_msg $?
    ;;
    
  stop)
      log_begin_msg "Stopping $DESC PID $(cat $PID)"
    [ -z `cat $PID 2>/dev/null` ] || \
        while test -d /proc/$(cat $PID); do
            killtree $(cat $PID) 15
            sleep 0.5
        done
    [ -z `cat $PID 2>/dev/null` ] || rm $PID

    log_end_msg $?
    ;;

  status)
    status_of_proc -p $PID "" $DESC && exit 0 || exit $?
    ;;

  restart)
    $0 stop
    sleep 3
    $0 start
    ;;
    
  *) echo "Usage: $0 {start|stop|restart|status}"
esac

exit 0