Running Vaadin Flow Spring App as Windows Service

Hi,

With batch file containing one line.

C:\Users\paulf\QNE\install\jdk-22\bin\java --enable-preview -jar C:\Users\paulf\QNE\install\qne.jar

I have tried nssm and winsw and they both show the service running but the service fails to run the batch file.

The batch file run from file explorer or a console runs OK but shuts down when the console is closed.

The problem may be related to the fact that the spring boot main runs twice which I think is normal ??

Any ideas or examples of Vaadin flow running as a Windows service?

Have you tried the spring-boot-daemon sample from GitHub - snicoll/spring-boot-daemon: Showcase of deploying a Spring Boot application as a Windows Service? I don’t immediately see why a Flow application should need anything different.

@ollit.1
Hi Olli,
That link uses winsw and is basically what I have already tried.
From the windows system log it appears that windows starts the Spring Boot Jar but shuts down after the code starts to run.

When you say “basically what I have already tried”, it sounds like you didn’t try that exact sample included in spring-boot-daemon. In that case, I’d recommend starting with that specific project first, because if you can’t get that one running, you have a better lead to where the problem lies. Stéphane Nicoll would likely be happy to hear about his example being broken.

@ollit.1
I will check that out in detail.
Do you have contact info for Stephane Nicolle?
As a matter of interest, I have set up same system in linux and it works well as a service.

Sorry,
Contact details on Github.

Maybe you have had success the last day and there is no value in this post. However I will share my setup anyway. I did not call a script but java directly from the service. I think that will work in your case also.

I ran a Spring Boot Application with WinSW over many months with daily machine restarts and without any problems. Since then the application is moved over to Linux.

scrubb.xml

<!-- WinSW config file -->
<service>
	<id>scrubb</id>
	<name>scrubb</name>
	<description>This service runs Scrubb. Detect usb, zip content and send email. User downloads.</description>
	<executable>java</executable>
	<arguments>-jar scrubb.jar</arguments>
	<!-- Cannot contain password here. Define as system environment variable instead -->
<!--	<env name="SCRUBB_PASSWORD" value="******"/>-->
</service>

README.md

# WinSW
_Windows Service Wrapper_ helps us install services inside Windows. 

## WinSW commands
On Windows name of `exe` and `xml` must match.

* `scrubb.exe install scrubb.xml`
* `scrubb.exe uninstall scrubb.xml`
* `scrubb.exe start scrubb.xml`
* `scrubb.exe stop scrubb.xml`
* `scrubb.exe restart scrubb.xml`

## Config
The `scrubb.xml` contains the configuration for how to set up the service correctly.

## Commands in order
### Prerequisite 
1. Go into directory WinSW: `cd WinSW`
2. Install service: `scrubb.exe install scrubb.xml`

### Build and deploy
1. Build executable: `mvn clean package`
2. Copy executable to directory WinSW: `cp target\scrubb-0.0.1-SNAPSHOT.jar WinSW\scrubb.jar`
3. `cd WinSW`
4. Restart service: `scrubb.exe restart scrubb.xml`

@avec112 No, John, I have not yet solved my problem and I look forward to trying your approach.
Thanks for passing on your info, I will report back my results.
Paul Fraser

1 Like

@ollit.1 @avec112
Hi Olli and John,

The failure I have had is related to something in my project code (not yet found) as I have successfully used winsw with a flow starter project.

Even though winsw is much larger than nssm (17+ mb) it is much better as it handles the requirement for administrator for windows service install much better from a user viewpoint . This is because the required .Net code is available in one of the binary downloads of winsw.

I contacted Stephane about his winsw repo and he is aware that it is out of date but had no current plans to update it.

Thank you both for your contributions to this topic.

1 Like