22

After upgrading my macOS to Sierra, when I start Jenkins using launchctl load I cannot connect to localhost:8080. If I call launchctl load again, I see response "service already loaded". There is no log file at the default location /var/log/jenkins/ (as set in jenkins-ci.plist). I also tried to create jenkins.log there and chown to jenkins user, but still nothing is printed there.

If I try to start Jenkins using java -jar jenkins.war, I can connect to localhost, but Jenkins runs as a new installation.

I have the latest JRE 1.8.0_102 installed.

How to diagnose the problem?

Vladimir Grigorov
  • 10,903
  • 8
  • 60
  • 70

9 Answers9

55

Seems that Sierra changed the permission of Jenkis folder. So the best solution is:
1. Add execute permissions to org.jenkins-ci.plist:
sudo chmod +x /Library/LaunchDaemons/org.jenkins-ci.plist
2. Set jenkins as the owner of /var/log/jenkins:
sudo chown jenkins /var/log/jenkins
3. Start Jenkins:
sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist

mac.slusarek
  • 693
  • 5
  • 7
  • 1
    Nice one. Thanks. One minor thing is you don't need to allow execution for everyone. With allowing it for the owner it's sufficient. So chmod u+x will do the trick. – Mig82 Jan 20 '17 at 00:20
  • nice, this helped. Only thing minor thing was apparently Jenkins was in some "partially running" state, so I first needed to Stop Jenkins with 'unload' (identical to step 3 but with 'unload' instead of 'load), before doing step 3 as described. – kalmiya Feb 06 '17 at 09:55
  • Jenkins not owning the log directory fixed it. – Rool Paap Aug 07 '17 at 14:02
  • This was the right fix for upgrading to High Sierra as well. – nick May 22 '18 at 13:58
  • 4
    This also worked for me after upgrading my MacBook to OSX Mojave! – Rick Slinkman Oct 27 '18 at 14:42
  • 6
    @RickSlinkman, still unable to open the localhost:8080 OSX Mojave. – AsimRazaKhan Dec 03 '18 at 08:17
  • In my case, jenkins wasn't able to create the "jenkins" folder inside /var/log. I had to give access to the parent folder "/var/log" which fixed the issue. – Katana Jan 13 '20 at 16:46
18

This happened to me when I upgraded to Sierra and I managed to solve it with the answer from @mac.slusarek . But it happened again recently. This time I had allowed a minor update of the OS and I had also been playing around with SDK Man to switch JDK's. Not sure which one broke my Jenkins but this time around it was not a permissions issue.

I noticed from the logs Jenkins was trying to run on Java 9-ea, which is apparently not supported yet. I had installed Jenkins using the Jenkins installer for Mac, so tried uninstalling:

/Library/Application\ Support/Jenkins/Uninstall.command

and installing again but the issue didn't go away.

Then I found this article suggesting to instead install it using Homebrew. It was as easy as running:

$brew install jenkins

Since I only run it locally for development I don't need to start it as a daemon, so now I just run it by typing

$jenkins

Problem solved. I hope this helps others.

Mig82
  • 4,856
  • 4
  • 40
  • 63
10

I fixed it by setting the appropriate JAVA_HOME variable. The way I diagnosed it was to look at the errors that were thrown as Jenkins was trying to run:

tail -f /var/log/jenkins/jenkins.log

Then I tried to run it:

sudo launchctl load -w /Library/LaunchDaemons/org.jenkins-ci.plist

If it says it's already loaded, unload it first:

sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist

Then run it:

sudo launchctl load -w /Library/LaunchDaemons/org.jenkins-ci.plist

The error I saw was that Jenkins needed Java 8, not Java 10. So I unloaded:

sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist

and then installed Java 8. Then I edited the plist file:

sudo nano /Library/LaunchDaemons/org.jenkins-ci.plist

and added the appropriate JAVA_HOME environment variable:

<dict>
   <key>JENKINS_HOME</key>
   <string>/Users/Shared/Jenkins/Home</string>
   <key>JAVA_HOME</key>
   <string>/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home</string>
</dict>

Finally, I tried the launchctl command again:

sudo launchctl load -w /Library/LaunchDaemons/org.jenkins-ci.plist

and voilà!

Matt H
  • 6,422
  • 2
  • 28
  • 32
9

I had the same issue, installing the JDK didn't made the trick

However changing the rights of the log directory (in my case /var/log/jenkins) and restarting Jenkins worked.

Seems that moving to Sierra changed the rights on this folder.

Werdeil
  • 101
  • 4
  • 2
    I had this same issue, and @Werdeil is correct. Sierra changed the permissions of the Jenkins log directory (/var/log/jenkins) and that prevented Jenkins from restarting the daemon. So, I modified the permissions of /var/log/jenkins to be group writeable and group executable, and then restarted Jenkins. It's now working. Thanks for this answer - it helped me out a lot. Glad we're all looking out for each other. Cheers. – Coder Roadie Oct 29 '16 at 08:38
9

In my case, the install on Catalina (OSX 10.15) somehow didn't even create the /var/log/jenkins file. I had to

sudo mkdir /var/log/jenkins

and then take ownership and then Jenkins started normally. Just did the normal OSX installer so not sure why the install was corrupt.

Mark Thormann
  • 2,522
  • 1
  • 21
  • 23
  • 1
    This happened to me on both the original install as well as just now updating to Catalina OSX 10.15 Beta 9. Something in the update process seems to be killing or resetting everything in /var/log. Going to report to Apple. – Mark Thormann Sep 26 '19 at 16:25
  • 4
    change ownership of this folder as `chown jenkins /var/log/jenkins` – zangw Mar 02 '20 at 06:28
5

As I mentioned in the question, I had JRE installed. After I installed JDK, Jenkins is able to start normally.

Vladimir Grigorov
  • 10,903
  • 8
  • 60
  • 70
4

This same thing happened to me when I upgraded from Sierra to High Sierra. I followed the instructions outlined above by mac.slusarek, however the jenkins ID no longer existed on my computer. I created the jenkins id as a Standard user. Also, the files under /Users/Shared/Jenkins were no longer owned by jenkins. After I cat out the error log with the command:

sudo cat /var/log/jenkins/jenkins.log

After seeing the error:

Exception in thread "main" java.io.IOException: Jenkins has failed to create a 
temporary file in /Users/Shared/Jenkins/tmp
    at Main.extractFromJar(Main.java:368)
    at Main._main(Main.java:210)
    at Main.main(Main.java:112)
 Caused by: java.io.IOException: Permission denied
    at java.io.UnixFileSystem.createFileExclusively(Native Method)
    at java.io.File.createTempFile(File.java:2024)
    at Main.extractFromJar(Main.java:365)
    ... 2 more

I fixed the ownership with the command:

sudo chown -R jenkins /Users/Shared/Jenkins
Larry Ricker
  • 199
  • 1
  • 7
  • I also lost my jenkins user when I upgraded to High Sierra. I asked another question about that issue: https://stackoverflow.com/questions/47079065/jenkins-user-is-gone-after-macos-update/ – Vladimir Grigorov Nov 21 '17 at 14:51
3

I had the same problem.

I manually enabled the read + write access to the

/Users/Shared/Jenkins 

Folder.

Zumry Mohamed
  • 9,318
  • 5
  • 46
  • 51
3

I was facing issue in loading jenkins-cli.plist command on my MacOs(Mojave version).

Mac Version : Mojave 10.14.6 Jenkins Version : 2.190.1

I installed jenkins using .pkg file.

Reference link : https://java2blog.com/install-jenkins-mac-os-x/

When executing below command,

sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist

I was facing error saying "already loaded".

Solution:

step 1. Check jenkins logs for exact error.

tail -f /var/log/jenkins/jenkins.log

(In my case, it was port binding issue, port 8080 was already being used by some other application)

step 2. So I decided to start jenkins on some other port (say 7070).You can do this by using below commands.

sudo defaults write /Library/Preferences/org.jenkins-ci.plist httpPort 7070

sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist

step 3. Try to access it in browser, http://localhost:7070. It should work!!

Tapan Hegde
  • 1,222
  • 1
  • 8
  • 25