feat(cmd, osutil): implement Windows Services API communication (fixes #7042)#10524
feat(cmd, osutil): implement Windows Services API communication (fixes #7042)#10524rafaeloledo wants to merge 4 commits intosyncthing:mainfrom
Conversation
Signed-off-by: rafaeloledo <[email protected]>
lib/osutil/services_windows.go
Outdated
| s <- c.CurrentStatus | ||
| case svc.Stop, svc.Shutdown: | ||
| s <- svc.Status{State: svc.StopPending} | ||
| _ = exec.Command("taskkill", "/IM", "syncthing.exe", "/F").Run() |
There was a problem hiding this comment.
Why do we need to stop in such a reflective manner? This should simply result in a regular shutdown from within.
7a5b1bd to
caf26a5
Compare
Interrupt works well when the service is on console emulating CTRL+C/CTRL+D signals in this case, it's working as a service tied to Windows Service API, so it's not working executing a manual separate taskkill is discouraged also remove code that is not needed Signed-off-by: rafaeloledo <[email protected]> Co-authored-by: bt90 <[email protected]>
|
@bt90 So, i was trying to implement a good solution for stopping the process tree. The most recommended is sending Interrupt signal. Unfortunately, it's not working on my tests. Sending If i stop the service in the CLI, no warnings are given. So, the warning is a non-blocking action. It's better than no communication. 2026-01-10.19-06-52.mp4If anyone knows how to improve the Stop action, i can merge it here. |
|
Isn't the thing that the notification is sent to the running process, so you don't need to find a process and send it a signal, because it is ourselves... We need to cancel the context in main so that the process exits? |
6ba70e5 to
85521a0
Compare
Signed-off-by: rafaeloledo <[email protected]> Co-authored-by: Jakob Borg <[email protected]>
|
Does the PR fix #7042? |
I think so. Just to remind, i've implemented Start and Stop actions. It can start with windows without popping the terminal whatsoever. Btw, this issue is been there for a while... 2020 👀. I don't know if my implementation is 100%, so, i'm accepting any improvements. |
Signed-off-by: rafaeloledo <[email protected]>

Purpose
The purpose of this change is related to syncthing/docs#955. Since
--no-consoleis being discouraged on Windows 11 due toWindows Terminalbeing the new default "console".Here, i'm adding support for the Windows Services API in the project. It can now communicate and act as a service for Windows Services Manager.
It's necessary to the service be able to Start and Stop on the Manager's GUI.
2026-01-10.03-30-33.mp4
Currently, the Stop action is working in functionality, but it can be coded better.
Testing
Run the following commands on Windows:
Build the app with fake version
Then, create a service linked to the
syncthing.exepath.Run the service
Stop the service
sc stop syncthingDelete the service
https://learn.microsoft.com/en-us/windows/win32/services/services
Authorship
Name: rafaeloledo
Email: [email protected]