Newly installed Jenkins 2.387 with java-11, jenkins service failed to start

I have GitLab installed on same server which is using port “8080”, can I change port to 9090 to this /usr/lib/systemd/system/jenkins.service file ?

Port to listen on for HTTP requests. Set to -1 to disable.

To be able to listen on privileged ports (port numbers less than 1024),

add the CAP_NET_BIND_SERVICE capability to the AmbientCapabilities

directive below.

Environment=“JENKINS_PORT=9090”

Is there any other jenkins configuration files need to update port ? Thank you for the help

:/usr/lib/systemd/system>sudo service jenkins start
Starting jenkins (via systemctl): Warning: jenkins.service changed on disk. Run ‘systemctl daemon-reload’ to reload units.
Job for jenkins.service failed because the control process exited with error code. See “systemctl status jenkins.service” and “journalctl -xe” for details.
[FAILED]
:/usr/lib/systemd/system>sudo journalctl -u jenkins.service -e -n 100
May 16 15:41:56 mcdasatest07 jenkins[21769]: at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:304)
May 16 15:41:56 mcdasatest07 jenkins[21769]: at org.eclipse.jetty.server.Server.lambda$doStart$0(Server.java:402)
May 16 15:41:56 mcdasatest07 jenkins[21769]: at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
May 16 15:41:56 mcdasatest07 jenkins[21769]: at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
May 16 15:41:56 mcdasatest07 jenkins[21769]: at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
May 16 15:41:56 mcdasatest07 jenkins[21769]: at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
May 16 15:41:56 mcdasatest07 jenkins[21769]: at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
May 16 15:41:56 mcdasatest07 jenkins[21769]: at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
May 16 15:41:56 mcdasatest07 jenkins[21769]: at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
May 16 15:41:56 mcdasatest07 jenkins[21769]: at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
May 16 15:41:56 mcdasatest07 jenkins[21769]: at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
May 16 15:41:56 mcdasatest07 jenkins[21769]: at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
May 16 15:41:56 mcdasatest07 jenkins[21769]: at org.eclipse.jetty.server.Server.doStart(Server.java:398)
May 16 15:41:56 mcdasatest07 jenkins[21769]: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:93)
May 16 15:41:56 mcdasatest07 jenkins[21769]: at winstone.Launcher.(Launcher.java:168)
May 16 15:41:56 mcdasatest07 jenkins[21769]: Caused: java.io.IOException: Failed to start Jetty
May 16 15:41:56 mcdasatest07 jenkins[21769]: at winstone.Launcher.(Launcher.java:172)
May 16 15:41:56 mcdasatest07 jenkins[21769]: at winstone.Launcher.main(Launcher.java:390)
May 16 15:41:56 mcdasatest07 jenkins[21769]: at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
May 16 15:41:56 mcdasatest07 jenkins[21769]: at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
May 16 15:41:56 mcdasatest07 jenkins[21769]: at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43
May 16 15:41:56 mcdasatest07 jenkins[21769]: at java.base/java.lang.reflect.Method.invoke(Method.java:566)
May 16 15:41:56 mcdasatest07 jenkins[21769]: at executable.Main.main(Main.java:347)
May 16 15:41:56 mcdasatest07 systemd[1]: jenkins.service: main process exited, code=exited, status=1/FAILURE
May 16 15:41:56 mcdasatest07 systemd[1]: Failed to start My Company Jenkins Controller.
May 16 15:41:56 mcdasatest07 systemd[1]: Unit jenkins.service entered failed state.
May 16 15:41:56 mcdasatest07 systemd[1]: jenkins.service failed.
May 16 15:41:57 mcdasatest07 systemd[1]: jenkins.service holdoff time over, scheduling restart.
May 16 15:41:57 mcdasatest07 systemd[1]: Stopped My Company Jenkins Controller.
May 16 15:41:57 mcdasatest07 systemd[1]: Starting My Company Jenkins Controller…
May 16 15:41:58 mcdasatest07 jenkins[22044]: Running from: /usr/share/java/jenkins.war
May 16 15:41:59 mcdasatest07 jenkins[22044]: 2023-05-16 22:41:59.000+0000 [id=1] INFO winstone.Logger#logInternal: Beginning extraction f
May 16 15:41:59 mcdasatest07 jenkins[22044]: 2023-05-16 22:41:59.428+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: jetty-10.0
May 16 15:41:59 mcdasatest07 jenkins[22044]: 2023-05-16 22:41:59.524+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStop: Stopped Ser
May 16 15:41:59 mcdasatest07 jenkins[22044]: 2023-05-16 22:41:59.524+0000 [id=1] INFO winstone.Logger#logInternal: Jetty shutdown success
May 16 15:41:59 mcdasatest07 jenkins[22044]: java.io.IOException: Failed to start Jetty
May 16 15:41:59 mcdasatest07 jenkins[22044]: at winstone.Launcher.(Launcher.java:172)
May 16 15:41:59 mcdasatest07 jenkins[22044]: at winstone.Launcher.main(Launcher.java:390)
May 16 15:41:59 mcdasatest07 jenkins[22044]: at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
May 16 15:41:59 mcdasatest07 jenkins[22044]: at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
May 16 15:41:59 mcdasatest07 jenkins[22044]: at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43
May 16 15:41:59 mcdasatest07 jenkins[22044]: at java.base/java.lang.reflect.Method.invoke(Method.java:566)
May 16 15:41:59 mcdasatest07 jenkins[22044]: at executable.Main.main(Main.java:347)
May 16 15:41:59 mcdasatest07 jenkins[22044]: Caused by: java.io.IOException: Failed to bind to 0.0.0.0/0.0.0.0:8080
May 16 15:41:59 mcdasatest07 jenkins[22044]: at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:344)
May 16 15:41:59 mcdasatest07 jenkins[22044]: at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:304)
May 16 15:41:59 mcdasatest07 jenkins[22044]: at org.eclipse.jetty.server.Server.lambda$doStart$0(Server.java:402)
May 16 15:41:59 mcdasatest07 jenkins[22044]: at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
May 16 15:41:59 mcdasatest07 systemd[1]: jenkins.service: main process exited, code=exited, status=1/FAILURE
May 16 15:41:59 mcdasatest07 systemd[1]: Failed to start My Company Jenkins Controller.
May 16 15:41:59 mcdasatest07 systemd[1]: Unit jenkins.service entered failed state.
May 16 15:41:59 mcdasatest07 systemd[1]: jenkins.service failed.
May 16 15:41:59 mcdasatest07 systemd[1]: jenkins.service holdoff time over, scheduling restart.
May 16 15:41:59 mcdasatest07 systemd[1]: Stopped My Company Jenkins Controller.
May 16 15:41:59 mcdasatest07 systemd[1]: start request repeated too quickly for jenkins.service
May 16 15:41:59 mcdasatest07 systemd[1]: Failed to start My Company Jenkins Controller.
May 16 15:41:59 mcdasatest07 systemd[1]: Unit jenkins.service entered failed state.
May 16 15:41:59 mcdasatest07 systemd[1]: jenkins.service failed.
lines 44-101/101 (END)

