0

I'm struggling to make a SpringBootApp to run as a service at the moment. The biggest issue is that Devops doesn't allow us to make changes on the Ansible scripts that deploys the artifact and creates the service (sample shown below).

[Unit]
Description=A Spring Boot application
After=syslog.target

[Service]
User=rating-gateway
ExecStart=/opt/rating-gateway/rating-gateway-0.0.1-SNAPSHOT.jar
SuccessExitStatus=143
Restart=always
RestartSec=5

Technically, If I were to add java -jar on the ExecStart it will run correctly, but as we cannot edit the Ansible scripts I need to find a workaround. I've read a few guides where the service does not use java -jar instruction, but not sure what would be missing for this to run correctly.

I've added java to the PATH as I thought that would help me. But it didn't.

PATH=/home/rating-gateway/.local/bin:/home/rating-gateway/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/bin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.275.b01-1.el8_3.x86_64/bin

Any other ideas? to workaround this issue?

Thanks in advanced.

PS. I'm a Dev, but got root access to the server, so any help is pretty welcome.


(edit extra info) When I don't have java -jar on the ExecStart command. I get the following error in the /var/log/messages

Mar 30 08:44:44 systemd[134389]: rating-gateway.service: Failed at step EXEC spawning /opt/rating-gateway/rating-gateway-0.0.1-SNAPSHOT.jar: Exec format error

But I've already confirmed the architecture of both platform where jar is built and server that is deployed. Both are x84_64

1

You could use the Linux kernel support for miscellaneous binary formats (binfmt_misc). This allows you to register an interpreter (e.g. Java) to execute a file based on the first few bytes in the file (e.g. a jar file). See https://www.kernel.org/doc/Documentation/admin-guide/binfmt-misc.rst for more information.

1
0

Your error is from system's attempt to parse jar-file searching for an interpreter directive - #!/interpreter.

One way would be to just create shell-script called rating-gateway-0.0.1-SNAPSHOT.jar and run your Java application from it.

So you will end up with 2 files:

  • /opt/rating-gateway/rating-gateway-0.0.1-SNAPSHOT.realjar.jar - your actual jar-file
  • /opt/rating-gateway/rating-gateway-0.0.1-SNAPSHOT.jar - simple shell-script with the following content:
#!/usr/bin/env sh

java -jar /opt/rating-gateway/rating-gateway-0.0.1-SNAPSHOT.jar
1
  • Thanks Anlar. This actually worked, but as we are not able to change the Ansible scripts, this wasn't the solution we were looking for. It might work for other people tho. Thanks again – JDDelgado Mar 30 at 19:46

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.