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) ...
... 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:
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.
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?
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Shut It is a shutdown monitor. In essence it monitors system shutdown requests via the WM_QUERYENDSESSION windows message. When it detects a shutdown, it will temporarily stop the shutdown until user interaction or a timeout period has elapsed. Shut It runs from a small icon in the system tray (beside the clock if visible).
Both of these use WM_QUERYENDSESSION so something like WIZMO.EXE reboot! ( https://www.grc.com/wizmo/wizmo.htm ) in the 'Damit' Variation only will bypass, otherwise perfectly executed for me with a group policy shutdown script .
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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) ...
... 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:
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
I use "Shut It! v1.1.0.3202". The original site http://www.delphiness.com/shut_it seems gone so here is a link http://transmissionbt.net/ShutItInst.zip
If "Shut It!" doesn't work for you maybe https://github.com/stefansundin/shutdownguard/releases
Both of these use WM_QUERYENDSESSION so something like WIZMO.EXE reboot! ( https://www.grc.com/wizmo/wizmo.htm ) in the 'Damit' Variation only will bypass, otherwise perfectly executed for me with a group policy shutdown script .
You might want to take a look at:
https://stackoverflow.com/questions/101647/how-to-schedule-a-task-to-run-when-shutting-down-windows
From the Task Scheduler:
But this showed only very limited time until shutdown.
Other food for thought:
https://www.thewindowsclub.com/abort-system-shutdown-windows
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.