OpenWrt installs version 4.4.2 of qbittorrent-nox

I have been using the qbittorrent client that comes with the firmware, the version number is 4.1.9 , and I have experienced several times that I could not enter the webui after high-load downloads. I ran into it again the other day, and this time instead of ignoring it, I faced the problem head on and tried to fix it.

Published a post at V2EX the day before yesterday: Ask a question about qbittorrent-nox on Linux: webui doesn’t work after heavy download

There are still a lot of gains, thank you for your help in the comment area. I have now decided to install a higher version 4.4.x client on OpenWrt. Since there is no qbit program in the official opkg source of OpenWrt, most of them are compiled by some great gods themselves, and there is even an Enhanced Edition (that is, the enhanced version of qbit ee). After I did some research, I installed version 4.4.2 of this article.

The project address is https://github.com/userdocs/qbittorrent-nox-static

I am OpenWrt of x86_64 (amd64), the installation command is as follows (log in as root user)

 # mkdir -p ~/bin # wget -qO ~/bin/qbittorrent-nox https://github.com/userdocs/qbittorrent-nox-static/releases/latest/download/x86_64-qbittorrent-nox # chmod 755 ~/bin/qbittorrent-nox

Here why I use the permission setting of 755, because I intend to use the user dk to run the program. The downloaded files in the directory downloaded by pt will also be owned by dk. The following services such as samba are also logged in through the dk user.

Since my OpenWrt is installed in a SanDisk Kudou U disk, I don’t plan to run the program directly, because the subsequent system damage or something will cause the data in my BT_backup to be incomplete (not the latest). So I ran the qbittorrent-nox program with the --profile parameter

–profile=<path> save profile in

The above quotation is in the help file of the program. In fact, not only the configuration file is saved in this path, but also the cache and data (mainly *.fastresume and *.torrent files) will be saved in this path.

Use tree to observe the folder structure

 # tree -L 3 /mnt/ThreeTB2/qbit_profile_new /mnt/ThreeTB2/qbit_profile_new └── qBittorrent ├── cache ├── config │  ├── categories.json │  ├── ipc-socket │  ├── lockfile │  ├── qBittorrent-data.conf │  ├── qBittorrent.conf │  ├── rss │  └── watched_folders.json └── data ├── BT_backup ├── GeoDB ├── logs ├── nova └── rss 10 directories, 6 files

Then we copy the relevant data of the previous program to the new profile path through rsync, and use this profile after startup.

Let’s start writing an init.d startup/management script. The newer OpenWrt init process with PID 1 is replaced by the program procd . In fact, we are writing a /etc/init.d/your_service

cat /etc/init.d/qbittorrent-nox

 #!/bin/sh /etc/rc.common # Licensed to the public under the Apache License 2.0. # ubus call service list USE_PROCD=1 START=95 STOP=15 #打开procd 的debug 模式#PROCD_DEBUG=1 #INIT_TRACE=1 /etc/init.d/qbittorrent-nox $start NAME=qbittorrent-nox ARGS=/root/bin/qbittorrent-nox QBIT_PROFILE=/mnt/ThreeTB2/qbit_profile_new #QBIT_PROFILE=/root/.config/qBittorrent QBIT_PID_FILE=/var/run/qbittorrent-nox.pid # 定义此处配置文件变化,配合procd_set_param file /path/to/file 可以auto reload your service #QBIT_INI_FILE=/tmp/qBittorrent/config/qBittorrent.conf QBIT_INSTANCE="qbittorrent-nox-v4.4.2" start_service() { procd_open_instance $QBIT_INSTANCE # 给服务实例定义一个名称procd_set_param command $ARGS # 需要在前台被执行的服务procd_append_param command --profile="$QBIT_PROFILE" # 给以上命令附加的指令参数# 如果服务意外中止了,定义redpawn 可以自动重启它,如果服务命令的确只需要运行一次,需要谨慎设定这里# 如果进程在respawn_threshold 定义的时间内结束了,则判定为进程崩溃并尝试重启它,尝试5次后会停止重启procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5} #procd_set_param file /var/etc/your_service.conf # 如果此处定义的文件发生了变化,则会触发/etc/init.d/your_service reload 重启进程#procd_set_param netdev dev # likewise, except if dev's ifindex changes. #procd_set_param data name=value ... # likewise, except if this data changes. procd_set_param stdout 1 # 转发stdout 输出到logd procd_set_param stderr 1 # same for stderr procd_set_param user dk # 以dk 用户运行服务procd_set_param pidfile $QBIT_PID_FILE # 在服务启动时写入一个pid 文件,在停止服务时删除此pid 文件procd_close_instance # 结束服务实例配置} #stop_service() { # PID=`ps aux |grep 'qbit' |grep -v 'grep' |awk '{print $2}'` # echo "starting to kill $PID" # # 杀死qbit 进程pid # #kill -9 `ps aux |grep 'qbit' |grep -v 'grep' |awk '{print $2}'` # kill -9 $PID #} reload_service() { restart } restart() { echo "ready to restart qbittorrent-nox service" stop sleep 5 start }

