2

I have installed and configured jenkins on the centos 7.I have added valid java path i.e "/usr/bin/java" in the file /etc/init.d/jenkins.

Below are the java path detils:

lrwxrwxrwx. 1 root root 22 Dec 24  2015 java -> /etc/alternatives/java

Now, on running "service jenkins start" command from root user, I am getting below error.

● jenkins.service - LSB: Jenkins Continuous Integration Server
   Loaded: loaded (/etc/rc.d/init.d/jenkins)
   Active: failed (Result: exit-code) since Wed 2016-07-13 18:25:51 IST; 5s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 807 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=1/FAILURE)

Jul 13 18:25:51 localhost systemd[1]: Starting LSB: Jenkins Continuous Integration Server...
Jul 13 18:25:51 localhost runuser[812]: pam_unix(runuser:session): session opened for user jenkins by (uid=0)
Jul 13 18:25:51 localhost jenkins[807]: Starting Jenkins bash: /usr/bin/java: Permission denied
Jul 13 18:25:51 localhost runuser[812]: pam_unix(runuser:session): session closed for user jenkins
Jul 13 18:25:51 localhost jenkins[807]: [FAILED]
Jul 13 18:25:51 localhost systemd[1]: jenkins.service: control process exited, code=exited status=1
Jul 13 18:25:51 localhost systemd[1]: Failed to start LSB: Jenkins Continuous Integration Server.
Jul 13 18:25:51 localhost systemd[1]: Unit jenkins.service entered failed state.
Jul 13 18:25:51 localhost systemd[1]: jenkins.service failed.

I am not able to figure out why it's giving me permission denied even though every user having access to the java path.

also on running "journalctl -xe" command it shows below log:

Jul 13 18:45:33 localhost systemd[1]: Unit jenkins.service entered failed state.
Jul 13 18:45:33 localhost systemd[1]: jenkins.service failed.
Jul 13 18:45:33 localhost polkitd[20151]: Unregistered Authentication Agent for unix-process:27889:3161602 (system bus name :1.303, object path /org/freedesktop/PolicyKit1/AuthenticationAgen

Is it like that the Jenkins service does't having permission to access the java path? if not why it's giving that error?

Abhinandan Satpute
  • 2,558
  • 6
  • 25
  • 43
  • 1
    In jenkins.service unit file, owner of service may be defined as jenkins. despite of running as root, service tries to run with jenkins user. You can try to change `User=root` in service unit file. – sozkul Jul 13 '16 at 13:29
  • It worked like champ. – Abhinandan Satpute Jul 13 '16 at 13:35
  • 1
    Ok, but it is a better way to give permission to jenkins user. So check `/etc/alternatives/java` symbol link, find orginal java path. Check permissions. – sozkul Jul 13 '16 at 13:36
  • Yes.Will do it.I suggest you to write it as a answer so that it will help other people out there. – Abhinandan Satpute Jul 13 '16 at 13:41

4 Answers4

7

You have two options to solve the problem.

  1. Jenkins service is started by jenkins user. The error says that jenkins user does not have permission to run java. So check orginal java path and give execute permissions to other users.
  2. In jenkins.service unit file, change the owner of the service. Replace User=jenkins with User=root
sozkul
  • 665
  • 4
  • 10
2

The default user of service jenkins is "jenkins". So "jenkins" may not have the pemission to access service "java". So we need to change the use of service jenkins. From the jenkins service boost script "/etc/init.d/jenkins". We can get the config file path, such as "/etc/sysconfig/jenkins"

乔桑宁
  • 21
  • 2
0

Try changing the file, /etc/init.d/jenkins Specifically look for the JENKINS_USER key and try replacing jenkins with root.

This worked for me on RHEL.

Guru
  • 2,739
  • 1
  • 25
  • 27
0

Now Jenkins are running on java11 so you have to perform two steps.

1 - install java11

yum install java-11-openjdk-devel

2 - run the blow command to select the default JAVA 11 (if you have multiple version)

update-alternatives --config java -- and select 2

this will update the default JAVA to java11 and then systemctl start jenkins

Atul
  • 3
  • 2
  • This doesn't answer the OP question. How does the java version lead to the error given? – Aaron Newman May 24 '23 at 15:12
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 24 '23 at 15:13