Version 3 (modified by .faust, 14 years ago) (diff)

--

FreeBSD Init Script

Deluged

#!/bin/sh
#
#  deluged RCng startup script
#  created by: R.S.A. aka .faust 
#            mail: rsa dot aka dot f at gmail dot com
# 
 
# PROVIDE: deluged
# REQUIRE: NETWORKING SERVERS DAEMON ldconfig resolv
# BEFORE: LOGIN
# KEYWORD: shutdown
 
# Add the following line to /etc/rc.conf.local or /etc/rc.conf to enable deluged at startup
#       deluged_enable="YES"
#
# pidfile  (str):            Specify the full path to the PID file
# log (str):                    Specify the full path to the LOG file
# deluged_user (str):  Set to user running deluge-web
# cfg_dir (str):            Specify the full path to directory with deluge config files
# loglevel (str):      Set loglevel (Available: none, info, warning, error, critical, debug)
#
#  Warning! Rights to folders and files must be "rwx" for the user under which the run deluge 
 
. /etc/rc.subr
 
name="deluged"
rcvar=`set_rcvar`
 
load_rc_config $name
deluged_enable=${deluged_enable:=NO}

log="/home/deluge/${name}.log"
loglevel="error"
pidfile="/home/deluge/${name}.pid"
cfg_dir="/home/deluge/config/"
deluged_user="nobody"

required_dirs=${cfg_dir}

command_interpreter="/usr/local/bin/python"
command="/usr/local/bin/${name}"
start_cmd="${name}_start"

deluged_start()
{
if [ ! -f "${pidfile}" ]; then
    su -m ${deluged_user} -c "/usr/local/bin/${name} -c ${cfg_dir} -L ${loglevel} -l ${log} -P ${pidfile} > /dev/null 2>&1"
    echo "Starting ${name}."
else
    GETPROCESSPID=`/bin/ps -auxw | /usr/bin/awk '/deluged/ && !/awk/ && !/sh/ {print $2}'`
    PIDFROMFILE=`cat ${pidfile}`
    if [ "$GETPROCESSPID" = "$PIDFROMFILE" ]; then
        echo "${name} already running with PID: ${PIDFROMFILE} ?"  
        echo "Remove ${pidfile} manually if needed."
    else
        rm -f ${pidfile}
        su -m ${deluged_user} -c "/usr/local/bin/${name} -c ${cfg_dir} -l ${log} -P ${pidfile}"
        echo "Starting ${name}."
    fi
fi
}
 
 
run_rc_command "$1"

Web UI

#!/bin/sh
#
#  deluge-web RCng startup script
#  created by: R.S.A. aka .faust 
#            mail: rsa dot aka dot f at gmail dot com
# 
 
# PROVIDE: delugew
# REQUIRE: NETWORKING SERVERS DAEMON ldconfig resolv
# BEFORE: LOGIN
# KEYWORD: shutdown
 
# Add the following line to /etc/rc.conf.local or /etc/rc.conf to enable deluge-web at startup
#       delugew_enable="YES"
#
# pidfile  (str):            Specify the full path to the PID file
# log (str):                    Specify the full path to the LOG file
# delugew_user (str):  Set to user running deluge-web
# cfg_dir (str):            Specify the full path to directory with deluge config files
#
#  Warning! Rights to folders and files must be "rwx" for the user under which the run deluge 
. /etc/rc.subr
 
name="delugew"
rcvar=`set_rcvar`
 
load_rc_config $name
delugew_enable=${delugew_enable:=NO}

log="/home/deluge/${name}.log"
pidfile="/home/deluge/${name}.pid"
cfg_dir="/home/deluge/config/"
delugew_user="nobody"

required_dirs=${cfg_dir}

command_interpreter="/usr/local/bin/python"
command="/usr/local/bin/deluge-web"
start_cmd="${name}_start"
start_postcmd="${name}_poststart"

delugew_start()
{
if [ ! -f "${pidfile}" ]; then
    su -m ${delugew_user} -c "/usr/local/bin/deluge-web -f -c ${cfg_dir} -l ${log}"
    echo "Starting ${name}."
else
    GETPROCESSPID=`/bin/ps -auxw | /usr/bin/awk '/deluge-web/ && !/awk/ && !/sh/ {print $2}'`
    PIDFROMFILE=`cat ${pidfile}`
    if [ "$GETPROCESSPID" = "$PIDFROMFILE" ]; then
        echo "${name} already running with PID: ${PIDFROMFILE} ?"  
        echo "Remove ${pidfile} manually if needed."
    else
        rm -f ${pidfile}
        su -m ${delugew_user} -c "/usr/local/bin/deluge-web -f -c ${cfg_dir} -l ${log}"
        echo "Starting ${name}."
    fi
fi
}
 
delugew_poststart()
{
echo `/bin/ps -auxw | /usr/bin/awk '/deluge-web/ && !/awk/ {print $2}'` > $pidfile
}
 
run_rc_command "$1"