#! /bin/bash
#
# nat44-logging          Start/Stop the CGN logging.
#
# chkconfig: 2345 90 60
# description: script to send NAT translation setup to syslog local2

### BEGIN INIT INFO
# Provides: nat44-logging.sh
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start:  2345
# Default-Stop: 90
# Short-Description: run nat44-logging daemon
# Description: script to send NAT translation setup to syslog local2
### END INIT INFO

RETVAL=0
prog="nat44-logging.sh"
exec=/usr/local/ns/bin/nat44-logging.sh
lockfile=/var/lock/subsys/nat44-logging
pidfile=/var/run/nat44-logging.pid

# Source function library.
. /etc/rc.d/init.d/functions


start() {
    if [ $UID -ne 0 ] ; then
        echo "User has insufficient privilege."
        exit 4
    fi
    [ -x $exec ] || exit 5
    echo -n $"Starting $prog: "
    ($exec 1>/dev/null 2>/dev/null &) &
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
}

stop() {
    if [ $UID -ne 0 ] ; then
        echo "User has insufficient privilege."
        exit 4
    fi
    echo -n $"Stopping $prog: "
    killproc -p $pidfile $prog
    retval=$?
    killall conntrack
    retval2=$?
    echo
    [ $retval -eq 0 -a $retval2 -eq 0 ] && rm -f $lockfile
}

restart() {
    stop
    start
}

reload() {
    restart
}

force_reload() {
    # new configuration takes effect after restart
    restart
}

rh_status() {
    # run checks to determine if the service is running or use generic status
    status -p $pidfile $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}


case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reloa
d}"
        exit 2
esac
exit $?
