Jenkins is not running when the jenkins.war is not running

Viewed 1154

I am trying to auto schedule a Jenkins job for a selenium/maven project I am working on. Everything is running properly and auto scheduling works only if the .jar file is running (using the command:java -jar jenkins.war --httpPort=8089). But once I exit out of the command prompt and the Jenkins server it doesn't run at all. I was under the assumption that it should run regardless of being connected or not and the computer being logged in or logged out.

It looks to me like Jenkins Autoscheduling not working when the jenkins.war file is not up and running.

Am I missing something here?

1 Answers

The whole jenkins process is not running if the .war file is not being executed. The problem is how you run Jenkins.

There is extensive documentation how to run it. However, I end up running on a systemd enabled OS (linux) by having a system.d service file: /usr/lib/systemd/system/jenkins.service:

[Unit]
Description=Jenkins
Documentation=https://wiki.jenkins.io/display/JENKINS/Use+Jenkins
After=network.target
Requires=network.target

[Service]
Type=simple
EnvironmentFile=/etc/default/jenkins
ExecStart=/home/jenkins/jdk/jdk1.8.0_121/bin/java -Xmx2048m -Xms1024m -DJENKINS_HOME=/home/jenkins -jar /home/jenkins/jenkins.war --javaHome=/home/jenkins/jdk/jdk1.8.0_121 --httpPort=8080 --webroot=/var/cache/jenkins/war --ajp13Port=-1 --debug=5 --handlerCountMax=100 --handlerCountMaxIdle=20
# Restart=always
# RestartSec=120
User=jenkins

[Install]
WantedBy=multi-user.target

with: /etc/default/jenkins:

# Managed manually
JENKINS_HOME="/home/jenkins"
#JENKINS_LOGFILE="/home/jenkins/jenkins.log"

# TODO: manage JAVA_HOME through java-alternatives
JAVA_HOME="/home/jenkins/jdk/jdk1.8.0_121"
JAVA_OPTIONS="-Xmx2048m -Xms1024m"

# Web Configuration
HTTP_WEB_ROOT="/var/cache/jenkins/war"
HTTP_PORT="8080"
HTTP_LISTEN_ADDRESS="0.0.0.0"

# Jenkins Configurations
#   more: https://wiki.jenkins.io/display/JENKINS/Starting+and+Accessing+Jenkins
JENKINS_ARGS="--ajp13Port=-1 --debug=5 --handlerCountMax=100 --handlerCountMaxIdle=20"
$ systemctl status jenkins
● jenkins.service - Jenkins
   Loaded: loaded (/usr/lib/systemd/system/jenkins.service; linked; vendor preset: disabled)
   Active: active (running) since Wed 2021-03-31 10:08:36 EDT; 1 weeks 1 days ago
     Docs: https://wiki.jenkins.io/display/JENKINS/Use+Jenkins
 Main PID: 27219 (java)
    Tasks: 70 (limit: 512)
   CGroup: /system.slice/jenkins.service
           └─27219 /home/jenkins/jdk/jdk1.8.0_121/bin/java -Xmx2048m -Xms1024m

And publish it through Apache HTTP Server, through ProxyPath :

$ systemctl status apache
● apache2.service - The Apache Webserver
   Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-02-02 12:34:05 EST; 2 months 4 days ago
  Process: 30426 ExecReload=/usr/sbin/start_apache2 -DSYSTEMD -DFOREGROUND -k graceful (code=exited, status=0/SUCCESS)
 Main PID: 18524 (httpd-prefork)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
    Tasks: 11
   CGroup: /system.slice/apache2.service

with the Apache HTTP virtual host configuration:

<IfDefine SSL>
<IfDefine !NOSSL>

##
## SSL Virtual Host Context
##

<VirtualHost _default_:443>

  ProxyPass         /  http://localhost:8080/ nocanon
  ProxyPassReverse  /  http://localhost:8080/

  # ProxyRequests     Off
  ProxyPreserveHost On
  AllowEncodedSlashes NoDecode

  <Proxy http://localhost:8080/*>
    Require all granted
  </Proxy>

  # ProxyPassMatch  ^/(?\!.well-known)  http://localhost:8080 nocanon

  ErrorLog /var/log/apache2/error_log
  TransferLog /var/log/apache2/access_log

  #   SSL Engine Switch:
  #   Enable/Disable SSL for this virtual host.
  SSLEngine on

  #   You can use per vhost certificates if SNI is supported.
  SSLCertificateFile /etc/apache2/ssl.crt/<your-server>.com.crt
  SSLCertificateKeyFile /etc/apache2/ssl.key/<your-server>.com.key

  CustomLog /var/log/apache2/ssl_request_log   ssl_combined

</VirtualHost>

</IfDefine>
</IfDefine>

The same configuration setup, but through NGINX: Jenkins reverse-proxy configuration nginx

In this way, you can manage your jenkins server (start/stop) and manage TLS (SSL) comunication:

systemctl status jenkins nginx

If you run Jenkins through Docker, you don't need another WebServer (e.g. Apache/NGINX) in front of Jenkins as publicly, you're not going to expose the Jenkins Docker container, but you probably have a Kubernetes/(A)LB in front. It is not advised to publicly expose Jenkins.

The WebServer gives you the flexibility to use caching or CDN in front of your Jenkins especially if you make use of Publish artifacts functionality.

Related