bashfreebsdtransmission-daemon

Transmission on FreeNAS does not call script on completion


I have been trying to get this running for over a week and am at a loss. I am trying to call a script on completion by using the settings.json config like so:

"script-torrent-done-enabled": true,
"script-torrent-done-filename": "/posttorrent.sh",

My script is in the root of the jail and is owned by transmission. I have also checked permissions on the file (which are 755) and have run chmod +x /posttorrent.sh.

I have even simplified the file to just output to a log file like so:

#!/bin/bash
echo "$TR_TORRENT_NAME is completed" >> /posttorrent.log

However, thus far, I still do not have a posttorrent.log file anywhere, no matter what file I download. I am not totally sure if I am on the right track as Transmission is set to log level 3 and yet I do not even see the calls to the script in /var/log/debug.log. I am sure I am missing something easy as others have been able to get this working, I am just out of options now as I think I have read and/or tried everything I could find in relation to this issue. Thanks!


Solution

  • The script is relying on /bin/bash being present inside of the jail. You can either change the script to use /bin/sh, change /bin/bash to /usr/bin/env bash, or link /path/to/port/bin/bash to /usr/local/bin/bash (or wherever bash is located relative to the jail directory, but if it exists it should be in /usr/local/bin).

    ln -s /usr/local/bin/bash /path/to/jail/bin/bash
    

    Also, the root directory (by default) is only writable by root, so the transmission user would not have permission to create the log file in the root directory. To properly allow creation of the log file change the destination directory to one that the transmission user has permission to write to. For example /var/db/transmission/posttorrent.log, if using the FreeNAS plugin. A directory can be created for the transmission user using the install utility:

    install -d -o transmission -g transmission /home/transmission
    

    Alternatively the log file can be created manually using the install utility, or the owner can be set with chown:

    install -o transmission -g transmission -m 644 /dev/null /posttorrent.log
    # or on an existing log file
    chown transmission /posttorrent.log
    chgrp transmission /posttorrent.log
    # normally the mode bits will already be 644
    chmod 644 /posttorrent.log
    

    Transmission will also rewrite the configuration file when it exits. So transmission-daemon has to be stopped before editing the settings file. However, if using the Transmission plugin, the settings are stored in a SQLite database
    (/usr/pbi/transmission-amd64/transmissionUI/transmission.db)
    and the settings file will be recreated from the database on startup. sqlite3 can be used to manually edit the database, or the plugin's settings can be edited on the FreeNAS web UI.

    sqlite3 /usr/pbi/transmission-amd64/transmissionUI/transmission.db <<EOF
    UPDATE freenas_transmission SET enable=1;
    UPDATE freenas_transmission SET script_post_torrent="/posttorrent.sh";