10

I'm running Jenkins on Ubuntu 20.04 LTS and I want to change the port or the user Jenkins runs as but changes to the /etc/default/jenkins file do not change the port after restarting the service.

The service still starts as:

/usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080

While the /etc/default/jenkins file reads:

[...]
# port for HTTP connector (default 8080; disable with -1)
HTTP_PORT=8081


# servlet context, important if you want to use apache proxying
PREFIX=/$NAME

# arguments to pass to jenkins.
# full list available from java -jar jenkins.war --help
# --javaHome=$JAVA_HOME
# --httpListenAddress=$HTTP_HOST (default 0.0.0.0)
# --httpPort=$HTTP_PORT (default 8080; disable with -1)
# --httpsPort=$HTTP_PORT
# --argumentsRealm.passwd.$ADMIN_USER=[password]
# --argumentsRealm.roles.$ADMIN_USER=admin
# --webroot=~/.jenkins/war
# --prefix=$PREFIX

JENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=$HTTP_PORT"

I've checked two different Ubuntu 20.04 LTS machines and both have the same problem. Anyone have an idea what I'm doing wrong?

checkmate9
  • 103
  • 1
  • 4

3 Answers3

24

after jenkins 2.332.1.. the /etc/default/jenkins is no longer used. jenkins is now configured with systemd. you can check systemctl cat jenkins to see the options and systemctl edit jenkins to modify it..

you can change the port.

[Service]
Environment="JENKINS_PORT=8081"

updated java memory and java args Environment="JENKINS_OPTS="

Environment="JENKINS_OPTS=-Xmx2048m"
Priit
  • 173
  • 1
  • 4
Jihed Hmida
  • 256
  • 1
  • 4
  • 3
    Watch out, it should be `[SERVICE]` breakline `Environment="JENKINS_PORT=8081"` – Fyruz Apr 08 '22 at 16:16
  • 8
    Would have been helpful if a comment had been added to /etc/default/jenkins, rather than just silently breaking what people were used to on an update :-( – Michael Firth Apr 19 '22 at 09:54
  • More details can be found in the official documentation: https://www.jenkins.io/doc/book/system-administration/systemd-services/ – Attila Csipak Jul 08 '22 at 10:06
  • So wait, my changes that were in `/etc/default/jenkins` are still being honored after upgrading to 2.332.1 however on _new_ installs the `/etc/default/jenkins` changes are not honored. What happened here? – Rino Bino Jul 19 '22 at 18:01
  • @RinoBino jenkins 2.332.1+ LTS package installation migrates customized settings to systemd. After migration, the System V init config (`/etc/default/jenkins` on Debian) is ignored. See https://www.jenkins.io/blog/2022/03/25/systemd-migration/. – Dima Korobskiy Oct 23 '22 at 03:09
  • @DimaKorobskiy Thanks, yea I had understood that it no longer uses /etc/default/jenkins but I was confused on how an upgrade from an older version honored my custom settings from that file. Deeper investigation found that the package upgrade process through apt will copy settings to the systemd unit configurations automatically. That's how the existing custom settings were being honored on upgraded systems. – Rino Bino Oct 24 '22 at 16:22
  • I feel like this wasn't a JENKINS_OPTS but a JAVA_OPT and needed to be this to be applied: `Environment="JAVA_OPTS=-Djava.awt.headless=true -Xmx2048m -XX:MaxPermSize=512m"`. Jenkins would still use a ton of memory otherwise and it didn't give an error passing `-Xmx` but it wouldn't start passing the `-XX:MaxPermSize`. – jonespm Feb 04 '23 at 00:23
1

Update /etc/systemd/system/jenkins.service.d/override.conf and run systemctl daemon-reload

kundan
  • 1,278
  • 14
  • 27
0

Same problem here. Today I've just upgraded jenkins to v2.332.1 (on Ubuntu 20.04.1 LTS), I've slightly modified /etc/default/jenkins - updated java memory and java args:

...
# arguments to pass to java
JAVA_MEMORY="-Xmx2048m"

# Allow graphs etc. to work even when an X server is present
JAVA_ARGS="${JAVA_MEMORY} -Djava.awt.headless=true -Dhudson.model.DirectoryBrowserSupport.CSP=\"sandbox allow-scripts allow-same-origin; default-src 'none'; img-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self'; font-src 'self'; media-src 'self'\""
...

But after restarting the service using "systemctl restart jenkins", it does not use the new args. It seems that the /etc/default/jenkins is just ignored

jenkins  1774584       1 42 19:07 ?        00:07:14 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080
dnzm.fr
  • 1
  • 2
  • 1
    I just found this bug, which could be related to my issue: https://issues.jenkins.io/browse/JENKINS-67724 – dnzm.fr Mar 16 '22 at 18:56