背景:从23年底部署jenkins后就没升过级,安装插件顺手更新后导致无法启动,服务端运行状态显示 jenkins systemd[1]: Failed to start Jenkins Continuous Integration Server.
无法重新启动的状态信息
root@jenkins:~# sudo systemctl status jenkins
● jenkins.service - Jenkins Continuous Integration Server
Loaded: loaded (/lib/systemd/system/jenkins.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/jenkins.service.d
└─override.conf
Active: failed (Result: exit-code) since Tue 2024-07-30 17:16:14 CST; 24s ago
Process: 5405 ExecStart=/usr/bin/jenkins (code=exited, status=1/FAILURE)
Main PID: 5405 (code=exited, status=1/FAILURE)
Jul 30 17:16:14 jenkins systemd[1]: jenkins.service: Scheduled restart job, restart counter is at 5.
Jul 30 17:16:14 jenkins systemd[1]: Stopped Jenkins Continuous Integration Server.
Jul 30 17:16:14 jenkins systemd[1]: jenkins.service: Start request repeated too quickly.
Jul 30 17:16:14 jenkins systemd[1]: jenkins.service: Failed with result 'exit-code'.
Jul 30 17:16:14 jenkins systemd[1]: Failed to start Jenkins Continuous Integration Server.
重点关注:jenkins systemd[1]: jenkins.service: Failed with result 'exit-code'.
起初以为是更新了版本后,jdk版本不匹配,于是先升级jdk到11 (2.346之后貌似最低要求11)
sudo apt update
sudo apt install openjdk-11-jdk
查看java 和 jenkins 版本的命令
java --version
jenkins --version
顺便列举 ubuntu 切换多个jdk的命令,进入后按数字选择即可
update-alternatives --config java
至此,理论上jenkins的版本和java版本应该是互相匹配了,那么修改jenkins的配置,指定java路径
# 查看java目录
root@jenkins:~# which java
/usr/bin/java
# jenkins配置目录
vim /lib/systemd/system/jenkins.service
# 配置到jenkins的语句
Environment="JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64"
# jenkins的这两个配置也可以改为root,避免有权限问题
User=root
Group=root
# jenkins服务的端口号 8080
Environment="JENKINS_PORT=8080"
生效配置,并尝试启动jenkins
systemctl daemon-reload
systemctl start jenkins.service
systemctl status jenkins.service
若仍然失败,则继续查询jenkins的详细报错日志
sudo journalctl -u jenkins.service
我这边仍然无法启动的报错信息:
Starting Jenkins Continuous Integration Server...
Running from: /usr/share/java/jenkins.war
Exception in thread "main" java.io.UncheckedIOException: java.nio.file.NoSuchFileException: /var/log/root/root.log
at executable.Main.main(Main.java:357)
Caused by: java.nio.file.NoSuchFileException: /var/log/root/root.log
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:219)
at java.base/java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:478)
at java.base/java.nio.file.Files.newOutputStream(Files.java:220)
at winstone.Launcher.initLogger(Launcher.java:581)
at winstone.cmdline.CmdLineParser.parse(CmdLineParser.java:83)
at winstone.Launcher.getArgsFromCommandLine(Launcher.java:506)
at winstone.Launcher.main(Launcher.java:468)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at executable.Main.main(Main.java:351)
jenkins.service: Main process exited, code=exited, status=1/FAILURE
jenkins.service: Failed with result 'exit-code'.
Failed to start Jenkins Continuous Integration Server.
jenkins.service: Scheduled restart job, restart counter is at 5.
Stopped Jenkins Continuous Integration Server.
jenkins.service: Start request repeated too quickly.
jenkins.service: Failed with result 'exit-code'.
Failed to start Jenkins Continuous Integration Server.
重点关注:Caused by: java.nio.file.NoSuchFileException: /var/log/root/root.log
其实就是没有目录 /var/log/root 或者没有找到文件 root.log,不管是因为权限还是真的不存在
按这个目录创建对应需要的文件夹和日志文件后,自然可以成功启动
或者在另一份配置文件中调整日志输出的路径,也可以达到一样的效果
vi /etc/default/jenkins
JENKINS_LOG=/var/log/$NAME/$NAME.log
标签:systemd,java,service,Continuous,报错,jenkins,Jenkins,root
From: https://blog.csdn.net/qq_43728899/article/details/140814479