qBittorrent run FileBot on TrueNAS CORE

Any questions? Need some help?
Post Reply
tratento
Posts: 3
Joined: 10 Sep 2022, 01:41

qBittorrent run FileBot on TrueNAS CORE

Post by tratento »

Hi.

I'm running TrueNAS-13.0-U2, with qbt (4.3.8) and Filebot (4.9.6) running in a jail.

I've had qbt successfully running an external program before, although just a simple copy command:

Code: Select all

cp -r -n "%F" "/var/db/qbittorrent/Temp/"
I've also been using Filebot successfully using the CLI.

Code: Select all

filebot -script fn:sysinfo
produces:

Code: Select all

FileBot 4.9.6 (r9125)
JNA Native: 6.1.1
MediaInfo: 22.06
Tools: fpcalc/1.5.0
Extended Attributes: OK
Unicode Filesystem: OK
Script Bundle: 2022-08-15 (r836)
Groovy: 3.0.9
JRE: OpenJDK Runtime Environment 11.0.16
JVM: OpenJDK 64-Bit Server VM
CPU/MEM: 12 Core / 17 GB Max Memory / 78 MB Used Memory
OS: FreeBSD (amd64)
HW: FreeBSD qbittorrent 13.1-RELEASE-p1 FreeBSD 13.1-RELEASE-p1 n245406-814eb095751 TRUENAS  amd64
STORAGE: zfs [/] @ 198 GB
USER: root
DATA: /usr/local/share/filebot/data/0
Package: TAR
License: FileBot License P41253391 (Valid-Until: 2023-09-16)
Done ヾ(@⌒ー⌒@)ノ
I've tried the suggestions on the AMC page but can't seem to get it to work.

I've also tried basics like:

Code: Select all

filebot -script fn:sysinfo > output.txt

Code: Select all

/usr/local/bin/filebot -script fn:sysinfo > output.txt
But even find can't find output.txt

The qbt logs show that it does try to run it:

Code: Select all

...running external program, command: filebot -script fn:sysinfo > output.txt
Has anyone had success getting qBittorrent to run FileBot on TrueNAS CORE?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: qBittorrent run FileBot on TrueNAS CORE

Post by rednoah »

1.
Replace your in-line command:

Code: Select all

cp -r -n "%F" "/var/db/qbittorrent/Temp/"
with a customs script:

Code: Select all

/path/to/qbt-postprocess "%F"

2.
Ensure that your /path/to/qbt-postprocess is actually called:
viewtopic.php?t=3067


3.
You now have a bash script that is confirmed to work form qBT, but also works independently of qBT, so you can do rapid prototyping and testing until it works on the command-line without qBT. Most importantly, you will now be able to capture console output for each command and see why it doesn't work if it doesn't work when called by qBT for some reason:
https://github.com/filebot/plugins/blob ... h/debug.sh



:idea: Note that qBT doesn't interpret bash syntax such as > IO redirection, i.e. you're probably doing this, i.e. pass ">" as argument value:

Code: Select all

$ echo "printenv" ">" "output.txt"
printenv > output.txt


:idea: If you do printenv > output.txt then that's the same as printenv > "$PWD/output.txt" (in bash, not qBT) and so that's where the file goes, except you don't know $PWD, and so you don't know where the file goes. So we always use absolute paths as to eliminate unknown variables and variable behaviour.


e.g. Where does the file go? Don't know! What does pwd say?

Code: Select all

printenv > output.txt
e.g. Where does the file go? /path/to/output.txt

Code: Select all

printenv > /path/to/output.txt
:idea: Please read the FAQ and How to Request Help.
tratento
Posts: 3
Joined: 10 Sep 2022, 01:41

Re: qBittorrent run FileBot on TrueNAS CORE

Post by tratento »

I really appreciate your help with this. Although I think I'm fundamentally not understanding something.

So I've put the below in qBT:

Code: Select all

/root/script/filebot/test.sh "%F"
With test.sh being:

Code: Select all

#!/bin/sh

