How to use
Under Spring Boot
When using Spring Boot, simply import the systemd-spring-boot-starter
module as a dependency:
<dependencies>
<dependency>
<groupId>com.github.jpmsilva.jsystemd</groupId>
<artifactId>jsystemd-spring-boot-starter</artifactId>
<version>3.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
Autoconfiguration takes place through the class SystemdAutoConfiguration, and will notify systemd once your application starts up successfully, via a Spring Boot event listener of type ApplicationReadyEvent.
Regular Java application
As a regular Java application, you can also use jsystemd.
First, import the jsystemd-core
module as a dependency:
<dependencies>
<dependency>
<groupId>com.github.jpmsilva.jsystemd</groupId>
<artifactId>jsystemd-core</artifactId>
<version>3.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
Then, create an instance of Systemd using the provided builder methods, and once your application completes the startup sequence and is ready to do work, just call ready.
Systemd service unit
When using this library, service units should now use Type=notify
under the [Service]
unit configuration:
[Unit]
Description=MyService
Requires=network.target
After=network.target
After=syslog.target
[Service]
Type=notify
WorkingDirectory=/opt/myservice
ExecStart=/opt/jdk17/bin/java -XX:+ExitOnOutOfMemoryError -jar /opt/myservice/myservice.jar
SuccessExitStatus=143
KillMode=mixed
TimeoutStopSec=10
TimeoutStartSec=30
[Install]
WantedBy=multi-user.target
In the above example, /opt/myservice/myservice.jar
is a packed Java application.