Problem with qbt autostart

Linux specific questions, problems.
Post Reply
alexnt
Member
Member
Posts: 24
Joined: Thu Jun 01, 2023 5:29 pm

Problem with qbt autostart

Post by alexnt »

Hi everyone,
I have a nas debian vm with qbt/plex/samba(nothing complicated). When I set up the vm first time, I installed qbt native installation(latest stable version 4.5.2) and set it to autostart.
Then I noticed that when I reboot the machine or a current outage takes place, qbt starts and torrents seem to be active but something weird happens. Completed torrents do not actually seed and report to trackers and incomplete torrents do not resume download and stay stalled. The same happens if I add a new torrent, it stays stalled.
When this happens I close qbt and click the icon to start it again but it doesn't start. I must open task manager, search qbt(yes, it is still there) and kill the application. Then qbt starts normally.
I have found very little information about this on internet, so I asked on github. A person told me to try to reproduce the issue on newer versions of qbt but the latest stable version for the app is 4.5.2 on debian.
Then I installed it via flatpak but I had some other minor issues such as webui freespace reported as unknown and paths in app were more complicated.
Then tried appimage from official website. The minor issues to which I referred were solved but my major problem still exists.
I have also tried to delay qbt autostart but it didn't help either.
The default save location is on an external HDD(set to auto mount when vm starts), if it matters.
I don't know if this is considered as bug that's why I posted here, too.
User avatar
Peter
Administrator
Administrator
Posts: 2702
Joined: Wed Jul 07, 2010 6:14 pm

Re: Problem with qbt autostart

Post by Peter »

Eh, I would simply put a simple script in Crontab.
Every reboot, just killall qBittorrent and once it's not running (wait with a while?) just start it.

This feels like one of those things where I'd write a program to change values in a .CSV file. Spend like 5 hours on it.
And if I did it by hand, it'd only take me like 30 minutes.

Not worth the hassle IMO.

Ps.: Add a PSU, or change your filesystem settings so it is more resilient.
alexnt
Member
Member
Posts: 24
Joined: Thu Jun 01, 2023 5:29 pm

Re: Problem with qbt autostart

Post by alexnt »

Peter wrote: Wed Jan 24, 2024 12:14 pm Eh, I would simply put a simple script in Crontab.
Every reboot, just killall qBittorrent and once it's not running (wait with a while?) just start it.

This feels like one of those things where I'd write a program to change values in a .CSV file. Spend like 5 hours on it.
And if I did it by hand, it'd only take me like 30 minutes.

Not worth the hassle IMO.

