fedarovich / qbittorrent-cli

Command line interface for QBittorrent
MIT License
303 stars 16 forks source link

Cannot assign requested address #33

Closed Jorman closed 4 years ago

Jorman commented 4 years ago

Hi, the situation is pretty strange, and I'm not so able to understand why this happens, I'll try to explain what is and when happen the error. I wrote a little bash script to extract listening port with this command ACTUAL_QBITTORRENT_PORT=$($QBT_BIN server settings connection --username "$QBITTORRENT_USERNAME" --password "$QBITTORRENT_PASSWORD" --url "http://${QBITTORRENT_HOST}:$QBITTORRENT_PORT" --format json | $JQ_BIN '.ListenPort') When I run it inside putty shell all works, the same when I use it from command line, but if I call the script from a systemd system I get the "Cannot assign requested address" error. So this's the output if I launch the script

+ OWRT_UNAME=root
+ OWRT_IP_ADDR=10.0.0.1
+ QBITTORRENT_HOST=localhost
+ QBITTORRENT_USERNAME=admin
+ QBITTORRENT_PASSWORD=adminadmin
+ QBITTORRENT_PORT=8081
+ LOG_ENABLE=0
+ LOG_PATH=/tmp
+ [[ 0 == 1 ]]
+ [[ 0 == 1 ]]
++ command -v qbt
+ QBT_BIN=/usr/bin/qbt
++ command -v ssh
+ SSH_BIN=/usr/bin/ssh
++ command -v jq
+ JQ_BIN=/usr/bin/jq
+ [[ -z /usr/bin/qbt ]]
+ [[ -z /usr/bin/ssh ]]
++ /usr/bin/ssh root@10.0.0.1 'cat /tmp/pia-port-forward'
+ REMOTE_PIA_PORT=46786
+ [[ -n 46786 ]]
++ /usr/bin/qbt server settings connection --username admin --password adminadmin --url http://localhost:8081 --format json
++ /usr/bin/jq .ListenPort
+ ACTUAL_QBITTORRENT_PORT=46786
+ [[ 46786 == 46786 ]]
+ [[ 0 == 1 ]]

And this's the output when I call the script from the systemd

Mar 14 16:46:36 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: + OWRT_UNAME=root
Mar 14 16:46:36 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: + OWRT_IP_ADDR=10.0.0.1
Mar 14 16:46:36 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: + QBITTORRENT_HOST=localhost
Mar 14 16:46:36 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: + QBITTORRENT_USERNAME=admin
Mar 14 16:46:36 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: + QBITTORRENT_PASSWORD=adminadmin
Mar 14 16:46:36 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: + QBITTORRENT_PORT=8081
Mar 14 16:46:36 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: + LOG_ENABLE=0
Mar 14 16:46:36 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: + LOG_PATH=/tmp
Mar 14 16:46:36 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: + [[ 0 == 1 ]]
Mar 14 16:46:36 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: + [[ 0 == 1 ]]
Mar 14 16:46:36 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: ++ command -v qbt
Mar 14 16:46:36 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: + QBT_BIN=/usr/bin/qbt
Mar 14 16:46:36 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: ++ command -v ssh
Mar 14 16:46:36 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: + SSH_BIN=/usr/bin/ssh
Mar 14 16:46:36 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: ++ command -v jq
Mar 14 16:46:36 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: + JQ_BIN=/usr/bin/jq
Mar 14 16:46:36 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: + [[ -z /usr/bin/qbt ]]
Mar 14 16:46:36 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: + [[ -z /usr/bin/ssh ]]
Mar 14 16:46:36 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: + REMOTE_PIA_PORT=1234
Mar 14 16:46:36 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: + [[ -n 1234 ]]
Mar 14 16:46:36 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: ++ /usr/bin/qbt server settings connection --username admin --password adminadmin --url http://localhost:8081
Mar 14 16:46:40 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: Cannot assign requested address
Mar 14 16:46:40 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: + ACTUAL_QBITTORRENT_PORT=
Mar 14 16:46:40 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: + echo ''
Mar 14 16:46:40 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: + [[ '' == 1234 ]]
Mar 14 16:46:40 Qnap qBittorrent_OPENWRT_Pia_Port.sh[29617]: + [[ 0 == 1 ]]

As you can see, the ACTUAL_QBITTORRENT_PORT var is not valid because of "Cannot assign requested address" error

Do you've any idea?

Jorman commented 4 years ago

Never mind, I found the problem, was my fault, I used ExecStartPre instead ExecStartPost so qbt was launched before qbittorrent and not after! So, no worry.

J