Skip to content

Instantly share code, notes, and snippets.

@Zamana
Last active July 4, 2023 19:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zamana/021b69e754ccb8a4b30183c68885a471 to your computer and use it in GitHub Desktop.
Save Zamana/021b69e754ccb8a4b30183c68885a471 to your computer and use it in GitHub Desktop.

nzget

Installing NZBGet (the right way!) on FreeBSD/TrueNAS jail

O. Motivation

I did this a long time ago, and for reasons that doesn't matter right now, I need to do it again on November 2022. And I realized that I forgot some important steps (some "tricks" actually) which made me spent some precious time.

So, for my own reference, but mainly and most important: for the reference of all the futures generations that you walk on the surface of this planet, here is the straight forward steps in order to have NZBGet installed correctly in a FreeBSD or TrueNAS Jail (which is my case, by the way).

1. Disclaimer

In order to narrow things a bit, I will use some conventions here, but feel free to change them if know what you're doing.

All commands will be run as root.

By the way, I'll not explain here the process for create a jail in FreeBSD or TrueNAS. I'm assuming that you already has a jail, know how to build one or at least know how to search for how to know how to build one. Do your homework, kiddo.

2. The case of NZBGet in FreeBSD

If you search for nzbget in FreeBSD, you'll eventually find a package, ready to be installed:

pkg search nzbget
nzbget-21.1_2                  Binary newsreader supporting NZB files

but... don't do that.

This package seems somewhat "incomplete" and will install files in such a way that will turn things difficult to work. I really don't know the reasons, and I confess that I didn't try to understood them too much, because I was hoping for a seamless and smooth installation/configuration, exactly how I got from sonarr/radarr/lidarr/bazarr. Anyway...

In order to install NZBGet on FreeBSD, do this instead:

3. Installing NZBGet (the right way!) on FreeBSD/TrueNAS jail

3.1 Download the installer

First, go to this page, and download the installer:

cd /root
wget https://nzbget.net/download/nzbget-latest-bin-freebsd.run

NOTE: If you don't have wget and don't want to install it, you can use the native fetch, with the same results:

cd /root
fetch https://nzbget.net/download/nzbget-latest-bin-freebsd.run

Then turn on the executable bit:

chmod +x nzbget-latest-bin-freebsd.run

3.2 Run the installer

In order to follow the FreeBSD conventions, go to /usr/local/share and run the installer from there:

cd /usr/local/share
/root/nzbget-latest-bin-freebsd.run

The installer will create a folder nzbget at /usr/local/share. This folder will contain the NZBGet files.

3.2.1 Fixing unrar

The installer brings its own version of unrar, which doesn't work (segmentation fault). I guess it was compiled in another release of FreeBSD. In order to fix this, install unrar yourself:

pkg install unrar

unrar will be installed at /usr/local/bin. Now you have the option to keep things as they are and point NZBGet to find unrar at /usr/local/bin, or you can copy the working unrar to the installation folder. Both will work and this will be addressed later.

3.3 Folders

Beyond the /usr/local/share/nzbget, NZBGet will need at least 2 more folders: one for the configuration file, and another for downloading files.

Create them:

mkdir /usr/local/nzbget
mkdir /media/downloads

The first one follows the FreeBSD convention, and the second is free. If you decide to change it, remember to reflect your decision in the configuration file.

3.4 Configuration

COPY the sample config file from the installer folder to the destination config folder:

cp -av /usr/local/share/nzbget/nzbget.conf /usr/local/nzbget/

Note: DO NOT remove the nzbget.conf from /usr/local/share/nzbget; the system needs it right there, as a kind of "template" for the web interface. You have been warned!!!

3.5 User

Now you need to creat a user to run NZBGet.

