If you make a Jar in the form of Fully Executable Jar, a script will be added to the beginning of the Jar and output. This script can be used as it is as a script for starting the service.
To create it, make the contents of the <build> tag in pom.xml as follows.
pom.xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
<executable> true </ executable> is the key
Create a file with the same name as the Jar file to be executed but with the extension changed to .conf.
The contents are the definition of environment variables, options to be passed to java, and runtime arguments to be passed to jar.
export LANG="ja_JP.UTF8"
JAVA_OPTSJAVA_OPTS="-Xms1024M -Xmx1024M"
RUN_ARGSRUN_ARGS="--spring.profiles.active=production"
For systemd such as CentOS7, it is OK if you create a service file in / etc / systemd / system /
/etc/systemd/system/hoge.service
[Unit]
Description = <Service description>
[Service]
ExecStart = /home/application/hoge.jar
Restart = always
Type = simple
User = application
Group = application
SuccessExitStatus = 143
[Install]
WantedBy = multi-user.target
with this
$ sudo systemctl start hoge
Can do something
Recommended Posts