Blob Blame History Raw
#!/bin/bash
#
# opentracker An open and free BitTorrent tracker
#
# chkconfig: - 55 45
# description: An open and free BitTorrent tracker
# processname: /usr/bin/opentracker-ipv4
# config: /etc/opentracker-ipv4/opentracker-ipv4.conf
# pidfile: /var/run/opentracker-ipv4.pid

### BEGIN INIT INFO
# Provides: opentracker-ipv4
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $network $remote_fs
# Default-Start:
# Default-Stop:
# Short-Description: A BitTorrent tracker
# Description: An open and free BitTorrent tracker
### END INIT INFO

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

if [ -f /etc/sysconfig/opentracker-ipv4 ]; then
	. /etc/sysconfig/opentracker-ipv4
fi

RETVAL=0
prog=opentracker-ipv4
lockfile=/var/lock/subsys/$prog
pidfile=/var/run/$prog.pid
binary=/usr/bin/$prog
chroot=/var/opentracker
conf=/etc/opentracker/opentracker-ipv4.conf

start() {
	echo -n $"Starting $prog: "
	$binary -f $conf -m $OPTIONS

	# Horrible, but works
	if [ $? -eq 0 ]; then
	    pidof -o $$ -o $PPID -o %PPID -x $binary > $pidfile

	    if [ $? -eq 0 ]; then
		echo_success
	    else
		rm -f $pidfile
		echo_failure
		RETVAL=1
	    fi
	else
	    echo_failure
	    RETVAL=1
	fi

	echo
	[ $RETVAL -eq 0 ] && touch $lockfile

	return $RETVAL
}

stop() {
	echo -n $"Stopping $prog: "
	killproc $prog
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f $lockfile

	return $RETVAL
}

restart() {
	stop
	start
}

# See how we were called.
case "$1" in
    start)
		start
		;;
    stop)
		stop
		;;
    restart|force-reload|reload)
		restart
		;;
    status)
		status $prog
		RETVAL=$?
		;;
    condrestart|try-restart)
		if [ -f ${pidfile} ]; then
			stop
			start
		fi
		;;
    *)
		echo $"Usage: $prog {start|stop|status|reload|restart|condrestart|force-reload|try-restart}"
		RETVAL=1
esac

exit $RETVAL