#!/bin/sh
#
# byedpi - starts the ciadpi daemon
#
# chkconfig: 345 95 05
# description: A local SOCKS proxy for users in DPI envoronments 
#
# processname: ciadpi
# pidfile: /run/byedpi/byedpi.pid
#
### BEGIN INIT INFO
# Provides: byedpi
# Required-Start: $syslog $network
# Required-Stop: $syslog $network
# Default-Start:  3 4 5
# Default-Stop:   0 1 2 6
# Short-Description: byedpi service
# Description: A local SOCKS proxy for users in DPI envoronments
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

PIDFILE=/run/byedpi/byedpi.pid
RETVAL=0

SourceIfNotEmpty /etc/sysconfig/byedpi

start()
{
    start_daemon --pidfile "$PIDFILE" --user byedpi --background \
        --make-pidfile -- /usr/bin/ciadpi $BYEDPI_ARGS
    RETVAL=$?
    return $RETVAL
}

stop()
{
    stop_daemon --pidfile "$PIDFILE" --expect-user byedpi -- /usr/bin/ciadpi
    RETVAL=$?
    return $RETVAL
    rm -f $PIDFILE
}

restart()
{
    stop
    start
}

_status()
{
    status --pidfile "$PIDFILE" --expect-user byedpi -- /usr/bin/ciadpi
    RETVAL=$?
    return $RETVAL
}

# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart|reload)
        restart
        ;;
    condstop)
        _status >/dev/null 2>&1
        if [ $? -eq 0 ]; then
            stop
        fi
        ;;
    condrestart|condreload)
        _status >/dev/null 2>&1
        if [ $? -eq 0 ]; then
            restart
        fi
        ;;
    status)
        _status
        ;;
    *)
        msg_usage "${0##*/} {start|stop|restart|condstop|condrestart|status}"
        RETVAL=1
esac

exit $RETVAL
