Tokyo
Tokyo

Reputation: 211

Jar as a Service in RHEL 8.2 - Not Starting

I have a spring boot uber jar that I need to run as a service in RHEL 8.2 environment.

The service file created in /etc/systemd/system/myapp.service is as simple as this:

[Unit]
Description=myapp

[Service]
User=appuser
WorkingDirectory=/home/appuser 
ExecStart=/usr/bin/java -Xmx256m -jar -Dspring.profiles.active=test /home/appuser/myapp.jar 
SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

Now when I try to start the service and check the status using the below commands I get the below error:

[root@myappdev01 /etc/systemd/system]# sudo systemctl status myapp
myapp.service - myapp
   Loaded: loaded (/etc/systemd/system/myapp.service; disabled; vendor preset: disabled)
   Active: activating (auto-restart) (Result: exit-code) since Fri 2020-09-11 23:48:26 +04; 5s ago
  Process: 273497 ExecStart=/usr/bin/java -jar -Dspring.profiles.active=test /home/appuser/myapp.jar (code=exited, status=1/FAILURE)
 Main PID: 273497 (code=exited, status=1/FAILURE)

Sep 11 23:48:26 myappdev01.server systemd[1]: myapp.service: Main process exited, code=exited, status=1/FAILURE
Sep 11 23:48:26 myappdev01.server systemd[1]: myapp.service: Failed with result 'exit-code'.

journatlctl -u myapp.service also doesn't help much.

What have I done wrong here?

Upvotes: 2

Views: 1131

Answers (1)

Mureinik
Mureinik

Reputation: 311188

The jar you're using needs to come directly after the -jar flag:

ExecStart=/usr/bin/java -Xmx256m -Dspring.profiles.active=test -jar /home/appuser/myapp.jar 

Upvotes: 1

Related Questions