Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 410
anwesh mohapatra Avatar asked Jul 14 '19 08:07

anwesh mohapatra


2 Answers

add shebang to the script

#!/bin/bash
sudo java -jar "/home/ubuntu/FirstWebAppWithoutDB.jar"

and execution permission

chmod +x spring-start.sh
like image 172
UtLox Avatar answered Sep 23 '22 00:09

UtLox


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

like image 23
Jamal IMEHLI Avatar answered Sep 20 '22 00:09

Jamal IMEHLI