Files
winsw/docs/self-restarting-service.md
Next Turn dcf3013f75 Revise docs for 3.0.0-alpha.3 (#608)
* Mention optional settings

* Mention removed settings

* Add links to system requirements

* markdownlint fixes

* Remove trailing spaces

* Mention boolean elements

* Add preshutdown

* Add `dev ps` command

* Stop misleading

* Why aren't you using Windows 10?

* Add `stdoutPath`/`stderrPath`

* Relative paths and the default working directory

* Send a close message to Windows (GUI) apps

* Use valid XML

* Add `customize` and `dev kill` commands

* Update README.md

* Add commands

* Fix spacing

* Update installation.md

* Update README.md
2020-08-11 07:54:32 +08:00

994 B

Self-restarting Windows services

Restart from the spawned process

To support self-restarting services, winsw exposes WINSW_EXECUTABLE environment variable into the forked process, which refers to the full path of WinSW.exe that's managing the service. To restart the service from within, execute %WINSW_EXECUTABLE% restart!. Note that you are invoking restart! command, not restart command. This hidden command is a flavor of the restart operation, where winsw creates another winsw process in a separate process group, and restarts the service from there.

This additional indirection is necessary because WinSW will kill child processes recursively when it stops a service. Windows Service Control Manager (SCM) doesn't provide the restart operation as an atomic operation either, so winsw implements restart by a sequence of stop and start. The second winsw process in a separate process group ensures that winsw can survive this massacre to execute the start call.