Skip to content

Instantly share code, notes, and snippets.

@karnauskas
Created October 13, 2014 21:45
Show Gist options
  • Save karnauskas/aca138bb8338689a178e to your computer and use it in GitHub Desktop.
Save karnauskas/aca138bb8338689a178e to your computer and use it in GitHub Desktop.
Jenkins service unit file for Systemd
[Unit]
Description=Jenkins
After=network.target
Requires=network.target
[Service]
Type=simple
EnvironmentFile=/etc/sysconfig/jenkins
ExecStart=/usr/bin/java ${JENKINS_JAVA_OPTIONS} -jar /usr/lib/jenkins/jenkins.war --httpPort=${JENKINS_PORT} --httpListenAddress=${JENKINS_LISTEN_ADDRESS} ${JENKINS_ARGS}
Restart=always
User=jenkins
RestartSec=20
[Install]
WantedBy=multi-user.target
@karnauskas
Copy link
Author

And you think I know what was there 5 years ago? Something like this. You're welcome.

JENKINS_LISTEN_ADDRESS="0.0.0.0"
JENKINS_PORT="3000"
JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Xmx256m" 
JENKINS_ARGS=""

@csaltos
Copy link

csaltos commented Jan 29, 2022

Thank you for the reference !! ... just in case for Jenkins LTS 2.319.2 you can use something like:

/etc/jenkins/jenkins.conf

JENKINS_WAR=/opt/jenkins/jenkins.war

JENKINS_HOME=/opt/jenkins/home

JAVA_ARGS="-Djava.awt.headless=true \
  -Djava.net.preferIPv4Stack=true \
  -XX:+AlwaysPreTouch \
  -XX:+UseG1GC \
  -Xms1024m \
  -Xmx1024m \
  -Xss16m \
  -Xlog:gc*=debug:file=gclog.log:utctime,level,tags:filecount=9,filesize=1M"

JENKINS_ARGS="--httpPort=8080 \
  --logfile=/var/log/jenkins/jenkins.log \
  --useJmx"

/lib/systemd/system/jenkins.service

[Unit]
Description=Jenkins
After=network.target

[Service]
Type=simple
User=jenkins
Group=jenkins
EnvironmentFile=/etc/jenkins/jenkins.conf
ExecStart=/usr/bin/java $JAVA_ARGS -jar $JENKINS_WAR $JENKINS_ARGS
WorkingDirectory=/opt/jenkins/home
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

Ensure you have the jenkins user created with the Jenkins home and logs directory permissions with the Jenkins war downloaded at /opt/jenkins/jenkins.war and just run the command systemctl start jenkins

Tested on Debian 11 Bullseye arm64 and OpenJDK 11 in and AWS m6g.large

Based on:
https://www.jenkins.io/doc/book/managing/system-properties/
https://www.jenkins.io/doc/book/installing/initial-settings/
https://github.com/jenkinsci/winstone#command-line-options

@karnauskas
Copy link
Author

Interesting to see that small piece of config still makes some traction 7 years later.

@basil
Copy link

basil commented Feb 1, 2022

Interesting to see that small piece of config still makes some traction 7 years later.

Because in all these years the Jenkins project still hasn't shipped systemd(1)-based packages. But that is about to change in jenkinsci/packaging#266.

@csaltos
Copy link

csaltos commented Feb 2, 2022

Buenísimo !! 👍😎

@arturocandela
Copy link

Me ha servido mucho, gracias

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment