Menu

Make transmission-daemon behave more like a Windows service?

flash0082
2018-08-18
2018-08-30
  • flash0082

    flash0082 - 2018-08-18

    Hi, I'm new here.

    First of all let me say thank you for all the amazing resources I've found in this forum. It's allowed me to set up Transmission on a Windows homeserver and connect to it via the remote GUI. All of that has been awesome and definitely works tons better than any other torrent client solution I've used or tried in the past.

    There's only a small issue I have and that's because the transmission-daemon isn't a service as we know it on Windows. After installing the service in the recommended method (I'm using the following command by the way) ...

    cygrunsrv.exe --install TransmissionBT --path "C:/torrent/transmission/transmission-daemon.exe" -O -a "--logfile transmission-log.txt --pid-file transmission-daemon.pid"
    

    ... I am happy to say that it seems to work exactly like a service. The only downside comes from the fact that no settings are saved when Windows is shut down or restarted. There are two possibilities why this may happen:

    1. Because cygrunsrv.exe is a service that does not appear to run (Windows doesn't believe it is active), since it acts more like an intermediary to the transmission-daemon and it's not a constantly running background process of the service kind. This could make the -O argument (When in effect, cygrunsrv sends the shutdown signal (see --shutsig) to the application process when cygrunsrv learns that the system is shutting down.) useless.
    2. Because the default shutdown signal of cygrunsrv.exe doesn't work for the transmission-daemon. I've tried all those mentioned in the docs (next to TERM there were HUP, INT and QUIT mentioned by name) with no success. Does the daemon even have a shutdown/termination signal that would make it shutdown softly while writing any changes to the config?
    3. It may also be possible that Windows may shut down client applications like the transmission-daemon earlier than services, which means the process has already been terminated before the service can do so gracefully.

    I've also used the group policy shutdown script to execute the soft stop. While the script is being executed, it doesn't work in stopping the transmission-daemon softly. The timing as mentioned in 3. above may be an issue.

    Right now I'm executing a simple batch script manually that does use transmission-remote.exe too and then begins the shutdown/restart process. That works, but only if I am shutting down or restarting manually. If I'm not in control of the action or simpy forget about it no changes are written to file.

    I know this shouldn't be too big of a deal but I have fallen into this trap half a dozen times already, mostly when I was changing bandwidth settings that were suddenly wildly different the next day.

    Things I haven't tried yet are to write my own service that runs all the time, so it would fix the possible problem I mentioned in 1. earlier but it would likely run afoul of problem 3. as well. Creating a scheduled task with a trigger using an event-log entry will very likely to run into the same problem.

    Are there any other ways you guys can think of that would reliably shut down the headless daemon softly?

    Thanks for all your help,
    flash

     
  • flash0082

    flash0082 - 2018-08-30

    Wow, thanks for the very detailed reply. I appreciate this a lot!

    So, I have done some more testing on Windows 10, since the NUC-like device came with a license and I need a Windows-based OS for some other software too. The problems I mentioned in my initial post are definitely of the timing variety. Based on data gathered from my own code testing, once a shutdown is initiated, it will immediately kill off regular tasks before any shutdown commands are executed (task, group policy or the other way around) and finally it's the services. It's what I expected.

    I did forget about the WM_QUERYENDSESSION though, so I'm happy for your helpful reply. Shut It seems to be exactly what I want. I'm not sure if it's going to work as expected on a Win 10 (or any Win Vista+ version for that matter) but I'll be trying it soon.

    By the way, in my research I came upon a blog post (Russian original / English translation) that made it a lot clearer how the operating system shutdown process works under the hood. The focus has to be on the "top-level window", because apparently Windows won't send the WM_QUERYENDSESSION to processes that don't have one visible.

    If Shut It won't work, I'm thinking of some other possible avenues to follow.

    But right now I'm questioning if that work would even be worth it. The only settings that I can see myself changing regularly are not very important and I can do a manual restart of the daemon for others. I've observed t hat the statistics relating to torrents (stats.json and the .resume files) are updated every 5-15 (?) minutes already, so the potential loss is limited.

     

Log in to post a comment.