#!/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
LOCKFILE=/run/lock/subsys/byedpi
RETVAL=0

SourceIfNotEmpty /etc/sysconfig/byedpi

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

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

restart()
{
    stop
    start
}

# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart|reload)
        restart
        ;;
    condstop)
        if [ -f "$LOCKFILE" ]; then
            stop
        fi
        ;;
    condrestart|condreload)
        if [ -f "$LOCKFILE" ]; then
            restart
        fi
        ;;
    status)
        status --pidfile "$PIDFILE" --expect-user byedpi -- /usr/bin/ciadpi
        RETVAL=$?
        ;;
    *)
        msg_usage "${0##*/} {start|stop|restart|condstop|condrestart|status}"
        RETVAL=1
esac

exit $RETVAL