Here’s a “cleaner” version

cat /etc/init.d/qbittorrent-nox

 #!/bin/sh /etc/rc.common # Licensed to the public under the Apache License 2.0. # ubus call service list USE_PROCD=1 START=95 STOP=15 NAME=qbittorrent-nox ARGS=/root/bin/qbittorrent-nox QBIT_PROFILE=/mnt/ThreeTB2/qbit_profile_new QBIT_PID_FILE=/var/run/qbittorrent-nox.pid QBIT_INSTANCE="qbittorrent-nox-v4.4.2" start_service() { procd_open_instance $QBIT_INSTANCE # 给服务实例定义一个名称procd_set_param command $ARGS # 需要在前台被执行的服务procd_append_param command --profile="$QBIT_PROFILE" # 给以上命令附加的指令参数# 如果服务意外中止了,定义redpawn 可以自动重启它,如果服务命令的确只需要运行一次,需要谨慎设定这里# 如果进程在respawn_threshold 定义的时间内结束了,则判定为进程崩溃并尝试重启它,尝试5次后会停止重启procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5} procd_set_param stdout 1 # 转发stdout 输出到logd procd_set_param stderr 1 # same for stderr procd_set_param user dk # 以dk 用户运行服务procd_set_param pidfile $QBIT_PID_FILE # 在服务启动时写入一个pid 文件,在停止服务时删除此pid 文件procd_close_instance # 结束服务实例配置} reload_service() { restart } restart() { echo "ready to restart qbittorrent-nox service" stop sleep 5 start }

Set permissions for qbittorrent-nox

 # chmod 755 /etc/init.d/qbittorrent-nox # chown root:root /etc/init.d/qbittorrent-nox

It doesn’t matter if there is no luci page, the 4.4.2 version of the qbit is the most needed.

Manage autostart

 # /etc/init.d/qbittorrent-nox enable # /etc/init.d/qbittorrent-nox start

A little note

  • The permission of the file /root/bin/qbittorrent-nox can be set to 0755 to belong to the root user and group, but my program is running under the dk user, so setting it to 0755 ensures that dk can execute this program
  • --profile program configuration and data directory --profile=<路径> 保存配置文件于<dir>
  • Copy the configuration and data through rsync to use the new profile and persist it to the hard disk. At this time, my system is running in a U disk, so it is not good to save these data in / under
  • No need to write stop_service() function, use stop directly to stop the child process of procd

Reference and thanks

If you want to customize your procd startup script more individually, and encounter problems during startup, you can add the debug option PROCD_DEBUG=1 to enable debug mode

procd instance information seen by opening debug mode

20220508133632

qbittorrent-nox 4.4.2

20220508142944

If you have any questions, please leave a message.

This article is reprinted from: https://hellodk.cn/post/1041
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment