Last active
December 10, 2015 15:20
-
-
Save rhwood/4136130 to your computer and use it in GitHub Desktop.
OS X LaunchDaemon for a Jenkins Java Web Start slave. This is now maintained at https://github.com/rhwood/jenkins-slave-osx Please refer to that version instead.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# create jenkins group | |
NEXT_GID=$((`dscl /Local/Default list /Groups gid | awk '{ print $2 }' | sort -n | grep -v ^[5-9] | tail -n1` + 1)) | |
sudo dscl /Local/Default create /Groups/jenkins | |
sudo dscl /Local/Default create /Groups/jenkins PrimaryGroupID $NEXT_GID | |
sudo dscl /Local/Default create /Groups/jenkins Password \* | |
sudo dscl /Local/Default create /Groups/jenkins RealName 'Jenkins Node Service' | |
# create jenkins user | |
NEXT_UID=$((`dscl /Local/Default list /Users uid | awk '{ print $2 }' | sort -n | grep -v ^[5-9] | tail -n1` + 1)) | |
sudo dscl /Local/Default create /Users/jenkins | |
sudo dscl /Local/Default create /Users/jenkins UniqueID $NEXT_UID | |
sudo dscl /Local/Default create /Users/jenkins PrimaryGroupID $NEXT_GID | |
sudo dscl /Local/Default create /Users/jenkins UserShell /usr/bin/false | |
sudo dscl /Local/Default create /Users/jenkins NFSHomeDirectory /var/lib/jenkins | |
sudo dscl /Local/Default create /Users/jenkins Password \* | |
sudo dseditgroup -o edit -a jenkins -t user jenkins | |
# download the LaunchDaemon | |
sudo curl --url https://raw.github.com/gist/4136130/d3c9d7275ce78e050d8594037a2d509652a766e5/org.jenkins-ci.slave.jnlp.plist -o /Library/LaunchDaemons/org.jenkins-ci.slave.jnlp.plist | |
# create the jenkins home dir | |
sudo mkdir /var/lib/jenkins | |
# download the jenkins JNLP slave script | |
sudo curl --url https://raw.github.com/gist/4136130/2553c4cec9bc7ed5557359a22c6c1b61028afa40/slave.jnlp.sh -o /var/lib/jenkins/slave.jnlp.sh | |
sudo chown -R jenkins:wheel /var/lib/jenkins | |
sudo chmod 755 /var/lib/jenkins/slave.jnlp.sh | |
# create a logging space | |
sudo mkdir /var/log/jenkins | |
sudo chown jenkins:wheel /var/log/jenkins | |
# remember to edit the LaunchDaemon | |
echo "IMPORTANT:" | |
echo "edit /Library/LaunchDaemons/org.jenkins-ci.slave.jnlp.plist to use the correct master" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>org.jenkins-ci.slave.jnlp</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/var/lib/jenkins/slave.jnlp.sh</string> | |
<string>--master=http://jenkins.example.com</string> | |
</array> | |
<key>KeepAlive</key> | |
<true/> | |
<key>RunAtLoad</key> | |
<true/> | |
<key>UserName</key> | |
<string>jenkins</string> | |
<key>WorkingDirectory</key> | |
<string>/var/lib/jenkins</string> | |
<key>StandardInPath</key> | |
<string>/dev/null</string> | |
<key>StandardErrorPath</key> | |
<string>/var/log/jenkins/jenkins.log</string> | |
<key>StandardOutPath</key> | |
<string>/var/log/jenkins/jenkins.log</string> | |
</dict> | |
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
JENKINS_SLAVE=`hostname -s | tr '[:upper:]' '[:lower:]'` | |
JENKINS_MASTER=http://jenkins | |
JENKINS_PORT='' | |
if [ -f /etc/jenkins.node.conf ]; then | |
source /etc/jenkins.node.conf | |
fi | |
while [ $# -gt 0 ]; do | |
case $1 in | |
--node=*) | |
JENKINS_SLAVE=${1#*=} | |
;; | |
--master=*) | |
JENKINS_MASTER=${1#*=} | |
;; | |
--jnlp-port=*) | |
JENKINS_PORT=":${1#*=}" | |
;; | |
esac | |
shift | |
done | |
echo "Getting slave.jar from ${JENKINS_MASTER}" | |
RESULT=-1 | |
while [ $RESULT -ne 0 ]; do | |
curl --url ${JENKINS_MASTER}/jnlpJars/slave.jar -o /var/lib/jenkins/slave.jar | |
RESULT=$? | |
if [ $RESULT -ne 0 ]; then | |
sleep 10 | |
fi | |
done | |
JENKINS_JNLP_URL=${JENKINS_MASTER}${JENKINS_PORT}/computer/${JENKINS_SLAVE}/slave-agent.jnlp | |
echo "Launching slave process at ${JENKINS_JNLP_URL}" | |
java -jar /var/lib/jenkins/slave.jar -jnlpUrl ${JENKINS_JNLP_URL} |
This script works for Jenkins versions prior to version 1.498 (see JENKINS-16273).
I am now maintaining a more complete version of this work at https://github.com/rhwood/jenkins-slave-osx Please use that version instead.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are two variables that can be passed as strings in the ProgramArguments array:
ping jenkins
does not work).Alternately, these two variables can be set in /etc/jenkins.node.conf as JENKINS_SLAVE and JENKINS_MASTER respectively.