As my system runs in a jail, and several of them needs to "talk" to each other, I prefer to run all my related systems under only one and just one user, in order to avoid the famous "Permission War From HELL" effect. In my specific case this user is always plex (you've got the idea...). So...

Create a user and give it the permissions in all relevant folders:

pw add user plex -d /usr/local/share/nzbget
chown -R plex:plex /usr/local/nzbget
chown plex:plex /media/downloads

3.6 Start script

To be able to control NZBGet with service and also to start it at system/jail boot, create a script in /usr/local/etc/rc.d/nzbget with the following contents:

#!/bin/sh

# PROVIDE: nzbget
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable the nzbget daemon:
#
# nzbget_enable="YES"
#
# Following additional settings are available:
#
# nzbget_user:    user to run nzbget as (recommended)
# nzbget_conf:    path to config if in a non-standard location (optional)

command=/usr/local/bin/nzbget

. /etc/rc.subr

load_rc_config nzbget

nzbget_enable=${nzbget_enable:-NO}
nzbget_user=${nzbget_user:-root}
nzbget_conf=${nzbget_conf:+"-c $nzbget_conf"}

name=nzbget
rcvar=nzbget_enable

start_cmd="nzbget_cmd -D"
stop_cmd="nzbget_cmd -Q"
reload_cmd="nzbget_cmd -O"

nzbget_cmd() {
  /usr/bin/su $nzbget_user -c "exec $command $nzbget_conf $1"
}

run_rc_command "$1"

and set the permissions:

chmod +x /usr/local/etc/rc.d/nzbget

3.7 Starting NZBGet at boot

Now configure NZBGet to start at boot with the correct user and using the config file:

sysrc nzbget_enable=YES
sysrc nzbget_user=plex
sysrc nzbget_conf="/usr/local/nzbget/nzbget.conf"

From now on you will be able to control the NZBGet system with:

service nzbget start | stop | status

4. Configuring NZBGet (the application)

After starting the application with service nzbget start, if everything is fine, you'll be able to access the WEB UI at:

  • http://<IP_ADDR>:6789

From all the configurations, these ones are mandatory to get NZBGet working properly:

4.1 Download folder

By default, NZBGet points the download folder to the home folder of the user under which it's running, and that's not always the case. In FreeBSD at least it's very common users which doesn't have a home folder. That's the case of our plex user, by the way. So the first thing is to change this and point to the download folder defined in 3.3 at the "PATHS" section:

nzbget_paths

4.2 Unpack programs

And lastly, configure the path to unrar and 7-Zip accordingly:

nzbget_unpack

5. Bonus: reverse proxy

If you want to avoid the ":6789" in your URL, you can put NZBGet behind a revere proxy.

Here is my configuration for Nginx:

server {
        listen       80;
        server_name  nzbget.lan;

        location / {
                proxy_pass http://IP_ADDR:6789;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }

which allows me to access NZBGet as "http://nzbget.lan".

NOTE: change "IP_ADDR" with the actual IP of your installation


I hope this guide will be helpful to you.

I'm open to all contributions and criticisms that you may have, including grammar and spelling mistakes.

Happy NZBGetting!

@atratus7
Copy link

Hi, I get to step 3.7 and when I run service nzbget start I get the message 'su: no directory'. Any ideas on what could be causing this? My start script is /usr/local/etc/rc.d/nzbget. Is that correct?

@Zamana
Copy link
Author

Zamana commented Dec 25, 2022

Hello atratus7!

Can you paste here the contents of your "/etc/rc.conf" file and the result of id plex, please?

Thanks!

@atratus7
Copy link

Hi Zamana,

Thanks for getting back to me so quickly.

Here's the contents of my "/etc/rc.conf" file.

_cron_flags="$cron_flags -J 15"

# Disable Sendmail by default
sendmail_enable="NO"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"

# Run secure syslog
syslogd_flags="-c -ss"

# Enable IPv6
ipv6_activate_all_interfaces="YES"
ifconfig_epair0b="SYNCDHCP"
nzbget_enable="YES"
nzbget_user="plex"
nzbget_conf="/usr/local/nzbget/nzbget.conf"_

And here's the result of running "id plex"

uid=1001(plex) gid=1001(plex) groups=1001(plex)

@Zamana
Copy link
Author

Zamana commented Dec 25, 2022

Ok.

Let's try something different.

Item 3.6. Change the line 34 from:

usr/bin/su -l $nzbget_user -c "exec $command $nzbget_conf $1"

to:

/usr/bin/su $nzbget_user -c "exec $command $nzbget_conf $1"

in the /usr/local/etc/rc.d/nzbget script.

Check if this works, please.

Thanks.

@atratus7
Copy link

Hi Zamana,

Unfortunately, that didn't work; however, I am getting different message now. Here are the steps I did.

I changed to the directory /usr/local/etc/rc.d and opened the startup script in nano

I didn't need to change line 34 because it was already

/usr/bin/su $nzbget_user -c "exec $command $nzbget_conf $1"

I changed it to

usr/bin/su $nzbget_user -c "exec $command $nzbget_conf $1"

saved the file and exited nano

I entered service nzbget start and got the message

start does not exist in /etc/rc.d or the local startup directories (/usr/local/etc/rc.d), or is not executable

I opened the script and changed line 34 back to

/usr/bin/su $nzbget_user -c "exec $command $nzbget_conf $1"

saved the file and exited nano

I entered service nzbget start and got the same message as before

I changed to the home directory for root@nzbgetjail, entered service nzbget start and got the same message again

@Zamana
Copy link
Author

Zamana commented Dec 25, 2022

Ok.

Please, post here the output of this command:

cat /etc/passwd | grep plex

@atratus7
Copy link

Here's the output of cat /etc/passwd | grep plex

plex:*:1001:1001:User &:/home/plex:/bin/sh

@Zamana
Copy link
Author

Zamana commented Dec 25, 2022

I supposed that you are logged in as "root" in your jail.

Post here the output of these two commands:

cd
su -l plex
pwd
exit

and

cd
su plex
pwd
exit

@atratus7
Copy link

Yep, logged in as "root".

cd - changed to home directory for root
su -l plex - su: no directory
pwd - /root
exit - shell closed

cd - changed to home directory for root
su plex - prompt changed to $
pwd - /root
exit - prompt changed back to root@nzbgetjail:~ #

@Zamana
Copy link
Author

Zamana commented Dec 26, 2022

Ok.

It seems to me that "/home/plex" folder does not exist. Let's set the plex home folder to "/usr/local/share/nzbget":

pw user mod plex -d /usr/local/share/nzbget

After this, try to execute both commands again and if they succeed, try to start the service with:

service nzbget start

@atratus7
Copy link

OK. I've set the plex home folder as you directed and this was the output for both commands.

cd - changed to home directory for root
su -l plex - prompt changed to $
pwd - /usr/local/share/nzbget
exit - prompt changed back to root@nzbgetjail:~ #

cd - changed to home directory for root
su plex - prompt changed to $
pwd - /root
exit - prompt changed back to root@nzbgetjail:~ #

I tried starting the service with service nzbget start and got the following output

root@nzbgetjail:~ # service nzbget start
nzbget.conf(55): Invalid value for option "TempDir" (/usr/local/share/nzbget/downloads/tmp):
could not create directory /usr/local/share/nzbget/downloads: Permission denied
nzbget.conf(52): Invalid value for option "QueueDir" (/usr/local/share/nzbget/downloads/queue):
could not create directory /usr/local/share/nzbget/downloads: Permission denied

I checked the permissions on /usr/local/share/nzbget and got the following output

root@nzbgetjail:~ # ls -l /usr/local/share/nzbget
total 6528
-rwxr-xr-x 1 plex plex 2298200 Jun 4 2021 7za
-rw-r--r-- 1 plex plex 201623 Jun 4 2021 cacert.pem
-rw-r--r-- 1 plex plex 180715 Jun 4 2021 ChangeLog
-rw-r--r-- 1 plex plex 18091 Jun 4 2021 COPYING
-rwxr-xr-x 1 plex plex 5169 Jun 4 2021 install-update.sh
-rw-r--r-- 1 root wheel 24 Dec 25 15:10 installer.cfg
-rw-r--r-- 1 plex plex 1878 Jun 4 2021 license-7zip.txt
-rw-r--r-- 1 plex plex 1976 Jun 4 2021 license-unrar.txt
-rwxr-xr-x 1 plex plex 6938448 Jun 4 2021 nzbget
-rw-r--r-- 1 root wheel 66847 Dec 4 13:09 nzbget.conf
-rw-r--r-- 1 plex plex 451 Jun 4 2021 pubkey.pem
-rw-r--r-- 1 plex plex 15876 Jun 4 2021 README
drwxr-xr-x 2 plex plex 4 Dec 25 15:10 scripts
-rwxr-xr-x 1 plex plex 1384680 Jun 4 2021 unrar
drwxr-xr-x 4 plex plex 19 Dec 25 15:10 webui

@Zamana
Copy link
Author

Zamana commented Dec 26, 2022

Ok.

I guess that the problems with the user plex are fixed now. Good.

Check if the nzbget process is running. You can do this with:

service nzbget status

or

netstat -an | grep 6789

Once nzbget is running, you need to follow on with 4.1 section, defining where you want the downloads are saved etc. The directories you will choose need to be writeable by the plex user.

If you're in a jail, probably you'll need to do bind mounts from the host inside the jail.

@atratus7
Copy link

I ran service nzbget status and the service wasn't running.

I created the following folders that were mentioned in the output when I tried service nzbget start

/usr/local/share/nzbget/downloads
/usr/local/share/nzbget/downloads/nzb
/usr/local/share/nzbget/downloads/queue
/usr/local/share/nzbget/downloads/tmp

I get no output when I run service nzbget start but service nzbget status reports that the service isn't running

Any ideas on where I should look now?

@Zamana
Copy link
Author

Zamana commented Dec 26, 2022

I guess that the best way is try to run the process manually, from command line, and see what it says.

Run NZBGet from command line, as the plex user:

su -l plex
nzbget -D -c nzbget.conf

Check if there are any messages. If not, check if it is listening at port 6789:

netstat -an | grep 6789

If so, try to access the web interface: http://:6789

@atratus7
Copy link

Hmmm. I'm not getting any messages when I run nzbget from the command line as the plex user; but I'm not getting any output when I run the netstat command either.

I think I need to go away and do more research on creating jails and users and granting permissions in TrueNAS / FreeBSD.

Also I don't want to keep taking up your time, which you've been very generous with so far. I don't want to impose on your generosity any more especially at this time of year when you should be spending time with your family.

Thank you very much for all of your help. I'll let you know how I get on.

@Zamana
Copy link
Author

Zamana commented Dec 26, 2022

Hello!

I'm really sorry for not being able to help you with this issue.

It could be something you missed from the tutorial, or could be some step that I forgot to mention. For example, I already fixed the user creation by adding the home folder. Thanks!

Anyway, here is the command that I use to create my jails, if you like to try:

#!/bin/sh

NAME="$1"
IP="$2"
RELEASE="13.1-RELEASE"
GW="192.168.0.1"

iocage create -n $NAME \
        -r $RELEASE \
        vnet="on" \
        defaultrouter=$GW \
        ip4_addr="vnet0|$IP/24" \
        ip6_addr=none \
        allow_raw_sockets=1 \
        allow_mlock=1 \
        dhcp=off \
        bpf=yes \
        boot=on

iocage set mount_fdescfs=1 $NAME
iocage set mount_procfs=1 $NAME

You'll need to adjust the gateway of your network (my network is /24; check yours), and probably the RELEASE (check your other jails).

To use, pass as argument the NAME of the jail you want to create and an IP in your network that is not being used.

Best wishes!

@MichaelInkster
Copy link

@atratus7,
I have just gone through and had the same issues as you. I was able to resolve it by using the following in the rc.d file:

#!/bin/sh

# PROVIDE: nzbget
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable the nzbget daemon:
#
# nzbget_enable="YES"
#
# Following additional settings are available:
#
# nzbget_user:    user to run nzbget as (recommended)
# nzbget_conf:    path to config if in a non-standard location (optional)

. /etc/rc.subr

name=nzbget
rcvar=nzbget_enable

load_rc_config $name

start_cmd="nzbget_cmd -D"
stop_cmd="nzbget_cmd -Q"
reload_cmd="nzbget_cmd -O"

command="/usr/local/share/nzbget/nzbget"

: ${nzbget_enable:=NO}
: ${nzbget_user:=root}
: ${nzbget_conf:="/usr/local/nzbget/nzbget.conf"}

nzbget_cmd() {
  exec su $nzbget_user -c "$command -c $nzbget_conf $1"
}

run_rc_command "$1"

hopefully this will help you get yours running.

@MichaelInkster
Copy link

And the main changes to my version of the rc.d file for anyone that is interested:

  • command runs from /usr/local/share (stated in 3.2 of the guide as the folder to install into)
  • I also add a second nzbget to the command variable to get to the application rather than the folder
  • Changed the variables format to match the rc.d scripting guidance on freebsd documents
  • Put the /usr/local/nzbget/nzbget.conf as the default path for the nzbget_conf variable
  • modified the exec command string to call exec with su, user, and the parameters after it (didn't work without this format change).

Thankyou @Zamana for getting this documented. I would have struggled without this guidance.

@Zamana
Copy link
Author

Zamana commented Mar 6, 2023

Hello!

Thanks for the contribution.

I updated the article with my current (and working!) version of the rc script. Here is the difference between our versions now:

16,17d15
< command=/usr/local/bin/nzbget
<
20,25d17
< load_rc_config nzbget
<
< nzbget_enable=${nzbget_enable:-NO}
< nzbget_user=${nzbget_user:-root}
< nzbget_conf=${nzbget_conf:+"-c $nzbget_conf"}
<
28a21,22
> load_rc_config $name
>
32a27,32
> command="/usr/local/share/nzbget/nzbget"
>
> : ${nzbget_enable:=NO}
> : ${nzbget_user:=root}
> : ${nzbget_conf:="/usr/local/nzbget/nzbget.conf"}
>
34c34
<   /usr/bin/su $nzbget_user -c "exec $command $nzbget_conf $1"
---
>   exec su $nzbget_user -c "$command -c $nzbget_conf $1"

And, in my case, here is the relevant lines in /etc/rc.conf:

nzbget_enable="YES"
nzbget_user="plex"
nzbget_conf="/usr/local/nzbget/nzbget.conf"

@BenediktGeisberger
Copy link

Thank you @Zamana soooooooo much for this guide. I was almost giving up.
I ran into the same problems as @atratus7 but luckily the script version of @MichaelInkster worked for my TrueNas (v12) system.

Thank you both for your efforts and updating this guide.

@mimikm
Copy link

mimikm commented Jul 4, 2023

hi, if I follow tutorial to the letter i get:

env: /usr/local/etc/rc.d/nzbget: Permission denied

service will not start, only deviation was to change user to nzbget from plex

@MichaelInkster
Copy link

Hi @mimikm,
Which rc.d script are you using to start the service, the one in the tutorial or the one I had posted in the comments? The version that I posted in the comments appears to have also worked for some people that have not had success with the version in the tutorial

@Zamana
Copy link
Author

Zamana commented Jul 4, 2023

Hi!

Here is the version that I'm currently using and it is working:

#!/bin/sh

# PROVIDE: nzbget
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable the nzbget daemon:
#
# nzbget_enable="YES"
#
# Following additional settings are available:
#
# nzbget_user:    user to run nzbget as (recommended)
# nzbget_conf:    path to config if in a non-standard location (optional)

command=/usr/local/bin/nzbget

. /etc/rc.subr

load_rc_config nzbget

nzbget_enable=${nzbget_enable:-NO}
nzbget_user=${nzbget_user:-root}
nzbget_conf=${nzbget_conf:+"-c $nzbget_conf"}

name=nzbget
rcvar=nzbget_enable

start_cmd="nzbget_cmd -D"
stop_cmd="nzbget_cmd -Q"
reload_cmd="nzbget_cmd -O"

nzbget_cmd() {
  /usr/bin/su $nzbget_user -c "exec $command $nzbget_conf $1"
}

run_rc_command "$1"

Note that the user which runs the process nzbget is plex, but you need to run the /usr/local/etc/rc.d/nzbget script as root.

Regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment