kemitix / spring-boot-daemon

Deploy a Spring Boot application as a Windows Service

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spring Boot Daemon

Manage a Spring Boot application as a Windows Service

Building

You need Maven to build the project and a simple `mvn package` at the root will do.

Unix

There is no need for Spring Boot Daemon on Unix thanks to the native Spring Boot support from 1.3 onwards.

Windows

The `windows` distribution uses https://github.com/kohsuke/winsw[`winsw`].

WARNING: You need to install the `.NET` framework on the target machine first.

Installing and Running Services

To install the application as a service, extract the distribution zip somewhere and open a shell with administrative rights in that directory.

Install Service

C:\dir> install.bat

Once the service has been installed, you can start it the usual way, that is:

Start Service

C:\dir> startup.bat

Stop Service

C:\dir> shutdown.bat

Run Application from Command line

C:\dir> run.bat

View Service Status

C:\dir> status.bat

Note: A result of `NonExistent` means the service is not installed.

Uninstall Service

C:\dir> shutdown.bat
C:\dir> uninstall.bat

Logs

The logs are available in the `logs` directory of the distribution.

Usage in your application

Or, **How to convert your application into a Windows Service**.

To enable running your own Spring Boot applications as a Windows Service:

  • add `net.kemitix:spring-boot-daemon-integration` as a dependency
  • copy, unaltered, the `assembly` and `dist` directories from `spring-boot-daemon-sample/src/main` into your own application sources
  • add the `project/build/plugins` section from `spring-boot-daemon-sample/pom.xml` to your own `pom.xml`, including the `spring-boot-maven-plugin` (needs layout=ZIP), which should be first among these plugins
  • add the following properties and repositories to your `pom.xml`, updating the values to suit:
<properties>
     <spring-boot.version>1.3.5.RELEASE</spring-boot.version>
     <start-class>net.nicoll.SampleApplication</start-class> <!--1-->
     <winsw.version>1.18</winsw.version>
     <maven-dependency-plugin.version>2.10</maven-dependency-plugin.version>
     <maven-resources-plugin.verion>2.7</maven-resources-plugin.verion>
     <maven-assembly-plugin.version>2.6</maven-assembly-plugin.version>
     <dist.dir>${project.build.directory}/dist</dist.dir>
     <dist.service.name>${project.artifactId}</dist.service.name>
     <dist.service.display.name>Sample Spring Boot App</dist.service.display.name> <!--2-->
     <dist.service.description>
         Demonstrate how to integrate a Spring Boot app as a Windows Service <!--3-->
     </dist.service.description>
     <dist.jar>lib\${project.artifactId}-${project.version}.jar</dist.jar>
     <dist.start.class>${start-class}</dist.start.class>
     <dist.jmx.port>50201</dist.jmx.port> <!--4-->
 </properties>
 <repositories>
     <repository><!-- repo for downloading winsw.exe from -->
         <id>jenkins</id>
         <name>Jenkins Repository</name>
         <url>http://repo.jenkins-ci.org/releases</url>
         <snapshots>
             <enabled>false</enabled>
         </snapshots>
     </repository>
 </repositories>
  1. Your Spring Boot application class
  2. The name that shows in the Windows Services Control Panel
  3. The longer description that shows in the Windows Services Control Panel
  4. The JMX Port on the machine that will be assigned to the server, must not conflict with another usage and is required to be able to shutdown the service

About

Deploy a Spring Boot application as a Windows Service

License:Other


Languages

Language:Java 83.1%Language:Groovy 16.9%