Skip to content

DoneCmdUsage

Preston edited this page Aug 6, 2019 · 1 revision

About DoneCmd

DoneCmd is an external program called when a task is finished. The program must be executable (eg: mode 0755).

When DoneCmd is called, the following environment variables are set:

CLD_DIR=/path/of/DownloadDirectory
CLD_PATH=Torrent-Downloaded-File-OR-Dir
CLD_SIZE=46578901
CLD_TYPE=file
CLD_HASH=12345678901234567890abcdefgabcdefg
CLD_RESTAPI=127.0.0.1:2001
CLD_STARTTS=1614926125
CLD_FILENUM=1
  • CLD_DIR is same with DownloadDirectory in the config.
  • CLD_PATH is the downloaded file path, joining CLD_DIR and CLD_PATH will be the absolute path to the downloaded file.
  • CLD_SIZE is the file size in bytes. When CLD_TYPE=torrent, is the whole torrent size.
  • CLD_TYPE is the calling event type, for each torrent task DoneCmd will be called at least twice (multiple times if the torrent has more than one file), once with CLD_TYPE=file when a file is completed, and CLD_TYPE=torrent when the whole torrent completed.
  • CLD_HASH is the hash of the torrent.
  • CLD_RESTAPI is the --rest-api argument of the program.
  • CLD_STARTTS is the Unix timestamp that the task was started.

An example of bash script using this env varilables to do useful things, is provided under scripts/doneCMD.sh

Trouble Shooting

Cloud Torrent-rs logs details when running DoneCmd, heres example output from journalctl:

Aug 19 16:41:41 host.net cloud-torrent[8522]: [DoneCmd] [/usr/local/bin/add2aria2.py] environ:[LANG=en_US.utf8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin HOME=/var/lib/nginx LOGNAME=nginx USER=nginx SHELL=/sbin/nologin CLD_DIR=/srv/http/dl/cloud CLD_PATH=魔道祖师 羡云篇 01.mp4 CLD_SIZE=324558998 CLD_TYPE=file]
Aug 19 16:41:42 host.net cloud-torrent[8522]: [DoneCmd] Output: ID:[256] AddURL: xxxx----.mp4

The first line is the external program and it's starting environment virables, other than those starts with CLD_, they are derived from Cloud Torrent-rs.

The second line is the stdout/stderr output combined from the external program.

If there were errors running the program, the message also logged here.

Note that there maybe spaces in the variable CLD_PATH, when the program is an shell script, remember to double quote it: echo "$CLD_PATH"

Debug The script

You don't need to wait for a downloaded torrent to test a script for doneCMD. Use the bash env can easily produce the running environment.

In the following example, prefix with env ... gives all the environments like Cloud Torrent-rs does to doneCMD.sh.

The switch bash -x will show details on every line executed.

env \
  CLD_DIR=/srv/http/dl/cloud \
  CLD_RESTAPI=localhost:3001 \
  CLD_PATH="Some Downloaded File.mp4" \
  CLD_HASH=12345678901234567890abcdefgabcdefg \
  CLD_TYPE=file \
  CLD_SIZE=789554712 \
  CLD_STARTTS=1629104374 \
  CLD_FILENUM=1 \
  bash -x /path/to/your/doneCMD.sh

Clone this wiki locally