Ubuntu 12.04 LTS에 Deluge 설치하기 (troubleshooting)

리눅스 서버를 위한 토렌트 클라이언트의 양대 산맥은 Transmission과 Deluge라고 할 수 있습니다.

Transmission이 가볍고 단순해서 좋긴 한데, 다운받은 파일의 user와 group이 debian-transmission이라 파일을 자동으로 관리하기가 영 불편해서, 최종적으로 Deluge를 선택하게 되었습니다. (Deluge는 deluged 프로세스의 user와 group을 지정할 수 있고, 자연스럽게 deluged가 다운받은 파일의 user와 group도 그대로 따라갑니다.)

Deluge는 비교적 화려한 기능과 인터페이스를 제공하지만, Python으로 구현되어 있어 Transmission보다 비교적 메모리를 많이 사용하고 느립니다.

설치는 잘 정리되어 있는 다음 문서를 그대로 따라하시면 됩니다.

http://linuxplained.com/install-deluge-web-interface-on-ubuntu-1204/

add-apt-repository가 없으신 분은 python-software-properties 패키지를 설치해 주시면 되겠습니다.

sudo apt-get install python-software-properties

설치 및 실행이 완료되면 다음 주소로 webui에 접근할 수 있습니다.

http://localhost:8112/

토렌트 등록, 시작, 멈춤, 삭제, 설정 등 모든 작업이 webui에서 가능합니다.

기본적인 동작에는 아무런 문제가 없지만 특정 디렉토리에 토렌트 파일을 복사해 넣으면 자동으로 다운로드가 시작되는 기능이 한글 토렌트 파일명에 대하여 동작하지 않는 문제가 있습니다.

Preferences > Downloads > Folder > Autoadd .torrent files from > /data/torrent

이 문제를 해결하기 위해 /data/torrent에 한글 이름의 토렌트 파일이 추가되면 임의의 영문 이름으로 바꾸는 node.js 모듈을 작성하여 forever로 돌리고 있습니다.

var fs = require(‘fs’);

var path = require(‘path’);

var torrentDir = ‘/data/torrent/’;

var workingFilename = {};

function randomString(len, charSet) {

  charSet = charSet || ‘ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789’;

  var randomString = ”;

  for (var i = 0; i < len; i++) {

      var randomPoz = Math.floor(Math.random() * charSet.length);

      randomString += charSet.substring(randomPoz,randomPoz+1);

  }

  return randomString;

}

fs.watch(torrentDir, function(action, filename){

  var hangulRegexp = /[ㄱ-ㅎ|ㅏ-ㅣ|가-힣]/;

  var ext = path.extname(filename);

  if (!workingFilename[filename] && ext == ‘.torrent’ && hangulRegexp.test(filename)) {

    var fromPath = torrentDir + filename;

    var toPath = torrentDir + randomString(8) + ‘.torrent’;

    workingFilename[filename] = toPath;

    setTimeout(function() {

      fs.rename(fromPath, toPath, function(err) {

        if (!err) console.log(filename + ‘: success’); else console.log(filename + ‘: fail’);

        setTimeout(function() {

          delete workingFilename[filename];

        }, 2500);

      });

    }, 2500);

  }

});

Samba를 통해 해당 디렉토리에 토렌트 파일을 복사한 경우, 같은 파일에 대하여 callback이 여러번 호출되기 때문에 map을 사용하여 중복을 피했고, 파일이 생성되고 내용이 저장되기 이전에 이름을 바꾸어 버리는 문제를 피하기 위해 시간차를 두었습니다.

Deluge가 기본으로 제공하는 플러그인 중에 토렌트 파일이 추가되거나 다운로드가 완료되었을 때, 특정 스크립트를 자동으로 실행하는 기능을 제공하는 Execute라는 플러그인이 있습니다.

자세한 내용은 다음 문서를 참조하세요.

http://dev.deluge-torrent.org/wiki/Plugins/Execute

참고로 플러그인을 사용하도록 설정한 후 webui에서 스크립트를 추가하려고 하면 javascript 에러가 발생하는데, deluged를 다시 시작하면 잘 됩니다.

이 역시 한글 이름의 토렌트 파일의 경우 제대로 동작하지 않습니다.

이 문제를 해결하기 위해 다음 문서를 참조하여,

http://forum.deluge-torrent.org/viewtopic.php?f=9&t=40517

Execute 플러그인의 소스코드를 수정하였습니다.

sudo vi /usr/share/pyshared/deluge/plugins/Execute-1.2.egg/execute/core.py

빨간색 부분의 코드를 추가하시면 됩니다.

122         # Go through and execute all the commands

123         for command in self.config[“commands”]:

124             if command[EXECUTE_EVENT] == event:

125                 command = os.path.expandvars(command[EXECUTE_COMMAND])

126                 command = os.path.expanduser(command)

127                 log.debug(“[execute] running %s”, command)

128                 if isinstance(torrent_name, unicode):

129                     torrent_name = torrent_name.encode(‘utf-8’)

130                 d = getProcessOutputAndValue(command, (torrent_id, torrent_name, save_path), env=os.environ)

131                 d.addCallback(log_error, command)

deluged를 다시 시작하면 의도한대로 added, complete 이벤트에 등록해 둔 script가 실행 됩니다.

다운로드가 완료된 후에 해당 토렌트를 삭제하고 싶다면 다음과 같은 스크립트를 사용하시면 됩니다.

#!/bin/bash

date=`date +%Y%m%d`

time=`date +%H:%M:%S`

echo \($date $time\) $1 $2 $3 >> /data/torrent/log/complete.log

deluge-console rm $1

deluge-console 패키지도 설치해 주셔야 합니다.

deluge-console를 사용하면 console에서 다운로드 상태를 보거나 토렌트를 추가하고 삭제하는 작업이 console에서 가능합니다. 자세한 내용은 다음 문서를 참조하세요.

http://whatbox.ca/wiki/Deluge_Console_Documentation

댓글 남기기