Jenkins systemd service file

This is a small snippet to run Jenkins via systemd service unit and not via the included init.d file (which systemd need to auto-generate a unit for it).


Copy the file into `/etc/systemd/system/jenkins.service` and run `systemctl daemon-reload`

# /etc/systemd/system/jenkins.service
[Unit]
Description=Standalone Jenkins Master server
Documentation=https://www.jenkins.io/doc

Wants=network-online.target
After=network-online.target

[Service]
User=jenkins
Group=jenkins
Environment=HTTP_PORT=8080
Environment=JAVA_ARGS=-Djava.awt.headless=true
Environment=JENKINS_HOME=/var/lib/jenkins
Environment=JENKINS_WAR=/usr/lib/jenkins/jenkins.war
Environment=LISTEN_ADDRESS=127.0.0.1
Environment=WEBROOT=/var/cache/jenkins/war
WorkingDirectory=/var/lib/jenkins
LimitNOFILE=8192
ExecStart=/usr/bin/java ${JAVA_ARGS} -jar ${JENKINS_WAR} --webroot=${WEBROOT} --httpPort=${HTTP_PORT} --httpListenAddress=${LISTEN_ADDRESS}

[Install]
WantedBy=multi-user.target

Note:

Just in case there are left over from the old jenkins service, run disable & enable to recreate the link

sudo systemctl disable jenkins
sudo systemctl enable jenkins

Resources

Leave a Reply

Your email address will not be published.