1

I've installed transmission-deamon on Raspbian. I've set it up to directly download on to a NAS share, which is mounted at /home/pi/nas/public via CIFS in /etc/fstab.

All this generally works fine, except when the Pi restarts - either due to a power failure or any other reason - then transmission can't find any of the incomplete files and gives me that dreaded error..

No data found! Ensure your drives are connected or use "Set Location". To re-download, remove the torrent and re-add it.

I've tried to manually change the deamon startup delay from 30 to 60 in /etc/init.d/transmission-daemon, but sometimes, I find that the share hasn't been mounted at all, even minutes after a reboot. Another reboot usually seems to fix this.

So here's what I wish to automate on startup..

  1. Wait 60 seconds to allow for all the shares to mount.
  2. Then, check for the existence of a file for eg. /home/pi/nas/public/test.txt, which is in the NAS.
  3. If the file doesn't exist, it means the shares didn't mount. Go back to step 1.
  4. If the file exists, it means the shares mounted, so launch transmission-deamon.

Is this something that's possible with an init script?

To make it even more solid, perhaps a counter can be maintained that increments with each "file not found" reboot. If the counter exceeds 10, something is seriously wrong and an email should be sent to me.

2

I have seen this problem both after a power outage and, occasionally, if the NAS has 'gone to sleep'. The following bit of script has 'cured' the problem for me.

You could put this in a while-loop with a counter and raise an alarm after too many tries. I haven't needed to do that.

#!/bin/bash

# check if the NAS is available. just need to check if we can ls a file on it 

ls /mnt/SHAREMOUNTPOINT/Pi_testfile.txt
if (( $? > 0 ))
then
    echo "NO NAS"
    sudo umount /mnt/SHAREMOUNTPOINT
    sleep 5
    sudo mount -t cifs //YOURSHAREADDRESS /mnt/SHAREMOUNTPOINT -o sec=ntlm,username=USERNAME,password=PASSWORD,dir_mode=0777,file_mode=0777
    sleep 2
fi 

Change the stuff in capitals to match your situation

  • Thanks! I'll try it. Just to be certain, I insert this into "/etc/init.d/transmission-daemon" right? – aalaap Feb 13 '15 at 6:18
  • My current init.d/td script starts with "#!/bin/sh -e". Will this bash script work as-is in sh? – aalaap Feb 13 '15 at 13:33
0

After reading @KenR and @goldilocks' answers, I wrote/modified this right after the case "$1" in and start) lines in my /etc/init.d/transmission-daemon:

    log_daemon_msg "Checking if shares are mounted" "$NAME"
    count=0
    while [ ! -f /home/pi/nas/public/Downloads/check.txt ]
    do
        log_daemon_msg "Waiting 30 seconds to allow for mounting" "$NAME"
        sleep 30
        count=$((count+1))
        if [ $count -eq 10 ]; then
            log_daemon_msg "Giving up after 10 retries. Please check network and mounts" "$NAME"
            exit 1
        fi
    done
    log_daemon_msg "Starting bittorrent daemon" "$NAME"
    start_daemon
    ;;

Now I just have to wait till the power fails again! :-)

I could make it automatically restart after 15 minutes of failure...

0

I do the mounting via autofs/automounter which will delay all the I/O operations until after the share is mounted. However you still need to adjust the init script dependencies in /etc/init.d/transmission-daemon to make sure transmission gets started after autofs e.g. like this:

# Required-Start:    $local_fs $remote_fs $network $named $portmap autofs
# Required-Stop:     $local_fs $remote_fs $network $named $portmap autofs

($portmap is only needed for NFS, may not be necessary in your case)

then re-run:

sudo update-rc.d transmission-daemon defaults

to install and configure autofs on my Raspbian I did:

sudo apt-get install autofs
sudo update-rc.d rpcbind enable # needed for NFS shares

then edit /etc/auto.master and uncomment:

/net    /etc/auto.net

and restart autofs. After that you would have all your NFS shares on your servers available under

/net/<server_name>/<share_name>

If you prefere "static" mountpoints uncomment the /misc/ section in /etc/auto.master and edit /etc/auto.misc accordingly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.