背景:新開發(fā)一個(gè)java服務(wù),寫完部署用公司共用的jenkins服務(wù)部署發(fā)現(xiàn)報(bào)錯(cuò),報(bào)錯(cuò)如下。
1、使用systemctl status xxx-xx-xx-service.service
查看該服務(wù)發(fā)現(xiàn),也可以使用cat /var/log/message
查看系統(tǒng)日志找報(bào)錯(cuò)原因。
xxx-xxx-xxx-service.service - xxx-xxx-xxx-SERVICE
Loaded: loaded (/usr/lib/systemd/system/xxx-xxx-xxx-service.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2023-08-29 15:03:50 CST; 38s ago
Process: 29024 ExecStart=/data/apps/xxx-xxx-xxx-xxx/xxx-xxx-xxx-SERVICE (code=exited, status=203/EXEC)
Main PID: 29024 (code=exited, status=203/EXEC)
Aug 29 15:03:50 test-auth-server systemd[1]: Started xxx-xxx-xxx-SERVICE.
Aug 29 15:03:50 test-auth-server systemd[1]: Starting xxx-xxx-xxx-SERVICE...
Aug 29 15:03:50 test-auth-server systemd[1]: xxx-xxx-xxx-service.service: main process exited, code=exited, status=203/EXEC
Aug 29 15:03:50 test-auth-server systemd[1]: Unit xxx-xxx-xxx-service.service entered failed state.
Aug 29 15:03:50 test-auth-server systemd[1]: xxx-xxx-xxx-service.service failed.
這個(gè)日志中(code=exited, status=203/EXEC)這個(gè)是錯(cuò)誤信息,我百度了一下,查了半天也沒發(fā)現(xiàn)到底什么原因,因?yàn)槠匠V苯訌?fù)制jenkins已有的項(xiàng)目配置部署沒問題,這個(gè)是自己新開發(fā)的項(xiàng)目不知道為什么,一直失敗,jenkins一直在做健康檢查。
就像這樣,連服務(wù)都沒啟動(dòng)(最后發(fā)現(xiàn)其實(shí)是maven配置的問題)。
FAILED - RETRYING: Healthcheck | Wait for xxx-xx-xx-service to be healthy on URLs [u'http://localhost:8098/actuator/health'] (40 retries left).
2、使用systemctl
命令查不出來(lái)所以然,就嘗試看var/log/message
系統(tǒng)日志,最終查到了相關(guān)信息是。
systemd: Started xx-xxx-xxx-SERVICE.
systemd: Starting xxx-xxx-xxx-SERVICE...
systemd: Failed at step EXEC spawning /data/apps/xx-xx-xxx-SERVICE/xx-xx-xx-SERVICE: Exec format error
systemd: xx-xx-xxx-service.service: main process exited, code=exited, status=203/EXEC
systemd: Unit xxx-xxx-xxx-service.service entered failed state.
systemd: xxx-xxx-xxx-service.service failed.
yanfa: [euid=yanfa]:yanfa pts/6 2023-08-28 12:57 (10.19.69.228):[/data/apps]2023-08-28 12:57:36 yanfa ll
ansible-systemd: Invoked with no_block=False force=None name=xxx-xxx-service daemon_reexec=False enabled=True daemon_reload=False state=restarted masked=None scope=None user=None
最終定位到
Failed at step EXEC spawning /data/apps/xx-xx-xxx-SERVICE/xx-xx-xx-SERVICE: Exec format error
這個(gè)是說(shuō)這個(gè)文件 有問題,通過(guò)file 命令看到這個(gè)其實(shí)就是打包后的jar文件了。file /data/apps/xxx-xxx-SERVICE/xxx-xx-xx-SERVICE
.它是一個(gè)軟連接,到這其實(shí)要開始運(yùn)行jar文件然后啟動(dòng)java服務(wù),但是就是這的問題,導(dǎo)致服務(wù)沒啟動(dòng)。
這個(gè)是查的原因:
根據(jù)你提供的信息,這個(gè)符號(hào)鏈接指向了一個(gè)名為 engine-0.0.1-SNAPSHOT.jar 的 JAR 文件,但是啟動(dòng)服務(wù)時(shí)卻出現(xiàn)了 status=203/EXEC 的錯(cuò)誤,這通常是由于二進(jìn)制文件格式不正確導(dǎo)致的。
可能的原因包括:
JAR 文件的權(quán)限不正確,導(dǎo)致無(wú)法執(zhí)行。
JAR 文件的格式不正確,無(wú)法在當(dāng)前系統(tǒng)上執(zhí)行。
JAR 文件的依賴項(xiàng)不正確,導(dǎo)致無(wú)法執(zhí)行。
你可以嘗試使用 java -jar 命令來(lái)手動(dòng)執(zhí)行 JAR 文件,以便查看詳細(xì)的錯(cuò)誤信息。例如:
java -jar /data/apps/YSDQ-USER-LEVEL-SERVICE/YSDQ-USER-LEVEL-SERVICE
如果 JAR 文件能夠正常執(zhí)行,則說(shuō)明問題可能出在服務(wù)啟動(dòng)腳本中。如果 JAR 文件無(wú)法執(zhí)行,則需要檢查 JAR 文件的權(quán)限、格式和依賴項(xiàng),以便解決問題。
但是我還是沒解決到底什么原因,最后問的同事,幫忙看了下maven的配置。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-682607.html
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
<mainClass>com.xxx.xxx.XXXServiceApplication</mainClass>
</configuration>
<version>${spring-boot.version}</version>
</plugin>
解釋:文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-682607.html
如果不設(shè)置 <executable>true</executable>,則Maven不會(huì)將生成的JAR文件標(biāo)記為可執(zhí)行文
件,這意味著你不能直接運(yùn)行它,而需要手動(dòng)指定Java命令來(lái)啟動(dòng)應(yīng)用程序。設(shè)置
<executable>true</executable> 可以使生成的JAR文件成為可執(zhí)行文件,
使得你可以直接通過(guò)命令行啟動(dòng)應(yīng)用程序。
到了這里,關(guān)于jenkins部署java服務(wù)發(fā)生(code=exited, status=203/EXEC)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!