Monday, July 13, 2009

Transmission-deamon Fedora init script

I've recently setup a my old PC as bittorent download station. I use Fedora 11 and I needed transmission-daemon statup script. After some diggig o internet I found only debian like scripts so I decided to write it my self. Here is the result. Use is freely and wisely.



#!/bin/bash
#
# /etc/rc.d/init.d/transmission-daemon
#
# Author: Miroslav Pilat
# chkconfig: 2345 13 87
# Description: Bittorrent client Transmission started as daemon
#

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

#
# ----- CONFIGURATION -----
#
# For the default location Transmission uses, visit:
# http://trac.transmissionbt.com/wiki/ConfigFiles
# For a guide on how set the preferences, visit:
# http://trac.transmissionbt.com/wiki/EditConfigFiles
# For the available environement variables, visit:
# http://trac.transmissionbt.com/wiki/EnvironmentVariables
#
# The name of the user that should run Transmission.
# It's RECOMENDED to run Transmission in it's own user,
# by default, this is set to 'transmission'.
# For the sake of security you shouldn't set a password
# on this user
USERNAME=transmission

# ----- *ADVANCED* CONFIGURATION -----
# Only change these options if you know what you are doing!
#
# The folder where Transmission stores the config & web files.
# ONLY change this you have it at a non-default location
#TRANSMISSION_HOME="/etc/transmission-daemon"
#TRANSMISSION_WEB_HOME="/usr/share/transmission/web"
#
# The arguments passed on to transmission-daemon.
# ONLY change this you need to, otherwise use the
# settings file as per above.
#TRANSMISSION_ARGS=""


# ----- END OF CONFIGURATION -----
#
# PATH should only include /usr/* if it runs after the mountnfs.sh script.
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
DESC="bittorrent client"
NAME=transmission-daemon
DAEMON=$(which $NAME)
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Read configuration variable file if it is present
if [ -f /etc/$NAME/$NAME.conf ]; then
. /etc/$NAME/$NAME.conf
fi

start() {
echo -n "Starting $NAME: "

if [ -n "$TRANSMISSION_HOME" ]; then
export TRANSMISSION_HOME
fi
if [ -n "$TRANSMISSION_WEB_HOME" ]; then
export TRANSMISSION_WEB_HOME
fi

if [ -f $PIDFILE ]; then
PID=`cat $PIDFILE`
echo $NAME already running: $PID
exit 2;
else
daemon $DAEMON $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/${NAME}
return $RETVAL
fi

touch /var/lock/subsys/${NAME}
return
}

stop() {
echo -n "Shutting down $NAME: "

killproc $NAME
rm -f /var/lock/subsys/${NAME}
return 0
}

case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $NAME
;;
restart)
stop
start
;;
*)
echo "Usage: {start|stop|status}"
exit 1
;;
esac
exit $?