Thank you MarkEWaite.

  1. made change in /usr/lib/systemd/system/jenkins.service: Environment=“JENKINS_PORT=9090”, same failed
  2. Google search asked to make change in /etc/default/jenkins, could find the path, the jenkins file doesn’t exist
  3. Suggested to run command as java -jar jenkins.war --httpPort=‘xyz’, wil it work?

The port Jenkins uses can be changed with systemctl edit jenkins as described in “Overriding service configurations”. It should be changed in the override file that the systemctl edit jenkins command creates.

That file might look like this:

[Unit]
Description=Jenkins on port 9090
[Service]
# Port to listen on for HTTP requests. Set to -1 to disable.
# To be able to listen on privileged ports (port numbers less than 1024),
# add the CAP_NET_BIND_SERVICE capability to the AmbientCapabilities
# directive below.
Environment="JENKINS_PORT=9090"

Note that the [SERVICE] line in the definition is mandatory. Without it, systemd will ignore the settings.

A video is also available that describes how to manage services with systemd.

Thanks for your information. How could I save the file and exit the file after code added?

When systemctl edit jenkins opens, it uses the system configured editor. When the file is saved from that system configured editor, the configuration is saved and systemd reloads the configuration.

If using vi, then the exit command is :wq

When systemctl edit jenkins:

[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=/usr/lib/jvm/java-11-openjdk-11.0.19.0.7-1.el7_9.x86_64”

Configuration as code directory
Environment=“CASC_JENKINS_CONFIG=/var/lib/jenkins/configuration-as-code/”
[Unit]
Description=Jenkins on port 9080
[Service]

Port to listen on for HTTP requests. Set to -1 to disable.
To be able to listen on privileged ports (port numbers less than 1024),
add the CAP_NET_BIND_SERVICE capability to the AmbientCapabilities
directive below.
Environment=“JENKINS_PORT=9080”

after save, run
:/usr/lib/systemd/system>systemctl start Jenkins
Failed to start Jenkins.service: Unit not found.

When systemctl edit jenkins:

[Unit]
Description=Jenkins on port 9080
[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=/usr/lib/jvm/java-11-openjdk-11.0.19.0.7-1.el7_9.x86_64”

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

# Port to listen on for HTTP requests. Set to -1 to disable.
# To be able to listen on privileged ports (port numbers less than 1024),
# add the CAP_NET_BIND_SERVICE capability to the AmbientCapabilities
# directive below.
Environment=“JENKINS_PORT=9080”

after save, run
:/usr/lib/systemd/system>systemctl start Jenkins
Failed to start Jenkins.service: Unit not found.
:/usr/lib/systemd/system>systemctl edit jenkins

  1. made change in /usr/lib/systemd/system/jenkins.service: Environment=“JENKINS_PORT=9090”, failed
  2. Google search asked to make change in /etc/default/jenkins, could find the path
  3. Suggested to run command as java -jar jenkins.war --httpPort=‘xyz’, wil it work? Please advise.

Thank you
Holly

You’ll want to read this guide: Managing systemd services

Thank you for the responding lide_o_mix. I did, made change in /usr/lib/systemd/system/jenkins.service with:

[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/"
```. keeps failing.
got log message as: Caused by: java.io.IOException: Failed to bind to 0.0.0.0/0.0.0.0:8080, we have GitLab using port 8080, I am change another port, but got issue in my first description.

That’s not the correct location to make a change. On my Ubuntu 22 system, the systemd override file that is created by systemctl edit jenkins is in /etc/systemd/system/jenkins.service.d/override.conf. If you use the command systemctl edit jenkins, you’ll have a better experience and will be making the change in the correct file.

When systemctl edit jenkins:

[Unit]
Description=Jenkins on port 9080
[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=/usr/lib/jvm/java-11-openjdk-11.0.19.0.7-1.el7_9.x86_64"

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

# Port to listen on for HTTP requests. Set to -1 to disable.
# To be able to listen on privileged ports (port numbers less than 1024),
# add the CAP_NET_BIND_SERVICE capability to the AmbientCapabilities
# directive below.
Environment="JENKINS_PORT=9080"

after save, run
:/usr/lib/systemd/system>systemctl start Jenkins
Failed to start Jenkins.service: Unit not found.

The command is case sensitive. You need

systemctl start jenkins

Good eye! Thank you for pointing it out. It works. Thanks everyone helped me out. Appreciated your help.

Holly