[HOWTO] Install Deluge in Finch / Qjail
Posted: 18 Aug 2014 13:38
Install Deluge inside a jail created with Finch / Qjail.
Create a Deluge Group and a Deluge user (nologin, primary group: deluge, home directory: /mnt/nonexistent) in NAS4free webgui: Access|Users.
Enter the Jail
Edit the startup script for the deamon to add deluge web interface
Now copy the following into the file /usr/local/etc/rc.d/deluged
Set permisssions on the script
Set the deamons run at startup
Start and stop the deluge deamon to create the default config files
Add User to the authentication file
The next step is to create a Deluge user for clients/UIs to access the daemon remotely.
The auth file should contain lines with only ‘::’, replacing and with your choice and with the desired authentication level.
You can use your favourite text editor to achieve this or can be done with a one-line echo command e.g.:
Edit /etc/protocols and disable ipv6 by placing "#" in front of ipv6
Search for:
Change to:
Start the deluge deamon
Using your web browser go to http://IPAddress:8112 and log in with the password deluge.
Create a Deluge Group and a Deluge user (nologin, primary group: deluge, home directory: /mnt/nonexistent) in NAS4free webgui: Access|Users.
Enter the Jail
Code: Select all
pw useradd -n deluge -u <user_ID> -c "Deluge BitTorrent Client" -s /sbin/nologin -w no
echo 'OPTIONS_UNSET=X11' >> /etc/make.conf
pkg update -f
pkg install net-p2p/deluge
mkdir -p /usr/local/deluge/.config/deluge
chown -R deluge:deluge /usr/local/deluge/
pkg install py27-pip
pip install service_identityNow copy the following into the file /usr/local/etc/rc.d/deluged
Code: Select all
#!/bin/sh
# $FreeBSD: net-p2p/deluge/files/deluged.in 300897 2012-07-14 14:29:18Z beat $
#
# PROVIDE: deluged
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# MANDATORY:
#
# deluged_enable (bool): Set to NO by default.
# Set it to YES to enable deluged.
#
# deluged_user (str): The UNPRIVILEGED user to run as
#
# OPTIONAL:
#
# deluged_flags (str): Set as needed
# See deluged(1) for more information
#
# deluged_confdir (path): Set to /home/$deluged_user/.config/deluge
# by default
#
# deluged_loglevel (str): Set to "error" by default
#
# deluged_logfile (path): Set to /var/tmp/deluged.log by default
#
# deluged_weblogfile (path): Set to /var/tmp/deluge-web.log by default
. /etc/rc.subr
name="deluged"
webname="deluge-web"
rcvar=deluged_enable
command=/usr/local/bin/${name}
webcommand=/usr/local/bin/${webname}
command_interpreter="/usr/local/bin/python2.7"
pidfile=/var/run/${name}/pid
webpidfile=/var/run/${webname}/pid
start_precmd=${name}_prestart
start_postcmd=${name}_poststart
stop_precmd=${name}_prestop
stop_postcmd=${name}_poststop
deluged_prestart()
{
if [ "$deluged_user" = 'asjklasdfjklasdf' ]; then
err 1 "You must set deluged_user to a real, unprivileged user"
fi
if [ ! -d "/var/run/${name}" ]; then
if [ -e "/var/run/${name}" ]; then
unlink /var/run/${name}
fi
mkdir -p /var/run/${name}
fi
if [ ! -d "/var/run/${webname}" ]; then
if [ -e "/var/run/${webname}" ]; then
unlink /var/run/${webname}
fi
mkdir -p /var/run/${webname}
fi
chmod 0755 /var/run/${name}
chown -R $deluged_user /var/run/${name}
chmod 0755 /var/run/${webname}
chown -R $deluged_user /var/run/${webname}
}
deluged_poststart()
{
if [ ! -f "${webpidfile}" ]; then
su -m ${deluged_user} -c "${webcommand} ${webcommand_args}"
echo "Starting ${webname}."
echo `/bin/ps -auxw | /usr/bin/awk '/deluge-web/ && !/awk/ {print $2}'` > $webpidfile
else
GETPROCESSPID=`/bin/ps -auxw | /usr/bin/awk '/deluge-web/ && !/awk/ && !/sh/ {print $2}'`
PIDFROMFILE=`cat ${webpidfile}`
if [ "$GETPROCESSPID" = "$PIDFROMFILE" ]; then
echo "${webname} already running with PID: ${PIDFROMFILE} ?"
echo "Remove ${webpidfile} manually if needed."
else
rm -f ${webpidfile}
su -m ${deluged_user} -c "${webcommand} ${webcommand_args}"
echo "Starting ${webname}."
echo `/bin/ps -auxw | /usr/bin/awk '/deluge-web/ && !/awk/ {print $2}'` > $webpidfile
fi
fi
}
deluged_prestop()
{
PIDFROMFILE=`cat ${webpidfile}`
kill ${PIDFROMFILE}
[ -e "$webpidfile" ] && unlink $webpidfile
[ -d "${webpidfile%/pid}" ] && rmdir ${webpidfile%/pid}
[ -e "$deluged_weblogfile" -a ! -s "$deluged_weblogfile" ] &&
unlink $deluged_weblogfile
}
deluged_poststop()
{
[ -e "$pidfile" ] && unlink $pidfile
[ -d "${pidfile%/pid}" ] && rmdir ${pidfile%/pid}
[ -e "$deluged_logfile" -a ! -s "$deluged_logfile" ] &&
unlink $deluged_logfile
}
load_rc_config $name
: ${deluged_enable:="NO"}
: ${deluged_user:="asjklasdfjklasdf"}
: ${deluged_confdir:="/usr/local/${deluged_user}/.config/deluge"}
: ${deluged_loglevel:="error"}
: ${deluged_logfile:="/var/tmp/${name}.log"}
: ${deluged_weblogfile:="/var/tmp/${webname}.log"}
required_dirs="$deluged_confdir"
command_args="-c $required_dirs -L $deluged_loglevel -l $deluged_logfile -P $pidfile"
webcommand_args="-f -c $required_dirs -L $deluged_loglevel -l $deluged_weblogfile"
run_rc_command "$1"Code: Select all
chmod 555 /usr/local/etc/rc.d/delugedCode: Select all
echo 'deluged_enable="YES"' >> /etc/rc.conf
echo 'deluged_user="deluge"' >> /etc/rc.conf Code: Select all
/usr/local/etc/rc.d/deluged start
/usr/local/etc/rc.d/deluged stopThe next step is to create a Deluge user for clients/UIs to access the daemon remotely.
The auth file should contain lines with only ‘::’, replacing and with your choice and with the desired authentication level.
You can use your favourite text editor to achieve this or can be done with a one-line echo command e.g.:
Code: Select all
echo "alice:MyC0mpL3xPass:10" >> /usr/local/deluge/.config/deluge/authSearch for:
Code: Select all
ipv6 41 IPV6 # ipv6 Code: Select all
#ipv6 41 IPV6 # ipv6 Code: Select all
/usr/local/etc/rc.d/deluged start