1

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!

Duffmaster33
  • 1,160
  • 9
  • 16
  • `"/posttorrent.sh"` is very suspect, don't you mean `"/path/to/posttorrent.sh"` ? Good luck. – shellter Jan 16 '16 at 23:57
  • @shellter it is possible its wrong, however the script is in the root of the jail which would seem to be /posttorrent.sh as the /path/to/posttorrent.sh. Certainly works that way from ssh though I have no idea if that is true from the daemon. I would think it is but clearly I don't know much :-/ – Duffmaster33 Jan 17 '16 at 01:32
  • OK, I'm not a FreeNAS user, but I thought I should ask the question. Good luck! – shellter Jan 17 '16 at 01:55
  • Does `/path/to/jail/bin/bash` exist? – kdhp Jan 17 '16 at 12:11
  • @kdhp that does not exist, however bash is available as a command and I do have it in /path/to/jail/usr/local/bin and usr/ports/shells/bash – Duffmaster33 Jan 17 '16 at 17:37

1 Answers1

1

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";
kdhp
  • 2,096
  • 14
  • 15
  • Thanks for your answer, but I'm not sure this fits. I did try it to be safe (amending the top line of my script to point at bash) but it didn't change anything. As I mentioned, bash is installed as a command in the Jail. In fact, it is not installed anywhere else. I get your point about it pointing to the right place which is why I changed it, but it can also be called through the ssh session, where I am in the Jail the entire time. – Duffmaster33 Jan 19 '16 at 01:23
  • @Duffmaster33 Multiple things could be overwriting the settings file. Hopefully some of the information added to the answer helps. – kdhp Jan 20 '16 at 09:24
  • The settings file is not the issue, I have verified multiple times that it is correct. I have also been editing it through the GUI, which does not have the issue of overwriting. – Duffmaster33 Jan 20 '16 at 14:50
  • @Duffmaster33 Does the transmission user have permission to create the log file? – kdhp Jan 21 '16 at 00:03
  • Great question, I honestly don't know. I did add transmission to the wheel group cause I was afraid of permissions issues, but am very foggy on if that means they have permissions or not. How would I check? – Duffmaster33 Jan 21 '16 at 18:21
  • @Duffmaster33 `ls -dl /` or `stat /`, unless you changed the permissions they should be `rwxr-xr-x` (only writable by root). – kdhp Jan 21 '16 at 22:37
  • Thank you! This is what I get: root@transmission_1:/ # ls -dl / drwxr-xr-x 20 root wheel 28 Jan 17 09:56 / Does that mean only root has access? How can I fix? – Duffmaster33 Jan 23 '16 at 01:35
  • 1
    @Duffmaster33 You can change the destination directory to somewhere that the `transmission` user has [permission](https://www.freebsd.org/doc/handbook/permissions.html) to write to. For example,`/var/db/transmission/posttorrent.log`, if using the FreeNAS plugin. Alternatively, you could manually set the [permissions](https://www.freebsd.org/doc/handbook/permissions.html) of the log file, for example changing the owner. `chown transmission /posttorrent.log` – kdhp Jan 23 '16 at 02:47
  • Ah! That did it, apparently Transmission likes to fail silently when the script fails. Thank you so much! If you update your answer, I will gladly accept it :) – Duffmaster33 Jan 23 '16 at 15:09
  • @Duffmaster33 The answer as been updated with the permission issues addressed. – kdhp Jan 24 '16 at 06:54