Skip to content

Instantly share code, notes, and snippets.

@dbishop
Last active April 8, 2019 22:06
Show Gist options
  • Save dbishop/bf0faca2e962038b92158d3e9eb94df8 to your computer and use it in GitHub Desktop.
Save dbishop/bf0faca2e962038b92158d3e9eb94df8 to your computer and use it in GitHub Desktop.
Jenkins Systemd party time
env SLAVE="coachman02"
env JTYPE="light-jobs"
env SECRET="1292eddf31b08baad457d2c781cd109f34fd2f2912808224fa2ed8542290a162"
description "Jenkins Slave (for $JTYPE)"
author "Leah Klearman <[email protected]>"
start on (local-filesystems and net-device-up IFACE!=lo)
stop on runlevel [016]
respawn
pre-start script
mkdir -p /var/lib/jenkins/${JTYPE}/log
cp /var/lib/jenkins/slave.jar /var/lib/jenkins/${JTYPE}/
chown -R jenkins:jenkins /var/lib/jenkins/${JTYPE}/
end script
exec su -s /bin/bash -c "cd /var/lib/jenkins/${JTYPE}; java -Dhudson.util.ProcessTree.disable=true -jar slave.jar -jnlpUrl https://carson.swiftstack.com/computer/${SLAVE}-${JTYPE}/slave-agent.jnlp -secret $SECRET -auth service:eYaclsG3hLZnsXc >> /var/lib/jenkins/${JTYPE}/log/slave.log 2>&1" jenkins
You put the service file in `/lib/systemd/system/`
On each server, for each slave name, create a file named
/var/lib/jenkins/SLAVENAME.env
and edit it to have right SLAVE and SECRET values.
Then make one symlink like this for each slave name (e.g. "light-jobs" or "medium-jobs" or "tasks":
ln -s /lib/systemd/system/[email protected] /etc/systemd/system/multi-user.target.wants/[email protected]
e.g.
ln -s /lib/systemd/system/[email protected] /etc/systemd/system/multi-user.target.wants/[email protected]
Then they'll start on boot. To start by hand: systemctl start jenkins-slave@light-jobs
[Unit]
Description=Jenkins Slave for %i
Requires=local-fs.target network.target network-online.target
After=local-fs.target network.target network-online.target
[Service]
EnvironmentFile=/var/lib/jenkins/%i.env
ExecStartPre=/bin/mkdir -p /var/lib/jenkins/%i/log
ExecStartPre=/bin/cp /var/lib/jenkins/slave.jar /var/lib/jenkins/%i/
ExecStartPre=/bin/chown -R jenkins:jenkins /var/lib/jenkins/%i/
ExecStart=/bin/su -s /bin/bash -c "cd /var/lib/jenkins/%i; java -Dhudson.util.ProcessTree.disable=true -jar ../slave.jar -jnlpUrl https://carson.swiftstack.com/computer/${SLAVE}-%i/slave-agent.jnlp -secret $SECRET -auth service:eYaclsG3hLZnsXc >> /var/lib/jenkins/%i/log/slave.log 2>&1" jenkins
Restart=always
RestartSec=10
StartLimitInterval=61s
[Install]
WantedBy=multi-user.target
# Put me in /var/lib/jenkins/light-jobs.env
SLAVE=coachman02
SECRET=1292eddf31b08baad457d2c781cd109f34fd2f2912808224fa2ed8542290a162
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment