#!/bin/bash
#
# Initfile for Tinyproxy daemon
#
# chkconfig: 345 90 25
# description: A small, efficient HTTP/SSL proxy daemon.
#
# processname: tinyproxy
# config: /etc/tinyproxy/tinyproxy.conf
# pidfile: /var/run/tinyproxy.pid

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

# Source networking configuration.
source /etc/sysconfig/network

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0

[ -f /etc/tinyproxy/tinyproxy.conf ] || exit 0

DAEMON="/usr/bin/tinyproxy"
OPTIONS=
NAME=tinyproxy
DESC=tinyproxy

if [ -r /etc/sysconfig/tinyproxy ]; then
    . /etc/sysconfig/tinyproxy
fi

test -f $DAEMON || exit 0


case "$1" in
  start)
    echo -n "Starting $DESC: "
    daemon $DAEMON $OPTIONS
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$NAME
    ;;
  stop)
    echo -n "Stopping $DESC: "
    killproc $DAEMON
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$NAME
    ;;
  reload|force-reload)
    echo -n "Reloading $DESC configuration files."
    killproc $DAEMON -HUP
    echo
    ;;
  status)
    status $DAEMON
    ;;
  restart)
    echo -n "Restarting $DESC: "
    echo
    $0 stop
    $0 start
    RETVAL=$?
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|reload|force-reload|status}"
    exit 1
    ;;
esac

exit $RETVAL
