Managing systemd services

Beginning with Jenkins 2.332.1 and Jenkins 2.335, the Linux package installers use systemd to manage services. The RPM and deb package installers migrate configuration settings from System V init to systemd overrides.

Viewing service configurations

The current service configuration of the Jenkins service as configured by the package installers and any overrides can be viewed with:

$ systemctl cat jenkins
# /etc/systemd/system/jenkins.service
#
# This file is managed by systemd(1). Do NOT edit this file manually!
# To override these settings, run:
#
#     systemctl edit jenkins
#
# For more information about drop-in files, see:
#
#     https://www.freedesktop.org/software/systemd/man/systemd.unit.html
#

[Unit]
Description=Jenkins Continuous Integration Server
Requires=network.target
After=network.target

[Service]
Type=notify
NotifyAccess=main
ExecStart=/usr/bin/jenkins
Restart=on-failure
SuccessExitStatus=143

# /etc/systemd/system/jenkins.service.d/override.conf
[Service]
Environment="JAVA_OPTS=-Djava.awt.headless=true"

Overriding service configurations

Default service configuration settings are stored in /etc/systemd/system/jenkins.service. Values may be overridden in the override.conf file for the service. Edit the override file with the command:

$ systemctl edit jenkins

The override.conf file is stored at /etc/systemd/system/jenkins.service.d/override.conf and can be used to customize the service. Example content of the override.conf file might include

[Unit]
Description=My Company Jenkins Controller

[Service]

# Add JVM configuration options
Environment="JAVA_OPTS=-Djava.awt.headless=true -XX:+UseStringDeduplication"

# Arbitrary additional arguments to pass to Jenkins.
# Full option list: java -jar jenkins.war --help
Environment="JENKINS_OPTS=--prefix=/jenkins --javaHome=/opt/jdk-11"

# Configuration as code directory
Environment="CASC_JENKINS_CONFIG=/var/lib/jenkins/configuration-as-code/"

Starting services

Once the Jenkins systemd service has been defined, it can be started with:

$ systemctl start jenkins

Stopping services

The Jenkins systemd service can be stopped with:

$ systemctl stop jenkins

Reloading service definitions

After changes to configuration files, the service definition may need to be reloaaded with:

$ systemctl daemon-reload

Reading service logs

Logs for the Jenkins service can be read with the command:

$ journalctl -u jenkins

Pruning service logs

Log files retained by systemd are commonly configured to automatically rotate. If the log files need to be reduced in size, use the command:

$ journalctl --vacuum-size=500M

Going further

Some recommended readings on this subject:



Was this page helpful?

Please submit your feedback about this page through this quick form.

Alternatively, if you don't wish to complete the quick form, you can simply indicate if you found this page helpful?

    


See existing feedback here.