Home > Back-end >  Jenkins fails after updating in AWS EC2 machine
Jenkins fails after updating in AWS EC2 machine

Time:09-22

I have Jenkins installed in an EC2 machine in AWS. I tried to install the slack plugin and it break the other plugins, so I tried updating Jenkins version to make it work again and now I cannot event start it. I get the following message:

Starting jenkins (via systemctl):  Failed to start jenkins.service: Unit is not loaded properly: Invalid argument.
See system logs and 'systemctl status jenkins.service' for details.
                                                           [FAILED]

I have also tried to delete Jenkins completely following this guide: to then reinstall it following the Jenkins in AWS guide. But it is still not working. At some point when I did the journalctl -xe I got this error (I cant remember what I did to get there but at least I saved this log trace):

Unit jenkins.service has begun starting up.
Sep 20 16:39:49 ip-10-10-3-149.ec2.internal jenkins[23035]: Sep 20, 2022 4:39:49 PM executable.Main verifyJavaVersion
Sep 20 16:39:49 ip-10-10-3-149.ec2.internal jenkins[23035]: SEVERE: Running with Java class version 52, which is older than
Sep 20 16:39:49 ip-10-10-3-149.ec2.internal jenkins[23035]: java.lang.UnsupportedClassVersionError: 52.0
Sep 20 16:39:49 ip-10-10-3-149.ec2.internal jenkins[23035]: at executable.Main.verifyJavaVersion(Main.java:145)
Sep 20 16:39:49 ip-10-10-3-149.ec2.internal jenkins[23035]: at executable.Main.main(Main.java:109)
Sep 20 16:39:49 ip-10-10-3-149.ec2.internal jenkins[23035]: Jenkins requires Java versions [17, 11] but you are running wit
Sep 20 16:39:49 ip-10-10-3-149.ec2.internal jenkins[23035]: java.lang.UnsupportedClassVersionError: 52.0
Sep 20 16:39:49 ip-10-10-3-149.ec2.internal jenkins[23035]: at executable.Main.verifyJavaVersion(Main.java:145)
Sep 20 16:39:49 ip-10-10-3-149.ec2.internal jenkins[23035]: at executable.Main.main(Main.java:109)
Sep 20 16:39:49 ip-10-10-3-149.ec2.internal systemd[1]: Failed to start Jenkins Continuous Integration Server.
-- Subject: Unit jenkins.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit jenkins.service has failed.
--

So I though I had finally found the error, I checked the java -version and it was saying java1.8. Therefore I changed it with alternatives --config java and set it to:

java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.16.0.8-1.amzn2.0.1.x86_64/bin/java)

I have also added this path to /etc/rc.d/init.d/jenkins. Now when I get the java -version I get this:

openjdk version "11.0.16" 2022-07-19 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.16.0.8-1.amzn2.0.1) (build 11.0.16 8-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.16.0.8-1.amzn2.0.1) (build 11.0.16 8-LTS, mixed mode, sharing)

when I try to get the status of jenkins with systemctl status jenkins.service -l I get:

● jenkins.service
   Loaded: error (Reason: Invalid argument)
  Drop-In: /etc/systemd/system/jenkins.service.d
           └─override.conf
   Active: failed (Result: start-limit) since Tue 2022-09-20 16:39:49 UTC; 15h ago
 Main PID: 23035 (code=exited, status=0/SUCCESS)

Sep 20 16:57:30 ip-10-10-3-149.ec2.internal systemd[1]: jenkins.service lacks both ExecStart= and ExecStop= setting. Refusing.
Sep 20 16:57:43 ip-10-10-3-149.ec2.internal systemd[1]: jenkins.service lacks both ExecStart= and ExecStop= setting. Refusing.
Sep 21 07:15:59 ip-10-10-3-149.ec2.internal systemd[1]: jenkins.service lacks both ExecStart= and ExecStop= setting. Refusing.
Sep 21 07:20:02 ip-10-10-3-149.ec2.internal systemd[1]: jenkins.service lacks both ExecStart= and ExecStop= setting. Refusing.
Sep 21 07:23:12 ip-10-10-3-149.ec2.internal systemd[1]: jenkins.service lacks both ExecStart= and ExecStop= setting. Refusing.
Sep 21 07:23:20 ip-10-10-3-149.ec2.internal systemd[1]: jenkins.service lacks both ExecStart= and ExecStop= setting. Refusing.
Sep 21 07:24:26 ip-10-10-3-149.ec2.internal systemd[1]: jenkins.service lacks both ExecStart= and ExecStop= setting. Refusing.
Sep 21 07:30:58 ip-10-10-3-149.ec2.internal systemd[1]: jenkins.service lacks both ExecStart= and ExecStop= setting. Refusing.
Sep 21 07:31:06 ip-10-10-3-149.ec2.internal systemd[1]: jenkins.service lacks both ExecStart= and ExecStop= setting. Refusing.
Sep 21 07:48:04 ip-10-10-3-149.ec2.internal systemd[1]: jenkins.service lacks both ExecStart= and ExecStop= setting. Refusing.

and when I use journalctl -xe I get:

-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit session-120.scope has finished starting up.
-- 
-- The start-up result is done.
Sep 21 07:40:01 ip-10-10-3-149.ec2.internal CROND[842]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Sep 21 07:41:28 ip-10-10-3-149.ec2.internal dhclient[3121]: XMT: Solicit on eth0, interval 131610ms.
Sep 21 07:43:39 ip-10-10-3-149.ec2.internal dhclient[3121]: XMT: Solicit on eth0, interval 118630ms.
Sep 21 07:45:38 ip-10-10-3-149.ec2.internal dhclient[3121]: XMT: Solicit on eth0, interval 121300ms.
Sep 21 07:46:59 ip-10-10-3-149.ec2.internal sshd[3483]: Received disconnect from 92.255.85.69 port 28784:
Sep 21 07:46:59 ip-10-10-3-149.ec2.internal sshd[3483]: Disconnected from 92.255.85.69 port 28784 [preaut
Sep 21 07:47:04 ip-10-10-3-149.ec2.internal dhclient[3075]: DHCPREQUEST on eth0 to 10.10.3.1 port 67 (xid
Sep 21 07:47:04 ip-10-10-3-149.ec2.internal dhclient[3075]: DHCPACK from 10.10.3.1 (xid=0x18dc5aad)
Sep 21 07:47:04 ip-10-10-3-149.ec2.internal NET[3542]: dhclient: Locked /run/dhclient/resolv.lock
Sep 21 07:47:04 ip-10-10-3-149.ec2.internal dhclient[3075]: bound to 10.10.3.149 -- renewal in 1618 secon
Sep 21 07:47:04 ip-10-10-3-149.ec2.internal ec2net[3561]: [get_meta] Querying IMDS for meta-data/network/
Sep 21 07:47:04 ip-10-10-3-149.ec2.internal ec2net[3562]: [get_meta] Getting token for IMDSv2.
Sep 21 07:47:04 ip-10-10-3-149.ec2.internal ec2net[3565]: [get_meta] Trying to get http://169.254.169.254
Sep 21 07:47:04 ip-10-10-3-149.ec2.internal ec2net[3570]: [remove_aliases] Removing aliases of eth0
Sep 21 07:47:39 ip-10-10-3-149.ec2.internal dhclient[3121]: XMT: Solicit on eth0, interval 116180ms.
Sep 21 07:48:03 ip-10-10-3-149.ec2.internal sudo[3947]:     root : TTY=pts/0 ; PWD=/root ; USER=root ; CO
Sep 21 07:48:03 ip-10-10-3-149.ec2.internal sudo[3947]: pam_unix(sudo:session): session opened for user r
Sep 21 07:48:03 ip-10-10-3-149.ec2.internal systemd[1]: Reloading.
Sep 21 07:48:04 ip-10-10-3-149.ec2.internal systemd[1]: jenkins.service lacks both ExecStart= and ExecSto
Sep 21 07:48:04 ip-10-10-3-149.ec2.internal sudo[3947]: pam_unix(sudo:session): session closed for user r
Sep 21 07:48:09 ip-10-10-3-149.ec2.internal sudo[4019]:     root : TTY=pts/0 ; PWD=/root ; USER=root ; CO
Sep 21 07:48:09 ip-10-10-3-149.ec2.internal sudo[4019]: pam_unix(sudo:session): session opened for user r
Sep 21 07:48:09 ip-10-10-3-149.ec2.internal sudo[4019]: pam_unix(sudo:session): session closed for user r

I have tried also the solution in here. I am not sure what else I can try.

UPDATE: this is how my jenkins unit looks like (systemctl cat jenkins):

# /etc/systemd/system/jenkins.service
[Service]
Environment="JENKINS_PORT=8000"

# /etc/systemd/system/jenkins.service.d/override.conf
[Service]
Environment="JENKINS_PORT=8000"

CodePudding user response:

According to the logs, the unit file is missing start and stop scripts which can be confirmed by
systemctl cat jenkins.
According to Jenkins docs, the systemd file needed changes.Copying and overriding the unit file with the one given in the docs can solve the problem.

  • Related