[英]Why am I getting “error: implicit declaration of function ‘fileno’” when I try to compile on Linux but not on a Mac
[英]why am I getting Exec format error when I am writing my linux service?
我正在編寫一個 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
將shebang添加到腳本中
#!/bin/bash
sudo java -jar "/home/ubuntu/FirstWebAppWithoutDB.jar"
和執行權限
chmod +x spring-start.sh
您的spring-start.sh由bash執行,您需要在springboot.service文件中明確您的 ExecStart,如下所示: ExecStart=/bin/bash /home/ubuntu/spring-start.sh
那些搜索的另一個答案! 如果您調用的是二進制文件而不是腳本,請確保它是為正確的體系結構 (arm/x86) 構建的,並且您可以直接運行它,這可能會向您顯示問題。
我的二進制文件是為 x86 構建的,當我在 arm 上運行它時,控制台錯誤是unexpected )
但這導致二進制文件出錯,導致 systemd 記錄Exec format error
,這與服務文件中的格式無關。
ExecStart=/bin/bash... 腳本.sh
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.