printenv > /root/output.txt 2>&1
I've confirmed that test.sh works and creates 'output.txt' (in the expected location) by running it from the CLI.

Then when I complete a download in qBT I have confirmed that it outputs the command via the qBT logs:

Code: Select all

(N) 2022-09-10T17:32:20 - 'XYZ' added to download list.
(N) 2022-09-10T17:32:58 - Enqueued to move "XYZ" from "/var/db/qbittorrent/claim/Torrents/_Temp_/" to "/var/db/qbittorrent/claim/Torrents/Downloads".
(N) 2022-09-10T17:32:58 - Moving "XYZ" to "/var/db/qbittorrent/claim/Torrents/Downloads"...
(N) 2022-09-10T17:32:58 - "XYZ" is successfully moved to "/var/db/qbittorrent/claim/Torrents/Downloads".
(N) 2022-09-10T17:32:58 - Torrent: XYZ, running external program, command: /root/script/filebot/test.sh "/var/db/qbittorrent/claim/Torrents/Downloads/XYZ"
But 'output.txt' isn't generated.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: qBittorrent run FileBot on TrueNAS CORE

Post by rednoah »

rednoah wrote: 09 Oct 2015, 16:48 First we make sure that our script is actually called, by adding simple debugging statements like this:

Code: Select all

printenv > "/path/to/log.txt"
By making a simple call that can't fail, we confirm that the script is called, and that we have file permissions to our log file. Make sure that the user running your script does have write permissions for your log location.
You should never run as root, as you have probably heard before. :lol:

Code: Select all

USER: root
:idea: You should run as normal user. If you run as normal user, then you will find that your normal user does not have write permission to /root and other system folders. If qBT is running as normal user - as it should be - then it does not have permission to write to /root and other system folders either - as it should be. ;)


:idea: I recommend copy & pasting the sample test script verbatim as that is guaranteed to work (unless you don't have /tmp write permission) and then checking if it works, and then making changes step by step, checking if it still works after every change:
https://github.com/filebot/plugins/blob ... h/debug.sh
:idea: Please read the FAQ and How to Request Help.
tratento
Posts: 3
Joined: 10 Sep 2022, 01:41

Re: qBittorrent run FileBot on TrueNAS CORE

Post by tratento »

Permissions, permissions, permissions... That should be TrueNAS's slogan.

I should know better by now.

So, probably telling a lot of you to suck eggs, but this might help someone out there.

I changed the location of the script to where qBT is in a TrueNAS jail:

Code: Select all

/var/db/qbittorrent/test.sh
and had the .txt file be generated in the same location:

Code: Select all

#!/bin/sh

printenv > /var/db/qbittorrent/output.txt 2>&1
This worked!

So next was to see what happened when FileBot was called. It gave a few errors, basically now that qBT (UserID 850) was trying to run FileBot it couldn't create its data directory.
I first tried manually creating the directory and chown it to qBT.

Code: Select all

mkdir /usr/local/share/filebot/data/850

chown -R qbittorrent:qbittorrent 850
Then had qBT call the script as below:

Code: Select all

#!/bin/sh

filebot -script fn:sysinfo > /var/db/qbittorrent/output.txt 2>&1
This worked!

So onwards to tweaking it to get it to work.

Edit:
rednoah wrote: 10 Sep 2022, 08:39
rednoah wrote: 09 Oct 2015, 16:48 You should never run as root, as you have probably heard before. :lol:
Just saw your post rednoah, thanks once again.

I could be completely wrong but when ssh'ing into TrueNAS CORE (as what ever user), then using iocage console to get into the shell of a jail you land as root of that jail, not root of that system. Also, you need to be root to console into a jail, then I can't figure out how to change user.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: qBittorrent run FileBot on TrueNAS CORE

Post by rednoah »

I have no idea how jails work. The admin console probably drops you in as root so you can do anything you might need to do, just for convenience. qBT seems to not run as root though. Background service running as different user with different environment variables, and things thus working from shell but not in the background service context, is a typical and understandable problem that everyone of us will run into at some point.
:idea: Please read the FAQ and How to Request Help.
Post Reply