Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

Why is my spring boot service not starting

Writer Mia Lopez

I have a spring boot service that I'm trying to run on my Ubuntu 20.04 server.

I have created a service file in /etc/systemd/system and here is the directory entry.

-rw-r--r-- 1 root root 116 Jun 5 15:10 wfwweb.service

and here is the contents

[Unit]
After=network.service
[Service]
ExecStart=/usr/local/bin/wfwweb-start.sh
[Install]
WantedBy=default.target

Next, I created the shell script in usr/local/bin and here's that directory entry.

-rwxr--r-- 1 root root 169 Jun 5 16:42 wfwweb-start.sh

This contains the following:

#!/bin/bash
java -version >> /var/log/wfwweb/wfwweb.log 2>&1 &
java -jar -Dspring.profiles.active=dev /opt/server/wfwweb-0.9.1.jar >> /var/log/wfwweb/wfwweb.log 2>&1 &

And finally I created a directory in /var/log and set it up for logrotate. Here is that directory entry.

ubuntu@ip-172-31-21-200:/var/log/wfwweb$ ls -lt
total 8
-rw-r--r-- 1 root root 7100 Jun 5 18:16 wfwweb.log
ubuntu@ip-172-31-21-200:/var/log/wfwweb$ 

On reboot, this is the only entry I see in syslog (relating to this).

Jun 5 18:17:43 ip-172-31-21-200 systemd[1]: wfwweb.service: Succeeded.

But the server isn't running and there is nothing in the log file.

If I then type sudo /usr/local/bin/wfwweb-start.sh

The server starts and the log file is filled up with messages.

So it has to be some kind of permissions thing, but I can't see it. Does anyone else?

13

1 Answer

If you intend to fork your application, you need to use Type=forking, or your .service will terminate as soon as the application is placed in the background.

Type=
If set to forking, it is expected that the process configured with ExecStart= will call fork() as part of its start-up. The parent process is expected to exit when start-up is complete and all communication channels are set up. The child continues to run as the main service process, and the service manager will consider the unit started when the parent process exits. This is the behavior of traditional UNIX services. If this setting is used, it is recommended to also use the PIDFile= option, so that systemd can reliably identify the main process of the service. systemd will proceed with starting follow-up units as soon as the parent process exits.

[Unit]
Description=Spring boot service wfwweb
After=network.target
[Service]
SuccessExitStatus=143
Type=forking
ExecStartPre=java -version
ExecStart=/bin/bash -c \ 'exec -a wfwweb java -jar -Dspring.profiles.active=dev /opt/server/wfwweb-0.9.1.jar &'
# User=user
#Group=group
StandardOutput=append:/var/log/wfwweb/wfwweb.log StandardError=append:/var/log/wfwweb/wfwweb.log
Restart=always
WorkingDirectory=/opt/server
[Install]
WantedBy=Multi-user.target
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy