systemd is the successor of the System V init system and is now being used by many modern Linux distributions. Although you can continue to use
init.d scripts with
systemd, it is also possible to launch Spring Boot applications by using
systemd ‘service’ scripts.
Assuming that you have a Spring Boot application installed in
/var/myapp, to install a Spring Boot application as a
systemd service, create a script named
myapp.service and place it in
/etc/systemd/system directory. The following script offers an example:
[Unit] Description=myapp After=syslog.target [Service] User=myapp ExecStart=/var/myapp/myapp.jar SuccessExitStatus=143 [Install] WantedBy=multi-user.target
|Remember to change the
Note that, unlike when running as an
init.d service, the user that runs the application, the PID file, and the console log file are managed by
systemd itself and therefore must be configured by using appropriate fields in the ‘service’ script. Consult the service unit configuration man page for more details.
To flag the application to start automatically on system boot, use the following command:
$ systemctl enable myapp.service
man systemctl for more details.