Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'am trying to start the jenkins' slave.jar on a Mac OS X 10.8.3 using a Launch Daemon so that it runs right after the machine is started.

But I'm experiencing a mysterious problem: The LaunchDaemon starts the slave as i can see in the log files

29.04.2013 14:57:06 hudson.remoting.jnlp.Main$CuiListener status
INFO: Locating server among [http://ci.****/]
29.04.2013 14:57:06 hudson.remoting.jnlp.Main$CuiListener status
INFO: Connecting to ci.****:53930
29.04.2013 14:57:06 hudson.remoting.jnlp.Main$CuiListener status
INFO: Handshaking
29.04.2013 14:57:06 hudson.remoting.jnlp.Main$CuiListener status
INFO: Connected

But the connection is closed right after that:

29.04.2013 14:57:06 hudson.remoting.SynchronousCommandTransport$ReaderThread run
SCHWERWIEGEND: I/O error in channel channel
java.io.IOException: Unexpected termination of the channel
    at hudson.remoting.SynchronousCommandTransport$ReaderThread.run(SynchronousCommandTransport.java:50)
Caused by: java.io.EOFException
    at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2576)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1295)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:349)
    at hudson.remoting.Command.readFrom(Command.java:92)
    at hudson.remoting.ClassicCommandTransport.read(ClassicCommandTransport.java:59)
    at hudson.remoting.SynchronousCommandTransport$ReaderThread.run(SynchronousCommandTransport.java:48)
29.04.2013 14:57:06 hudson.remoting.jnlp.Main$CuiListener status
INFO: Terminated

Here i found a solution to this problem - adding sudo as first command.

This works when i run it by myself in Terminal OR when i manually stop & start the LaunchDaemon via launchctl. It sounds stupid - running a command which is executed via sudo but it works in this case. BUT it doesn't work when system starts manually. Any idea? Here's my LaunchDaemon.plist file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.example.ci</string>
    <key>ProgramArguments</key>
    <array>
        <string>sudo</string>
        <string>/usr/bin/java</string>
        <string>-jar</string>
        <string>/Developer/jenkins/slave.jar</string>
        <string>-jnlpUrl</string>
        <string>http://ci.****/computer/****/slave-agent.jnlp</string>
        <string>-jnlpCredentials</string>
        <string>user:apitoken</string>
    </array>
    <key>KeepAlive</key>
    <true/>
    <key>StandardOutPath</key>
    <string>/Developer/jenkins/stdout.log</string>
    <key>StandardErrorPath</key>
    <string>/Developer/jenkins/error.log</string>
</dict>
</plist>
share|improve this question
    
You probably need to set the working directory for this command, as this is used as Jenkins home on the slave IIRC. Running a build slave as root is a really bad idea. FYI newer versions of Jenkins (~LTS 1,480) also have a separate slave token per slave, so you don't have to use a user's API token anymore. – Daniel Beck Apr 30 '13 at 8:05
    
FWIW You should be able to SSH into OS X if you enable remote access in system preferences, so you can control the connection from Jenkins. – Daniel Beck Apr 30 '13 at 10:26
    
Yeah, but the system is connected to an Active Directory. And i can't apply my AD credentials to jenkins system. But i guess i found a solution. I will check it and post it later if it works... – mr.VVoo Apr 30 '13 at 10:33
    
SSH authentication using keys would be an option, so you wouldn't need to provide a password in Jenkins. – Daniel Beck Apr 30 '13 at 10:33
    
But my key. So everyone else who has access to this jenkins will have also this posibility and unfortunately the whole company has access to administer jenkins. – mr.VVoo Apr 30 '13 at 12:29
up vote 5 down vote accepted

The problem is, that the jenkins slave tries to start some UI but this is - of course - not allowed. I found the same error which is related to an official Bug Report: https://issues.jenkins-ci.org/browse/JENKINS-15697

The solution is in this case to add -Djava.awt.headless=true to JVM options which leads to the following configuration of a LaunchDaemon.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.example.ci</string>
    <key>ProgramArguments</key>
    <array>
        <string>sudo</string>
        <string>/usr/bin/java</string>
        <string>-Djava.awt.headless=true</string>
        <string>-jar</string>
        <string>/Developer/jenkins/slave.jar</string>
        <string>-jnlpUrl</string>
        <string>http://ci.****/computer/****/slave-agent.jnlp</string>
        <string>-jnlpCredentials</string>
        <string>user:apitoken</string>
    </array>
    <key>KeepAlive</key>
    <true/>
    <key>StandardOutPath</key>
    <string>/Developer/jenkins/stdout.log</string>
    <key>StandardErrorPath</key>
    <string>/Developer/jenkins/error.log</string>
</dict>
</plist>

I've tested this and it works.

share|improve this answer
    
Hi, is it possible to run the slave without 'sudo', as a normal user? – karim Jul 2 '13 at 12:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .