[How To] NzbHydra2 in a iocage jail (FN 11.2)

Yakje

Explorer
Joined
Feb 8, 2017
Messages
82
While i was looking for an installation guide on how to install NzbHydra2 in a iocage jail in FN11.2, i was unable to find any.
Since i do really like the added benefit of running nzbhydra2, i tried to figure it out for myself and eventually succeeded!
I figured this could also be helpfull for others, which is why i decided to share it here.

Create jail + install dependencies
echo '{"pkgs":["openjdk8","python27","ca_root_nss"]}' > /tmp/pkg.json
iocage create -n "nzbhydra" -p /tmp/pkg.json -r 11.2-RELEASE ip4_addr="vnet0|<JAIL IP>/24" defaultrouter="<DEFAULT GATEWAY IP>" vnet="on" allow_raw_sockets="1" boot="on"
rm /tmp/pkg.json

Create config folder + mount points
iocage exec nzbhydra mkdir -p /config
iocage fstab -a nzbhydra /mnt/tank/apps/nzbhydra /config nullfs rw 0 0

Download and install NzbHydra2 (you can change the link to a newer release if you desire)
iocage exec nzbhydra ln -s /usr/local/bin/python2.7 /usr/local/bin/python
iocage exec nzbhydra "fetch https://github.com/theotherp/nzbhydra2/releases/download/v2.3.19/nzbhydra2-2.3.19-linux.zip -o /usr/local/share"
iocage exec nzbhydra "unzip /usr/local/share/nzbhydra2-2.3.19-linux.zip -d /usr/local/share/Nzbhydra"
iocage exec nzbhydra rm /usr/local/share/nzbhydra2-2.3.19-linux.zip

Download nzbhydrawrapper
iocage exec nzbhydra "fetch https://raw.githubusercontent.com/theotherp/nzbhydra2/master/other/wrapper/nzbhydra2wrapper.py -o /usr/local/share/Nzbhydra"

Set permissions
iocage exec nzbhydra "pw user add nzbhydra2 -c nzbhydra2 -u 1001 -d /nonexistent -s /usr/bin/nologin"
iocage exec nzbhydra chown -R nzbhydra2:nzbhydra2 /config /usr/local/share/Nzbhydra

Create rc directory
iocage exec nzbhydra mkdir /usr/local/etc/rc.d

Upload NzbHydra2 RC file to: /usr/local/etc/rc.d
Code:
#!/bin/sh
#
# PROVIDE: nzbhydra2
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# nzbhydra2_enable (bool):    Set to NO by default.
#            Set it to YES to enable it.
# nzbhydra2_user:    The user account nzbhydra daemon runs as what
#            you want it to be. It uses '_sabnzbd' user by
#            default. Do not sets it as empty or it will run
#            as root.
# nzbhydra2_group:    The group account nzbhydra daemon runs as what
#            you want it to be. It uses 'nzbhydra2' group by
#            default. Do not sets it as empty or it will run
#            as wheel.
# nzbhydra2_dir:    Directory where nzbhydra lives.
#            Default: /usr/local/nzbhydra2
# nzbhydra2_datafolder:    Data directory for nzbhydra (DB, Logs, config)
#            Default is same as nzbhydra2_dir/data

. /etc/rc.subr

name="nzbhydra2"
rcvar=${name}_enable

load_rc_config ${name}

: ${nzbhydra2_enable:="NO"}
: ${nzbhydra2_user:="nzbhydra2"}
: ${nzbhydra2_group:="nzbhydra2"}
: ${nzbhydra2_dir:="/usr/local/nzbhydra2"}
: ${nzbhydra2_datafolder:="${nzbhydra2_dir}/data"}

pidfile="/var/run/nzbhydra2/nzbhydra2.pid"
command="/usr/local/bin/python2.7"
command_args="${nzbhydra2_dir}/nzbhydra2wrapper.py --datafolder ${nzbhydra2_datafolder} --pidfile ${pidfile} --daemon --nobrowser"

start_precmd="prestart"
prestart() {
    if [ -f ${pidfile} ]; then
        rm -f ${pidfile}
        echo "Removing stale pidfile."
    elif [ ! -d ${pidfile%/*} ]; then
        install -d -o ${nzbhydra2_user} -g ${nzbhydra2_group} ${pidfile%/*}
    fi

    if [ ! -d ${nzbhydra2_datadir} ]; then
        install -d -o ${nzbhydra2_user} -g ${nzbhydra2_group} ${nzbhydra2_datadir}
    fi
}

run_rc_command "$1"

Make rc file readable and start nzbhydra2
iocage exec nzbhydra chmod u+x /usr/local/etc/rc.d/nzbhydra2
iocage exec nzbhydra sysrc "nzbhydra2_enable=YES"
iocage exec nzbhydra sysrc "nzbhydra2_user=nzbhydra2"
iocage exec nzbhydra sysrc "nzbhydra2_dir=/usr/local/share/Nzbhydra"
iocage exec nzbhydra sysrc "nzbhydra2_datafolder=/config"
iocage exec nzbhydra service nzbhydra2 start

NzbHydra2 should now be able at:
http://<JailIP>:5076
 

Mr. Slumber

Contributor
Joined
Mar 10, 2019
Messages
182
Wow! It thougt this would not be possible! Thanks! :)
 

hertzsae

Contributor
Joined
Sep 23, 2014
Messages
118
Thanks for the write up! I modified your instructions a bit and was able to get up and running with python 3 which is now supported. Here are the changes that need to be made to your instructions for python3 if you'd like to update your guide:

1. Install python 3 instead of 2.7 (and openjdk13 instead of openjdk8):
echo '{"pkgs":["openjdk8","python27","ca_root_nss"]}' > /tmp/pkg.json
becomes
echo '{"pkgs":["openjdk13","python3","ca_root_nss"]}' > /tmp/pkg.json

2. Fetch a newer version that supports python 3:
Do a find on "2.3.19" and replace with "2.14.1"

3. Remove the following line where you link python to python2.7 as no linking is needed:
iocage exec nzbhydra ln -s /usr/local/bin/python2.7 /usr/local/bin/python

4. In the RC file, change the following two lines:
command="/usr/local/bin/python2.7"
command_args="${nzbhydra2_dir}/nzbhydra2wrapper.py --datafolder ${nzbhydra2_datafolder} --pidfile ${pidfile} --daemon --nobrowser"
becomes
command="/usr/local/bin/python3"
command_args="${nzbhydra2_dir}/nzbhydra2wrapperPy3.py --datafolder ${nzbhydra2_datafolder} --pidfile ${pidfile} --daemon --nobrowser"

Also, if anyone is wondering what an easy way to get the RC file in place, I just did the following:
1. Open vi editor on the file (it will be created when you save it)
> iocage exec nzbhydra vi /usr/local/etc/rc.d/nzbhydra2
2. Type the letter 'i' which puts vi in insertion mode
3. Paste the contents of the file to your terminal window
4. Hit the Escape key to put vi in command mode
5. Type the colon key to start a command
6. Type 'wq' to Write and Quit (no quotes)
 
Last edited:

hertzsae

Contributor
Joined
Sep 23, 2014
Messages
118
I was looking through the latest commits and they finally made hydra compatible with versions of openjdk newer than 8. I edited the above pkg install line to openjdk13 instead of 8 as well. If someone is installing from scratch, they may as well be as future proof as possible.
 

Anicet

Cadet
Joined
Mar 31, 2020
Messages
5
I was looking through the latest commits and they finally made hydra compatible with versions of openjdk newer than 8. I edited the above pkg install line to openjdk13 instead of 8 as well. If someone is installing from scratch, they may as well be as future proof as possible.


I did everything from main post with changes you came up with. Jail is up and running but for some reason I cant open webinterface to manage nzbhydra like I do on other plugins (radarr and sonarr). I tried http://myfreenasip:5076 nothing . I am total newb when it comes to the freeenas but I did noticed one thing when running "iocage create -n "nzbhydra" -p /tmp/pkg.json -r 11.2-RELEASE ip4_addr="vnet0|<JAIL IP>/24" defaultrouter="<DEFAULT GATEWAY IP>" vnet="on" " ip4_addr="vnet0| while I picked nat and vnet when installing plugins. Any help or pointer are greatly appreciated!

Thx OP and hertzsea
 

hertzsae

Contributor
Joined
Sep 23, 2014
Messages
118
Here's the script that I installed with and I'll attach the RC file. It installs a slightly older version of hydra, but it can be updated via the GUI afterwards. I just tested the script in another jail and it still works. I'm on the latest version of 11.2U8. Any commands containing "Vol1" will need to be modified per your pathing.
# Use the bash shell
bash
# Create the jail
iocage create -n "nzbhydra" -r 11.2-RELEASE interfaces="vnet0:bridge0" defaultrouter="none" vnet="on" dhcp="on" bpf="yes" allow_raw_sockets="1" boot="on"

# Update to the latest repo and make sure it prints "FreeBSD: {url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest"}"
iocage exec nzbhydra "mkdir -p /usr/local/etc/pkg/repos"
iocage exec nzbhydra "echo 'FreeBSD: {url: \"pkg+http://pkg.FreeBSD.org/\${ABI}/latest\"}' > /usr/local/etc/pkg/repos/FreeBSD.conf"
iocage exec nzbhydra cat /usr/local/etc/pkg/repos/FreeBSD.conf

iocage exec nzbhydra pkg update
iocage exec nzbhydra pkg upgrade
iocage exec nzbhydra pkg install -y openjdk13 python3 security/ca_root_nss

# Create config folder + mount points
iocage exec nzbhydra mkdir -p /config
iocage fstab -a nzbhydra /mnt/Vol1/jail_config_data/nzbhydra /config nullfs rw 0 0


# Download and install NzbHydra2 (you can change the link to a newer release if you desire)
iocage exec nzbhydra "fetch https://github.com/theotherp/nzbhydra2/releases/download/v2.14.1/nzbhydra2-2.14.1-linux.zip -o /usr/local/share"
iocage exec nzbhydra "unzip /usr/local/share/nzbhydra2-2.14.1-linux.zip -d /usr/local/share/Nzbhydra"
iocage exec nzbhydra rm /usr/local/share/nzbhydra2-2.14.1-linux.zip


# Download nzbhydrawrapper
iocage exec nzbhydra "fetch https://raw.githubusercontent.com/theotherp/nzbhydra2/master/other/wrapper/nzbhydra2wrapperPy3.py -o /usr/local/share/Nzbhydra"

# Set permissions
iocage exec nzbhydra "pw user add nzbhydra2 -c nzbhydra2 -u 1001 -d /nonexistent -s /usr/bin/nologin"
iocage exec nzbhydra chown -R nzbhydra2:nzbhydra2 /config /usr/local/share/Nzbhydra

#Create rc directory
iocage exec nzbhydra mkdir /usr/local/etc/rc.d

# Upload NzbHydra2 RC file to: /usr/local/etc/rc.d
# Show : Nzbhydra2 RC file
# Make rc file readable and start nzbhydra2

###### Copy and paste the contentns of the RC file into the vi window (remember press i to insert first and after pasted press 'ESC' then ':wq')
iocage exec nzbhydra vi /usr/local/etc/rc.d/nzbhydra2

# Set service loading parameters
iocage exec nzbhydra chmod u+x /usr/local/etc/rc.d/nzbhydra2
iocage exec nzbhydra sysrc "nzbhydra2_enable=YES"
iocage exec nzbhydra sysrc "nzbhydra2_user=nzbhydra2"
iocage exec nzbhydra sysrc "nzbhydra2_dir=/usr/local/share/Nzbhydra"
iocage exec nzbhydra sysrc "nzbhydra2_datafolder=/config"
iocage exec nzbhydra service nzbhydra2 start

# Take snapshots before updating
zfs snapshot -r Vol1/jail_config_data/nzbhydra@NzbhydraUpgrade-`date +%Y%m%d`
zfs snapshot -r Vol1/iocage/jails/nzbhydra@NzbhydraUpgrade-`date +%Y%m%d`
 

Attachments

  • nzbhydra2 RC File.txt
    1.8 KB · Views: 362

msbxa

Contributor
Joined
Sep 21, 2014
Messages
151
Another shot method tested and works on FreeNAS 11.3-U2.1:

This will install nzbhydra2 v2.7.2. The Latest version: can be updated within nzbhydra2

Create nzbhydra2 jail through WebGui

iocage console nzbhydra2

pkg install nzbhydra2

chmod -R 777 /usr/local/share/nzbhydra2 If you need to update within nzbhydra2 you have to set permissions to 777.
chmod u+x /usr/local/etc/rc.d/nzbhydra2
sysrc nzbhydra2_enable=YES
service nzbhydra2 start

NzbHydra2 should now be able at: http://xxx.xxx.xxx.xxx.xxx:5076/
 

slimslider

Cadet
Joined
Nov 14, 2018
Messages
4
Another shot method tested and works on FreeNAS 11.3-U2.1:

This will install nzbhydra2 v2.7.2. The Latest version: can be updated within nzbhydra2

Create nzbhydra2 jail through WebGui

iocage console nzbhydra2

pkg install nzbhydra2

chmod -R 777 /usr/local/share/nzbhydra2 If you need to update within nzbhydra2 you have to set permissions to 777.
chmod u+x /usr/local/etc/rc.d/nzbhydra2
sysrc nzbhydra2_enable=YES
service nzbhydra2 start

NzbHydra2 should now be able at: http://xxx.xxx.xxx.xxx.xxx:5076/


Thanks for this! This was much simpler, so I tried this and it's working fine. Is there some disadvantage of setting it up this way?
 

hertzsae

Contributor
Joined
Sep 23, 2014
Messages
118
I was unaware that a package version existed when I did my install. Assuming that updates through the GUI work fine, then I don't see any major disadvantages. The only issue I see right now is that hydra was recently updated to allow python 3 instead of python 2. The package install currently uses python 2, but I'm sure that will change in the future. You can check on the freshports page - https://www.freshports.org/news/nzbhydra2/
 
Top