'why am I getting Exec format error when I am writing my linux service?
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
Solution 1:[1]
add shebang to the script
#!/bin/bash
sudo java -jar "/home/ubuntu/FirstWebAppWithoutDB.jar"
and execution permission
chmod +x spring-start.sh
Solution 2:[2]
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
Solution 3:[3]
ExecStart=/bin/bash ... script.sh
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | UtLox |
| Solution 2 | Jamal IMEHLI |
| Solution 3 | IvanP |
