Skip to content

Latest commit

 

History

History
52 lines (43 loc) · 2.19 KB

runawayProcessKiller.md

File metadata and controls

52 lines (43 loc) · 2.19 KB

Runaway Process Killer Extension

In particular cases Windows service wrapper may leak the process after the service completion. It happens when WinSW gets terminated without executing the shutdown logic. Examples: force kill of the service process, .NET Runtime crash, missing permissions to kill processes or a bug in the logic.

Such runaway processes may conflict with the service process once it restarts. This extension allows preventing it by running the runaway process termination on startup before the executable gets started.

Since: WinSW 2.0.

Usage

The extension can be configured via the XML Configuration File. Configuration sample:

<?xml version="1.0" encoding="utf-8" ?>
<service>
  <id>sampleService</id>
  <name>Sample service</name>
  <description>This is a stub service.</description>
  <executable>%BASE%\sleep.bat</executable>
  <arguments></arguments>
  <logmode>rotate</logmode>

  <extensions>
	<!-- This is a sample configuration for the RunawayProcessKiller extension. -->
  <extension enabled="true" 
             className="winsw.Plugins.RunawayProcessKiller.RunawayProcessKillerExtension"
             id="killOnStartup">
      <!-- Absolute path to the PID file, which stores ID of the previously launched process. -->
      <pidfile>%BASE%\pid.txt</pidfile>
      <!-- Defines the process termination timeout in milliseconds. 
           This timeout will be applied multiple times for each child process.
           After the timeout WinSW will try to force kill the process.
      -->
      <stopTimeout>5000</stopTimeout>
      <!-- If true, the parent process will be terminated first if the runaway process gets terminated. -->
      <stopParentFirst>false</stopParentFirst>
    </extension>
  </extensions>
</service>

Notes

  • The current implementation of the the extension checks only the root process (started executable)
  • If the runaway process is detected the entire, the entire process tree gets terminated
  • WinSW gives the runaway process a chance to the gracefully terminate. If it does not do it within the timeout, the process will be force-killed.
  • If the force kill fails, the WinSW startup continues with a warning.