Skip to content

Stopping of java process: logfile issue, status issue #634

@pkaltenboeck

Description

@pkaltenboeck

Summary.
I have a Java application which should run as Windows Service. One important requirement is that I'm able to restart the service inside my java application.

For testing purposes I wrote a small Java programm which calls the winsw.exe (renamed to wrapperService.exe) with the "restart!" argument.

At first I already struggled, because my ShutdownHook (which has a sleep of 20 seconds to simulate some shutdown tasks) hasn't been called - I thought - after checking the Task manager I noticed that my process is still running and ended after 20 seconds. Since I only but some System.out in my code I added a custom file and saw that my ShutdownHook is running as expected, winsw.exe isn't forwarding the System.out after stopping the service.

So I come to the following problems:

  • The ".out.log" isn't completed
  • winsw.exe immediately returns "Stopping process ", but process is still running
  • winsw.exe status says that the process is stopped, but process is still running (during the 20 seconds sleep time)
  • winsw.exe restart! starts a new process before the old is terminated, therefore the same process is running twice
  • edit: forgot to mention: the stoptimeout doesn't work either

wrapperService.xml

<service>
  <id>wrapperService</id>
  <name>WrapperService</name>
  <description>This service runs Jenkins continuous integration system.</description>
  <env name="SERVICE_HOME" value="%BASE%"/>
  <executable>java</executable>
  <arguments>-jar wrapperService.jar</arguments>
   <log mode="roll"></log>
  <stoptimeout>5sec</stoptimeout>
  <interactive>true</interactive>
</service>

Log-Files:
My Application log:

2020-08-06T14:31:05.844 main() start
2020-08-06T14:32:43.491 shutdownHook()
2020-08-06T14:33:03.492 waited 20 seconds

wrapperService.wrapper.log:

2020-08-06 14:31:05,511 INFO  - Starting the service with id 'wrapperService'
2020-08-06 14:31:05,684 DEBUG - Starting WinSW in service mode
2020-08-06 14:31:05,698 DEBUG - Completed. Exit code is 0
2020-08-06 14:31:05,703 INFO  - Starting java
2020-08-06 14:31:05,719 INFO  - Started process 34000
2020-08-06 14:31:05,724 DEBUG - Forwarding logs of the process System.Diagnostics.Process (java) to WinSW.RollingLogAppender
2020-08-06 14:32:43,469 INFO  - Stopping the service with id 'wrapperService'
2020-08-06 14:32:43,482 INFO  - Waiting for the service to stop...
2020-08-06 14:32:43,484 INFO  - Stopping wrapperService
2020-08-06 14:32:43,485 DEBUG - ProcessKill 34000
2020-08-06 14:32:43,488 INFO  - Stopping process 34000
2020-08-06 14:32:43,734 INFO  - The service stopped.
2020-08-06 14:32:43,737 DEBUG - Completed. Exit code is 0

wrapperService.out.log:

2020-08-06T14:31:05.844 main() start

Shell-Snippet:

PS C:\Users\Patrick\Desktop\wrapperService> .\wrapperService.exe start
2020-08-06 14:31:05,511 INFO  - Starting the service with id 'wrapperService'
PS C:\Users\Patrick\Desktop\wrapperService> .\wrapperService.exe stop
2020-08-06 14:32:43,469 INFO  - Stopping the service with id 'wrapperService'
2020-08-06 14:32:43,482 INFO  - Waiting for the service to stop...
2020-08-06 14:32:43,734 INFO  - The service stopped.
PS C:\Users\Patrick\Desktop\wrapperService> tasklist.exe | Select-String -Pattern '34000'

java.exe                     34000 Services                   0        20 176 K

PS C:\Users\Patrick\Desktop\wrapperService>

Environment

  • WinSW version: 3.0.0+fff33fdbdbd830458d364415078e0c1e7d967acb
  • WinSW package type: WinSW.NET461.exe
  • Windows version: Windows 10 x64 (1909)
  • Wrapped executable and version: java

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions