This is the old XigmaNAS forum in read only mode,
it will taken offline by the end of march 2021!



I like to aks Users and Admins to rewrite/take over important post from here into the new fresh main forum!
Its not possible for us to export from here and import it to the main forum!

[HOWTO] Install Deluge in Finch / Qjail

Jails with XigmaNAS
Forum rules
Set-Up GuideFAQsForum Rules
Post Reply
mekonghigh
Starter
Starter
Posts: 39
Joined: 13 Oct 2013 18:03
Status: Offline

[HOWTO] Install Deluge in Finch / Qjail

Post by mekonghigh »

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

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_identity
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

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"
Set permisssions on the script

Code: Select all

chmod 555 /usr/local/etc/rc.d/deluged
Set the deamons run at startup

Code: Select all

echo 'deluged_enable="YES"' >> /etc/rc.conf
echo 'deluged_user="deluge"' >> /etc/rc.conf 
Start and stop the deluge deamon to create the default config files

Code: Select all

/usr/local/etc/rc.d/deluged start
/usr/local/etc/rc.d/deluged stop
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.:

Code: Select all

echo "alice:MyC0mpL3xPass:10" >> /usr/local/deluge/.config/deluge/auth
Edit /etc/protocols and disable ipv6 by placing "#" in front of ipv6
Search for:

Code: Select all

ipv6	41	IPV6		# ipv6 
Change to:

Code: Select all

#ipv6	41	IPV6		# ipv6 
Start the deluge deamon

Code: Select all

/usr/local/etc/rc.d/deluged start 
Using your web browser go to http://IPAddress:8112 and log in with the password deluge.

Post Reply

Return to “Jails”