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
add shebang to the script
#!/bin/bash
sudo java -jar "/home/ubuntu/FirstWebAppWithoutDB.jar"
and execution permission
chmod +x spring-start.sh
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With