Last active
April 8, 2019 22:06
-
-
Save dbishop/bf0faca2e962038b92158d3e9eb94df8 to your computer and use it in GitHub Desktop.
Jenkins Systemd party time
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
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 |
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
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 |
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
[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 |
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
# 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