我正在编写一个 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
授予了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
原文由 anwesh mohapatra 发布,翻译遵循 CC BY-SA 4.0 许可协议
将 shebang 添加到脚本中
和执行许可