Deluge script using wrong XDG_CONFIG_HOME

General support for problems installing or using Deluge
Post Reply
piddlepot
New User
New User
Posts: 5
Joined: Tue Aug 12, 2014 12:22 am

Deluge script using wrong XDG_CONFIG_HOME

Post by piddlepot »

I'm working on a new headless Deluge 1.3.6 setup with FreeBSD 10 as the base. Everything is working just fine, but when a torrent finishes downloading, I'd like to copy it to the completed directory, rather than move it. To do this, I'm using the 'Execute' and 'Label' plugins, and copying to the destination based on the label. The problem is that the python script, when executed via the plugin, tries to read /root/.config/deluge rather than ~/.config/deluge.

The python script in question is the same one floating around the forums:

Code: Select all

#!/usr/local/bin/python

import sys
from deluge.ui.client import client
from twisted.internet import reactor

# Set up the logger to print out errors
from deluge.log import setupLogger
setupLogger()

d = client.connect()

torrent_id = sys.argv[1]

def on_connect_success(result):
    def on_get_torrent_status(torrent):
        print torrent["label"]
        client.disconnect()
        reactor.stop()

    client.core.get_torrent_status(torrent_id, ["label"]).addCallback(on_get_torrent_status)

d.addCallback(on_connect_success)

def on_connect_fail(result):
        print result
        reactor.stop()

d.addErrback(on_connect_fail)

reactor.run()
And I'm running it via the following shell script:

Code: Select all

$ cat copy_torrent.sh
#!/bin/sh

# export XDG_CONFIG_HOME="${HOME}/.config"
TORRENT_ID="${1}"
TORRENT_NAME="${2}"
TORRENT_PATH="${3}"

NEW_BASE="/media/New"

test -z "${TORRENT_ID}" && exit 255
test -z "${TORRENT_NAME}" && exit 254
test -z "${TORRENT_PATH}" && exit 253

TORRENT_LABEL="$(~/bin/get_label.py ${TORRENT_ID})"

case "${TORRENT_LABEL}" in
  tv | television ) RELDEST="TV" ;;
  movie | movies ) RELDEST="Movies" ;;
  music ) RELDEST="Music" ;;
esac

DESTINATION="${NEW_BASE}/${RELDEST}"

rsync -HrltpDq "${TORRENT_PATH}"/"${TORRENT_NAME}" "${DESTINATION}"
The output from ~/bin/get_label.py ${TORRENT_ID} when I run it manually as the appropriate user is exactly what it should be ("tv", "movie", "distro", etc.). But when it runs via the plugin, it just comes back with

Code: Select all

[ERROR   ] 00:16:38 common:167 Unable to use default config directory, exiting... ([Errno 13] Permission denied: '/root/.config/deluge')
I've even tried an "export XDG_CONFIG_HOME="${HOME}/.config" at the top of the shell script, but that doesn't help any. What's going on? Why is xdg reporting back with the wrong XDG_CONFIG_HOME, even when I try to force it? Or is there a better way to copy rather than move a file when finished downloading?
Cas
Top Bloke
Top Bloke
Posts: 3681
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: Deluge script using wrong XDG_CONFIG_HOME

Post by Cas »

I am not sure if that error has anything to do with the script you are trying to run, it wouldn't make sense as the script does not touch Config.

You need to provide more details, such as whether you are able to execute a simple shell script, what command you are putting into execute, the full log trace...
piddlepot
New User
New User
Posts: 5
Joined: Tue Aug 12, 2014 12:22 am

Re: Deluge script using wrong XDG_CONFIG_HOME

Post by piddlepot »

I don't really see how my scripts are getting in the way at all. I was hoping this was just something obvious that I was doing wrong, but I guess not.

On "Torrent Complete", deluge is configured to run "/media/.downloads/bin/copy_torrent.sh", which is the shell script noted above:

Code: Select all

{
  "file": 1,
  "format": 1
}{
  "commands": [
    [
      "847b202c90fa8c12e30e5e2de53d0e0055fcac1d",
      "complete",
      "/media/.downloads/bin/copy_torrent.sh"
    ]
  ]
}
The full error provided by the python script is exactly what I provided; it's a one-line error that it can't read my configuration. Where I would expect it to be reading from /media/.downloads/.config/deluge, it's apparently trying to read from /root/.config/deluge. Which I don't really get: it should only use '/root/' as ${HOME} if this runs as the root user, which it obviously doesn't, as it can't read that directory.

I just grabbed a small torrent (some episode of Archer), and got the same error.

deluged is running as:

Code: Select all

_downloads   59450   4.2  0.4 188180 67284  -  I     9:40PM      0:32.00 /usr/local/bin/python2.7 /usr/local/bin/deluged -c /media/.downloads/.config/deluge /media/.downloads/.config/deluge/python-eggs -L debug -l /var/tmp/deluged.log -P /var/run/deluged/pid
The debug log:

Code: Select all

[INFO    ] 21:40:28 configmanager:70 Setting config directory to: /media/.downloads/.config/deluge
[INFO    ] 21:40:31 daemon:124 Deluge daemon 1.3.6
[DEBUG   ] 21:40:31 daemon:125 options: {'profile': False, 'loglevel': 'debug', 'quiet': False, 'ui_interface': None, 'listen_interface': None, 'logfile': '/var/tmp/deluged.log', 'config': '/media/.downloads/.config/deluge', 'port': None, 'pidfile': '/var/run/deluged/pid', 'donot': False}
[DEBUG   ] 21:40:31 daemon:126 args: ['/media/.downloads/.config/deluge/python-eggs']
[INFO    ] 21:40:31 configmanager:70 Setting config directory to: /media/.downloads/.config/deluge
[DEBUG   ] 21:40:31 core:76 Core init..
[INFO    ] 21:40:31 core:80 Starting libtorrent 0.16.17.0 session..
[DEBUG   ] 21:40:31 configmanager:111 Getting config 'core.conf'

