#!/bin/bash
#
# Startup script for Ziproxy
#
# chkconfig: - 86 14
# description: Ziproxy

# Copyright (c)2005-2006 Daniel Mealha Cabrita

PROGNAME="Ziproxy"

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

rc_done="  done"
rc_failed="  failed"

return=$rc_done

PID_FILE=/var/run/ziproxy.pid
ZIPROXY=/usr/bin/ziproxy
ZIPROXY_CONF=/etc/ziproxy/ziproxy.conf

case "$1" in
start)
	gprintf "Starting %s: " "${PROGNAME}"
	if [ -f ${PID_FILE} ]; then
		echo " "
		echo "ERROR: Ziproxy already running ("${PID_FILE}"). Aborting."
		failure
	else
		${ZIPROXY} -d -c ${ZIPROXY_CONF} >${PID_FILE}
		if [ $? != 0 ]; then
			rm -f ${PID_FILE}
			failure
		else
			success
		fi
	fi
	echo
	;;
	
stop)
	gprintf "Stopping %s: " "${PROGNAME}"

	if [ ! -f ${PID_FILE} ]; then
		failure
	else
		PID=`cat ${PID_FILE}`
		kill ${PID}
		rm -f ${PID_FILE}
		success
	fi

	echo
	;;
		
restart|reload)
        $0 stop
        $0 start
        ;;

*)
        gprintf "Usage: %s {start|stop|restart}\n" "${PROGNAME}"
        exit 1

esac

