How to provide spring.config.location to WinSW to install SpringBoot as Windows service?

0

I'm trying to set up a WinSW to install a Spring Boot JAR as a Windows service on Windows10. So far it works when I just provide the JAR filename and the configuration options in the XML file.

<service>
    <id>testSB/id>
    <name>testSB</name>
    <description>This service runs a spring boot JAR as service.</description>
    <executable>java</executable>
    <startmode>Automatic</startmode>
    <delayedAutoStart>true</delayedAutoStart>
    <onfailure action="restart" delay="10 sec"/>
    <onfailure action="restart" delay="20 sec"/>
    <onfailure action="none"/>
    <resetfailure>1 hour</resetfailure>
    <arguments>-jar "myjar-1.0.0.jar" </arguments>
    <log mode="roll-by-size-time">
      <sizeThreshold>20480</sizeThreshold>
      <pattern>yyyyMMdd</pattern>
      <autoRollAtTime>00:30:00</autoRollAtTime>
      <zipOlderThanNumDays>5</zipOlderThanNumDays>
    </log>
    <logpath>%BASE%/logs</logpath>
</service>

It works and I can see the main page.

But, if I add --spring.config.location=application.yml, service will not run.

<service>
    <id>testSB/id>
    <name>testSB</name>
    <description>This service runs a spring boot JAR as service.</description>
    <executable>java</executable>
    <startmode>Automatic</startmode>
    <delayedAutoStart>true</delayedAutoStart>
    <onfailure action="restart" delay="10 sec"/>
    <onfailure action="restart" delay="20 sec"/>
    <onfailure action="none"/>
    <resetfailure>1 hour</resetfailure>
    <arguments>-jar "myjar-1.0.0.jar" --spring.config.location=./application.yml</arguments>
    <log mode="roll-by-size-time">
      <sizeThreshold>20480</sizeThreshold>
      <pattern>yyyyMMdd</pattern>
      <autoRollAtTime>00:30:00</autoRollAtTime>
      <zipOlderThanNumDays>5</zipOlderThanNumDays>
    </log>
    <logpath>%BASE%/logs</logpath>
</service>

Doesn't matter if I use relative path ./application.yml, using the %BASE%: %BASE%/application.yml, absolute path: C:\path\to\app.yml. It always fails and logs only say:

2020-09-21 16:57:25,626 DEBUG - Completed. Exit code is 0
2020-09-21 16:57:30,560 DEBUG - Starting WinSW in console mode
2020-09-21 16:57:30,930 DEBUG - User requested the status of the process with id 'testSB'
2020-09-21 16:57:30,932 DEBUG - Completed. Exit code is 0
2020-09-21 16:57:35,363 DEBUG - Starting WinSW in service mode
2020-09-21 16:57:35,380 INFO  - Starting java -jar "myjar-1.0.0.jar" --spring.config.location=C:\path\to\application.yml
2020-09-21 16:57:35,395 DEBUG - Completed. Exit code is 0

The Windows Event Viewer shows an error with this content:

Service cannot be started. System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
   at WinSW.Util.ProcessHelper.StartProcessAndCallbackForExit(Process processToStart, String executable, String arguments, Dictionary`2 envVars, String workingDirectory, Nullable`1 priority, ProcessCompletionCallback callback, Boolean redirectStdin, LogHandler logHandler, Boolean hideWindow)
   at WinSW.WrapperService.StartProcess(Process processToStart, String arguments, String executable, LogHandler logHandler, Boolean redirectStdin)
   at WinSW.WrapperService.OnStart(String[] args)
   at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)

Is there a way to provide this spring boot option to launch the JAR??

spring-boot
windows-services
winsw
asked on Stack Overflow Sep 21, 2020 by Alfabravo • edited Sep 21, 2020 by Alfabravo

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0