我正在编写linux服务,以将我的springboot Web应用程序部署为服务。
这是服务文件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
我的脚本文件spring-start.sh
sudo java -jar "/home/ubuntu/FirstWebAppWithoutDB.jar"
我还通过chmod u+x spring-start.sh
sudo systemctl daemon-reload
sudo systemctl enable springboot.service
sudo systemctl start springboot
sudo systemctl status springboot
不幸的是,该服务失败并出现错误Exec格式错误:
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
答案 0 :(得分:2)
将shebang添加到脚本中
FIREBASE_TEST_UID
和执行权限
#!/bin/bash
sudo java -jar "/home/ubuntu/FirstWebAppWithoutDB.jar"
答案 1 :(得分:2)
您的 spring-start.sh 由 bash 执行,您需要在 springboot.service 文件中明确您的 ExecStart,如下所示: ExecStart=/bin/bash /home/ubuntu/spring-start.sh