qbittorrent / qBittorrent

qBittorrent BitTorrent client
https://www.qbittorrent.org
Other
27.4k stars 3.9k forks source link

Run External Program Upon Completion Not Working #18893

Open Decoy256 opened 1 year ago

Decoy256 commented 1 year ago

qBittorrent & operating system versions

qBittorrent: 4.5.2 (qbittorrent-nox) OS: TrueNAS-13.0-U4 - qBittorrent is running inside a jail which is running FreeBSD version 13.2-RELEASE Qt: 5.15.8 Libtorrent: 1.2.18.0 Boost: 1.81.0 OpenSSL: 1.1.1t-freebsd zlib: 1.2.13

What is the problem?

I have searched through the forums here and elsewhere trying to solve this, but nothing seems to work.

I am running a simple command upon torrent completion: unrar x -r "%F"/*.rar "%F"/

This WAS working flawlessly for months, but suddenly it stopped working. I've even completely removed the entire jail and reinstalled, but the problem persists.

Looking at the log file, it indicates that it runs the command, but I think it's lying. I tried to test what might be the problem and so gave it another command to run upon completion: echo "test" > /config/debug.txt

Again, the log says it ran this command, but the file is not created. Why does it think that it's running the command, but producing nothing from even the simplest of commands?

I've seen that others have had issues with qBittorrent not running bash scripts upon completion, but I'm not running bash scripts, just a simple unrar command (or even a simple "echo" command apparently).

Steps to reproduce

  1. Setup qBittorrent to run any command upon torrent completion
  2. Complete a torrent
  3. Witness the sorrow

Additional context

No response

Log(s) & preferences file(s)

No response

krmcleod02 commented 1 year ago

Same issue.

Running direct on Ubuntu 22.04 LTS. Was working fine under 4.3, upgraded a few days ago to 4.5.2 for the sake of upgrading, and both the unrar and 7z external scripts refuse to run.

glassez commented 1 year ago

Could you test it with full paths of running programs specified?

Decoy256 commented 1 year ago

@glassez I could, but it doesn't even run "echo", so I'm not sure if that would change anything.

Also, I can run "unrar" from the command line without the full path.

And the qBittorrent logs show that it is running these commands, but to no effect.

Decoy256 commented 1 year ago

@krmcleod02 Have you checked out the qBittorrent logs to see if it thinks that it is running the commands?

glassez commented 1 year ago

And the qBittorrent logs show that it is running these commands, but to no effect.

It is because the log message is posted unconditionally: https://github.com/qbittorrent/qBittorrent/blob/9801cd0323576cb0811fffbe7785c2aeca43515e/src/app/application.cpp#L518-L521

glassez commented 1 year ago

I could, but it doesn't even run "echo", so I'm not sure if that would change anything.

IIRC, "echo" is built-in command of shell and not an executable so it cannot be run by qBittorrent.

Also, I can run "unrar" from the command line without the full path.

So I want to first find out if the problem is just that PATH is not available to the running process.

Decoy256 commented 1 year ago

It is because the log message is posted unconditionally:

Well, that's dumb. Kind of a pointless "log" if it isn't logging what actually happens. Can we submit that as a bug?

glassez commented 1 year ago

Can we submit that as a bug?

Sure.

krmcleod02 commented 1 year ago

So the log is showing it runs it against every torrent that's downloaded, but it doesn't report whether or not it's complete. My configuration keeps In Progress torrents in one folder, and then moves them to another for Completed downloads.

This is what is coming up in the log:

(N) 2023-04-28T15:46:18 - Enqueued torrent move. Torrent: #TORRENT NAME#. Source: #TORRENT LOCATION#. Destination: #DESTINATION LOCATION#

(N) 2023-04-28T15:46:18 - Start moving torrent. Torrent: #TORRENT NAME#. Destination: #DESTINATION LOCATION#

(N) 2023-04-28T15:46:18 - Moved torrent successfully. Torrent: #TORRENT NAME#. Destination: #DESTINATION LOCATION#

(N) 2023-04-28T15:46:18 - Torrent download finished. Torrent: #TORRENT NAME#

(N) 2023-04-28T15:46:18 - Running external program. Torrent: #TORRENT NAME#. Command: "/usr/local/bin/unrar" x -ibck -inul "#DESTINATION LOCATION#/*.r*" "#UNPACK LOCATION#"

Redacted for my own peace of mind. However, it doesn't give a report that it completed the External command, just claims that it ran it. It is pointing against the post move location when it reports the Unrar command. It just doesn't unpack the file.

Decoy256 commented 1 year ago

@glassez It looks like the log posted by @krmcleod02 indicates that he is feeding it the full path.

I can't recall, but I think I might have run across this (providing the full path) as a suggestion a while ago in another thread somewhere on the internet (I've been dealing with this issue for some time) and I tried giving it the full path, but to no avail.

glassez commented 1 year ago

I did a couple of quick tests and I see that it really runs (even w/o full path specified). Maybe the problem is not that it does not start, but that it cannot do useful work for some reason (for example, because of incorrect parameters or something else). Could you run qBittorrent from the console/terminal to see the output of the program being run?

glassez commented 1 year ago

So the log is showing it runs it against every torrent that's downloaded, but it doesn't report whether or not it's complete.

Even with this patch applied it won't report the status of executed programs (only whether or not it is started successfully) since the external process is started as detached.

Decoy256 commented 1 year ago

@glassez I am not sure what you mean by "run qbittorrent". The service is running at startup.

glassez commented 1 year ago

@glassez I am not sure what you mean by "run qbittorrent". The service is running at startup.

I mean start it manually, i.e. by typing the name of qBittorrent executable in shell command line. Just don't ask me how to do it in your system - I don't familiar with all these jails, etc.

Decoy256 commented 1 year ago

If I just type "/usr/local/etc/rc.d/qbittorrent", it says:

Usage: /usr/local/etc/rc.d/qbittorrent [fast|force|one|quiet] (start|stop|restart|rcvar|enable|disable|delete|enabled|describe|extracommands|status|poll)

When I type "/usr/local/etc/rc.d/qbittorrent restart", it outputs:

Stopping qbittorrent.
Waiting for PIDS: 20673.
Starting qbittorrent.
glassez commented 1 year ago

If I just type "/usr/local/etc/rc.d/qbittorrent"

"/usr/local/etc/rc.d/qbittorrent" isn't a qBittorrent itself. It looks like some script that manages qBittorrent to be used as a service. You could read it to see how it executes qBittorrent. P.S. you still need to stop running service instance before start it manually.

Decoy256 commented 1 year ago

This is the contents of the script:

#!/bin/sh

# PROVIDE: qbittorrent
# REQUIRE: DAEMON
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable this service:
#
# qbittorrent_enable:        Set to NO by default. Set it to YES to enable it.
# qbittorrent_conf_dir:      Directory where qbittorrent configuration
#                data is stored.
#                Default: /var/db/qbittorrent/conf
# qbittorrent_download_dir:  Directory to store downloaded data.
#                Default: /var/db/qbittorrent/Downloads
# qbittorrent_user:      The user account transmission daemon runs as.
#                Default is 'qbittorrent'
# qbittorrent_group:         The group associated with username qbittorrent
#                daemon runs as. Default is 'qbittorrent'
#

. /etc/rc.subr

name=qbittorrent
rcvar=qbittorrent_enable

load_rc_config $name

: ${qbittorrent_enable="NO"}
: ${qbittorrent_conf_dir="/var/db/qbittorrent/conf"}
: ${qbittorrent_download_dir="/var/db/qbittorrent/Downloads"}
: ${qbittorrent_user=qbittorrent}
: ${qbittorrent_group=qbittorrent}

command="/usr/local/bin/qbittorrent-nox"
command_args="--daemon"

qbittorrent_flags=" \
    ${qbittorrent_conf_dir:+--profile=${qbittorrent_conf_dir}} \
    ${qbittorrent_download_dir:+--save-path=${qbittorrent_download_dir}} \
    ${qbittorrent_flags}"

run_rc_command $1
Decoy256 commented 1 year ago

This is what happens when I run /usr/local/bin/qbittorrent-nox:

https://www.imgbly.com/ib/wLe2BWortD

glassez commented 1 year ago

This is what happens when I run /usr/local/bin/qbittorrent-nox:

First of all you should stop currently running qBittorrent service (as I said above) to prevent conflicts of used ports etc. Second is you should start qBittorrent using the same user/group and command line parameters (e.g. --profile, but except --daemon) as configured to be used by service instance (otherwise you starts it using another profile).

Decoy256 commented 1 year ago

So, could I just edit the script above and comment out the line that says command_args="--daemon"?

glassez commented 1 year ago

So, could I just edit the script above and comment out the line that says command_args="--daemon"?

You could try... Nothing terrible will happen (the main thing is, don't forget to put everything back in its place later). Sorry, I'm not a *nix guru to confidently answer such questions (I use Windows 99% of the time).

Decoy256 commented 1 year ago

If there is nothing else in that script that you think might cause problems, then I think I'll give that a try.

Decoy256 commented 1 year ago

OK, I commented it out and it seems to work, except when I stop the jail and then restart it, the TrueNAS UI hangs and doesn't register that it has finished starting the jail. That's OK, since I can just refresh the UI and I can still shell into the jail. I will test to see if this fixes the execute external program issue. If it does work, that show what? That qbittorrent isn't properly handling the fact that it is running as a daemon? What would be the solution from there?

Decoy256 commented 1 year ago

OK, I got it running with a torrent set to download, then went out for the day. Came back and the torrent has been stalled the whole time. Reset the script back to the way it was and everything started up and ran. Still not executing commands on completion, though.

glassez commented 1 year ago

OK, I got it running with a torrent set to download, then went out for the day. Came back and the torrent has been stalled the whole time

Well, it could still be because you ran it through a rc script... In fact, if you are ready to just test it without having to seed all your existing torrents, then you could run it manually with a clean profile (as you did earlier, but don't forget to stop the service instance first and then make sure your manually started instance is OK by looking at qBittorrent log) and add a single torrent for downloading.

glassez commented 1 year ago

@qbittorrent/bug-handlers, could someone help with troubleshooting this issue?

glottisfaun0000 commented 1 year ago

i'm having this same issue with qb 4.5.2 on macOS with the same results as @Decoy256 including when running with the path, e.g. "/usr/bin/touch ~/hi.txt". shows in log, nothing happened in filesystem.

glassez commented 1 year ago

e.g. "/usr/bin/touch ~/hi.txt"

Although ~ has a special meaning for many command line shells it is just a regular character and it is interpreted accordingly by other software. "touch /home/glassez/hi.txt" works well for me.

krmcleod02 commented 1 year ago

Apparently in a recent update, unrar somehow moved locations to /usr/bin in my case. I still had a residual location of /usr/local/bin/unrar, but it did nothing. The PATH had been changed.

After updating my command, it's running fine. Sorry for the confusion.

glottisfaun0000 commented 1 year ago

does running external program support piping?

such as, echo "%N" | /opt/homebrew/bin/notify

glassez commented 1 year ago

does running external program support piping?

such as, echo "%N" | /opt/homebrew/bin/notify

No. All it does is call the executable and pass everything else to it as parameters. If you need some features of shell, then you could call the shell (e.g. bash) and pass it the appropriate parameters.