<snip>

[DEBUG   ] 21:44:14 alertmanager:123 torrent_finished_alert: Archer.2009.S05E13.HDTV.x264-KILLERS.mp4 torrent finished downloading
[DEBUG   ] 21:44:14 alertmanager:123 state_changed_alert: Archer.2009.S05E13.HDTV.x264-KILLERS.mp4: state changed to: finished
[DEBUG   ] 21:44:14 alertmanager:123 state_changed_alert: Archer.2009.S05E13.HDTV.x264-KILLERS.mp4: state changed to: seeding
[DEBUG   ] 21:44:14 alertmanager:123 tracker_announce_alert: Archer.2009.S05E13.HDTV.x264-KILLERS.mp4 (udp://tracker.openbittorrent.com:80) sending announce (completed)
[DEBUG   ] 21:44:14 torrentmanager:878 on_alert_torrent_finished
[DEBUG   ] 21:44:14 torrentmanager:884 5d26a202e38e40d4437a92acf6405e27b7de3f11 is finished..
[DEBUG   ] 21:44:14 rpcserver:466 intevents: {2: ['TorrentRemovedEvent', 'PluginEnabledEvent', 'TorrentAddedEvent', 'PluginDisabledEvent', 'TorrentStateChangedEvent', 'ConfigValueChangedEvent']}
[DEBUG   ] 21:44:14 common:79 Calling CORE's custom email providers for TorrentFinishedEvent: ('5d26a202e38e40d4437a92acf6405e27b7de3f11',) {}
[DEBUG   ] 21:44:14 core:119 [execute] Running commands for complete
[DEBUG   ] 21:44:14 core:135 [execute] running /media/.downloads/bin/copy_torrent.sh
[DEBUG   ] 21:44:14 torrent:381 set_state_based_on_ltstate: Seeding
[DEBUG   ] 21:44:14 torrent:382 session.is_paused: False
[DEBUG   ] 21:44:14 torrentmanager:1028 on_alert_state_changed
[DEBUG   ] 21:44:14 torrent:381 set_state_based_on_ltstate: Seeding
[DEBUG   ] 21:44:14 torrent:382 session.is_paused: False
[DEBUG   ] 21:44:14 torrentmanager:1028 on_alert_state_changed
[DEBUG   ] 21:44:14 torrent:381 set_state_based_on_ltstate: Seeding
[DEBUG   ] 21:44:14 torrent:382 session.is_paused: False
[DEBUG   ] 21:44:14 torrentmanager:976 on_alert_tracker_announce
[DEBUG   ] 21:44:14 alertmanager:123 save_resume_data_alert: Archer.2009.S05E13.HDTV.x264-KILLERS.mp4 resume data generated
[DEBUG   ] 21:44:14 torrentmanager:1048 on_alert_save_resume_data
[DEBUG   ] 21:44:14 torrentmanager:736 Opening torrents fastresume file for load.
[DEBUG   ] 21:44:14 torrentmanager:776 Saving fastresume file: /media/.downloads/.config/deluge/state/torrents.fastresume
[DEBUG   ] 21:44:14 alertmanager:123 peer_blocked_alert: Archer.2009.S05E13.HDTV.x264-KILLERS.mp4: blocked peer: <removed>
[DEBUG   ] 21:44:14 alertmanager:123 peer_blocked_alert: Archer.2009.S05E13.HDTV.x264-KILLERS.mp4: blocked peer: <removed>
[DEBUG   ] 21:44:14 alertmanager:123 tracker_reply_alert: Archer.2009.S05E13.HDTV.x264-KILLERS.mp4 (udp://tracker.openbittorrent.com:80) received peers: 200
[DEBUG   ] 21:44:14 torrentmanager:959 on_alert_tracker_reply: Archer.2009.S05E13.HDTV.x264-KILLERS.mp4 (udp://tracker.openbittorrent.com:80) received peers: 200
The script was run with the following arguments:

Code: Select all

5d26a202e38e40d4437a92acf6405e27b7de3f11 Archer.2009.S05E13.HDTV.x264-KILLERS.mp4 /media/.downloads/torrents/incoming
I added some debugging, so I can confirm that the script *is* running as the "_downloads" user.

The output of the python script:

Code: Select all

[ERROR   ] 21:44:17 common:167 Unable to use default config directory, exiting... ([Errno 13] Permission denied: '/root/.config/deluge')
Since that went to STDERR and not STDOUT, the shell script identified no label, so the rsync command that was run:

Code: Select all

rsync -HrltpDq /media/.downloads/torrents/incoming/Archer.2009.S05E13.HDTV.x264-KILLERS.mp4 /media/New/
Cas
Top Bloke
Top Bloke
Posts: 3681
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: Deluge script using wrong XDG_CONFIG_HOME

Post by Cas »

Oh actually if it is authenticating it would require access to the config directory.

What user is deluged running as?

Have you logged the env values that the python script is using?
piddlepot
New User
New User
Posts: 5
Joined: Tue Aug 12, 2014 12:22 am

Re: Deluge script using wrong XDG_CONFIG_HOME

Post by piddlepot »

deluged is running as "_downloads", same user as deluge_web. I understand why it would need access to the config directory, but why is it looking for the wrong config directory?

I haven't tried logging the python env values, as I assumed that they would be the same as the shell script (which I've logged). I should just stop with the shell and do it all in python...

Weird note, I rebooted the server yesterday, and now the python script has now started throwing this error:

Code: Select all

[ERROR   ] 00:09:53 common:167 Unable to use default config directory, exiting... ([Errno 13] Permission denied: '/.config')
I'm confused.
Post Reply