Ps.: Add a PSU, or change your filesystem settings so it is more resilient.
First of all thank you for the reply.
Do you mean that the cronjob doesn't worth the hassle?
I searched a bit on the internet about cron but I'm not sure how to do it and I don't know if that could work with an appimage.
I found this link which is referring to reboot. https://phoenixnap.com/kb/crontab-reboot
But I also thought that the script could run after user autologin and not on reboot in case of current outage(I don't believe debian would consider the event as reboot), am I right?
Can you help me with the script and the cron job?
User avatar
Peter
Administrator
Administrator
Posts: 2702
Joined: Wed Jul 07, 2010 6:14 pm

Re: Problem with qbt autostart

Post by Peter »

First and foremost you can ignore most of this post.
My question is: Why do you even run a full qBittorrent or the .AppImage?
Why not use the -nox version that only has WebUI?

You can use this project to grab a fully built, latest, -nox static build: https://github.com/userdocs/qbittorrent-nox-static
You just run this and get the latest version for WebUI.

( the rest you can ignore )
I mean, cron is just like Task Scheduler on Windows.

First, you have to create a new script file somewhere, which cron will execute.
For example:
/home/username/restart_qbittorrent.sh

And in the file we need to:
- wait like 30-60 seconds to see if qBittorrent opens up at all
- run a command to kill it
- start qBittorrent up clean

So:

Code: Select all

#!/bin/bash

# Step 1: Wait for 60 seconds
sleep 60

# Step 2: Kill the qBittorrent process
# Replace 'qBittorrent' with the exact name if different
QB_PID=$(pgrep -f qBittorrent)
if [ ! -z "$QB_PID" ]; then
    kill $QB_PID
fi

# Step 3: Wait until qBittorrent is closed
while pgrep -f qBittorrent > /dev/null; do
    sleep 1
done

# Step 4: Start qBittorrent again
# Replace this with the command you use to start qBittorrent as an AppImage
/path/to/qbittorrent.AppImage &
To edit your cron file: $ crontab -e
alexnt
Member
Member
Posts: 24
Joined: Thu Jun 01, 2023 5:29 pm

Re: Problem with qbt autostart

Post by alexnt »

Peter wrote: Wed Jan 24, 2024 4:00 pm First and foremost you can ignore most of this post.
My question is: Why do you even run a full qBittorrent or the .AppImage?
Why not use the -nox version that only has WebUI?

You can use this project to grab a fully built, latest, -nox static build: https://github.com/userdocs/qbittorrent-nox-static
You just run this and get the latest version for WebUI.

( the rest you can ignore )
I mean, cron is just like Task Scheduler on Windows.

First, you have to create a new script file somewhere, which cron will execute.
For example:
/home/username/restart_qbittorrent.sh

And in the file we need to:
- wait like 30-60 seconds to see if qBittorrent opens up at all
- run a command to kill it
- start qBittorrent up clean

So:

Code: Select all

#!/bin/bash

# Step 1: Wait for 60 seconds
sleep 60

# Step 2: Kill the qBittorrent process
# Replace 'qBittorrent' with the exact name if different
QB_PID=$(pgrep -f qBittorrent)
if [ ! -z "$QB_PID" ]; then
    kill $QB_PID
fi

# Step 3: Wait until qBittorrent is closed
while pgrep -f qBittorrent > /dev/null; do
    sleep 1
done

# Step 4: Start qBittorrent again
# Replace this with the command you use to start qBittorrent as an AppImage
/path/to/qbittorrent.AppImage &
To edit your cron file: $ crontab -e
I had tried the -nox version following this guide (https://www.linuxcapable.com/install-qb ... ian-linux/) but I could not make alternate webui to work. I always got "Unacceptable file type, only regular file is allowed".
I found too difficult to follow the guide from your link....
Alternate webui works fine on client version.
Unfortunately, the script and cron job didn't work. I even removed the appimage from autostart and edited the script to start the appimage but it didn't work either.

Code: Select all

#!/bin/bash

# Step 1: Wait for 60 seconds
sleep 60

# Step 2: Start qBittorrent
# Replace this with the command you use to start qBittorrent as an AppImage
/home/username/Applications/qbittorrent.AppImage &
I had already renamed the appimage to "qbittorrent" beforehand, that's why I kept it as is in the script.
alexnt
Member
Member
Posts: 24
Joined: Thu Jun 01, 2023 5:29 pm

Re: Problem with qbt autostart

Post by alexnt »

Peter wrote: Wed Jan 24, 2024 4:00 pm First and foremost you can ignore most of this post.
My question is: Why do you even run a full qBittorrent or the .AppImage?
Why not use the -nox version that only has WebUI?

You can use this project to grab a fully built, latest, -nox static build: https://github.com/userdocs/qbittorrent-nox-static
You just run this and get the latest version for WebUI.

( the rest you can ignore )
I mean, cron is just like Task Scheduler on Windows.

First, you have to create a new script file somewhere, which cron will execute.
For example:
/home/username/restart_qbittorrent.sh

And in the file we need to:
- wait like 30-60 seconds to see if qBittorrent opens up at all
- run a command to kill it
- start qBittorrent up clean

So:

Code: Select all

#!/bin/bash

# Step 1: Wait for 60 seconds
sleep 60

# Step 2: Kill the qBittorrent process
# Replace 'qBittorrent' with the exact name if different
QB_PID=$(pgrep -f qBittorrent)
if [ ! -z "$QB_PID" ]; then
    kill $QB_PID
fi

# Step 3: Wait until qBittorrent is closed
while pgrep -f qBittorrent > /dev/null; do
    sleep 1
done

# Step 4: Start qBittorrent again
# Replace this with the command you use to start qBittorrent as an AppImage
/path/to/qbittorrent.AppImage &
To edit your cron file: $ crontab -e
I followed the documentation on the link you posted and now I have a nox static user service that I can also change the webui to dark mode!!!!
I tested it on a clean debian test vm and it's working.
One more question: What do I need to do when any update is released?
Thank you very much for your time and all the information!!!
User avatar
Peter
Administrator
Administrator
Posts: 2702
Joined: Wed Jul 07, 2010 6:14 pm

Re: Problem with qbt autostart

Post by Peter »

What do I need to do when any update is released?
Just replace the file you use to run it now, with the new file downloaded from that Github project.
There is no other steps, nothing to install. "Static" means everything is included in that one single big file.
alexnt
Member
Member
Posts: 24
Joined: Thu Jun 01, 2023 5:29 pm

Re: Problem with qbt autostart

Post by alexnt »

Peter wrote: Fri Jan 26, 2024 2:46 pm
What do I need to do when any update is released?
Just replace the file you use to run it now, with the new file downloaded from that Github project.
There is no other steps, nothing to install. "Static" means everything is included in that one single big file.
So I only need to run

Code: Select all

wget -qO ~/bin/qbittorrent-nox https://github.com/userdocs/qbittorrent-nox-static/releases/latest/download/x86_64-qbittorrent-nox
chmod 700 ~/bin/qbittorrent-nox
?

Now, I did the same procedure and "installed" nox static on the actual vm I had the initial issue and guess. I still have it.... The difference is that I downloaded the torrents on the same drive with the os instead of an external drive.
I don't know what would change if I created the service for system and not local user as I did.
In this case it says: "Modify the path to the binary and your local username"

Code: Select all

[Unit]
Description=qBittorrent-nox service
Wants=network-online.target
After=network-online.target nss-lookup.target

[Service]
Type=exec
User=qbtuser
ExecStart=/usr/local/bin/qbittorrent-nox
Restart=on-failure
SyslogIdentifier=qbittorrent-nox

[Install]
WantedBy=multi-user.target
I understand that I need to replace username with my local user, but what is binary?

Also, how would a script be to kill qbt-nox on start up.
I tried from terminal:

Code: Select all

sudo kill -9 PID
Process was killed and it immediatelly started by itself(I assume because the service was running).
But I couldn't kill it by using name:

Code: Select all

sudo kill -9 qbittorrent-nox
.
As, pid changes every time, how am I supposed to kill it on start up?
alexnt
Member
Member
Posts: 24
Joined: Thu Jun 01, 2023 5:29 pm

Re: Problem with qbt autostart

Post by alexnt »

Something weird is happening with killing the process.
Sometimes command

Code: Select all

pkill  qbittorrent-nox
works from 1st execution. Sometimes it needs a 2nd time to execute. Sometimes it needs sudo.
When I kill it from task manager it is being killed and it restarts by itself as I mentioned in the post above.
I tried the following script:

Code: Select all

#!/bin/bash

# Step 1: Wait for 45 seconds
sleep 45

# Step 2: Kill the qBittorrent-nox process
pkill qbittorrent-nox


# Step 3: Wait until qBittorrent-nox is closed
sleep 10

#Step 4: Again kill
pkill qbittorrent-nox

Step 5: Wait again
sleep 10
done

# Step 4: Start qBittorrent-nox again
# Replace this with the command you use to start qBittorrent as an AppImage
systemctl --user start qbittorrent
and the crontab -e:

Code: Select all

@reboot /home/username/restart_qbt-nox.sh
It didn't work....

One more thing: I added a torrent after reboot and it stayed at "downloading" but it never downloaded. Then, I forced resumed it(right click) and after some seconds it started downloading. Progress bar percentage increased BUT there was no speed indication.
https://i.postimg.cc/MGCvg4Yq/Screensho ... 143829.png
alexnt
Member
Member
Posts: 24
Joined: Thu Jun 01, 2023 5:29 pm

Re: Problem with qbt autostart

Post by alexnt »

UPDATE:
I disabled the service I had previously created for the local user and created another for system.

After reboot I added a torrent and it started to download without showing speed.Next I added another one stayed at stalled. Then I resarted qbt and both started downloading normally and speed was shown.

I can't understand what is happening... How can I check that?

UPDATE 2
It seems that scripts don't run with cronjob but I can run them manually.

I have tried 2 scripts:

1(user service).

Code: Select all

#!/bin/bash

# Step 1: Wait for 20 seconds
sleep 20

# Step 2: Kill the qBittorrent-nox process
pkill -9 qbittorrent-nox


# Step 3: Wait until qBittorrent-nox is closed
sleep 10

# Step 4: Start qBittorrent-nox
systemctl --user start qbittorrent
2(system service).

Code: Select all

#!/bin/bash

# Step 1: Wait for 20 seconds
sleep 20

# Step 2: Kill the qBittorrent-nox process
pkill -9 qbittorrent-nox


# Step 3: Wait until qBittorrent-nox is closed
sleep 10

# Step 4: Start qBittorrent-nox
systemctl start qbittorrent
3(user service).

Code: Select all

#!/bin/bash

# Step 1: Kill the qBittorrent-nox process
pkill -9 qbittorrent-nox


# Step 2: Wait until qBittorrent-nox is closed
sleep 10

# Step 3: Start qBittorrent-nox
systemctl --user start qbittorrent
4(system service).

Code: Select all

#!/bin/bash

# Step 1: Kill the qBittorrent-nox process
pkill -9 qbittorrent-nox


# Step 2: Wait until qBittorrent-nox is closed
sleep 10

# Step 3: Start qBittorrent-nox
systemctl start qbittorrent
crontab -e:

1.

Code: Select all

@reboot /home/username/restart_qbt-nox.sh
or

2.

Code: Select all

@reboot sleep 20 && /home/seedbox/restart_qbt-nox.sh
This for the scripts 3 + 4.
Post Reply