I am writing a linux service to deploy my springboot web app as a service.
Here is the service file springboot.service
[Unit]
Description=My Webapp Java REST Service
[Service]
User=ubuntu
# The configuration file application.properties should be here:
#change this to your workspace
WorkingDirectory=/home/ubuntu
#path to executable.
#executable is a bash script which calls jar file
ExecStart=/home/ubuntu/spring-start
SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
My script file spring-start.sh
sudo java -jar "/home/ubuntu/FirstWebAppWithoutDB.jar"
I also gave execution permission to the spring-start.sh by chmod u+x spring-start.sh
sudo systemctl daemon-reload
sudo systemctl enable springboot.service
sudo systemctl start springboot
sudo systemctl status springboot
Unfortunately the service fails with error Exec format error:
springboot.service: Failed to execute command: Exec format error
Jul 14 07:39:56 ip-172-31-40-71 systemd[10075]: springboot.service: Failed at step EXEC spawning /home/ubuntu/spring-start.sh: Exec format error
1
add shebang to the script
#!/bin/bash
sudo java -jar "/home/ubuntu/FirstWebAppWithoutDB.jar"
and execution permission
chmod +x spring-start.sh
4
Your spring-start.sh is executed by bash you need to explicit your ExecStart in springboot.service file like this :
ExecStart=/bin/bash /home/ubuntu/spring-start.sh
2
Another answer for those searching! If you are calling a binary and not a script, make sure it’s built for the correct architecture (arm/x86) and that you can run it directly, which might show you the problem.
My binary was built for x86 and when I ran it on arm, the console error was unexpected )
but this caused the binary to error, which caused systemd to log Exec format error
which was nothing to do with the format in the service file.
ExecStart=/bin/bash … script.sh
1