Jenkins refused to connect on port 8080

Viewed 30717

I have configured Jenkins on an Ubuntu server, everything was working fine for almost 2 months, Jenkins was building jobs and running test cases. But recently I increased the number of test cases on it. After some time it started to refuse connection when I opened up Jenkins through a web browser.

IP:8080 is giving an error "connection refused".

I tried to restart the Jenkins service by:

sudo service jenkins restart

It restarted normally, but still, jenkins was not opening up on the browser.

Then I checked the default settings of jenkins in /etc/default/jenkins:

# defaults for jenkins continuous integration server
# pulled in from the init script; makes things easier.
NAME=jenkins

# location of java
JAVA=/usr/bin/java

# arguments to pass to java
JAVA_ARGS="-Djava.awt.headless=true"  # Allow graphs etc. to work even when an X server is present
JAVA_ARGS="-Xmx1024m"
#JAVA_ARGS="-Djava.net.preferIPv4Stack=true" # make jenkins listen on IPv4 address

PIDFILE=/var/run/$NAME/$NAME.pid

# user and group to be invoked as (default to jenkins)
JENKINS_USER=$NAME
JENKINS_GROUP=$NAME

# location of the jenkins war file
JENKINS_WAR=/usr/share/$NAME/$NAME.war

# jenkins home location
JENKINS_HOME=/var/lib/$NAME

# set this to false if you don't want Hudson to run by itself
# in this set up, you are expected to provide a servlet container
# to host jenkins.
RUN_STANDALONE=true

# log location.  this may be a syslog facility.priority
JENKINS_LOG=/var/log/$NAME/$NAME.log
#JENKINS_LOG=daemon.info

# OS LIMITS SETUP
#   comment this out to observe /etc/security/limits.conf
#   this is on by default because http://github.com/jenkinsci/jenkins/commit/2fb288474e980d0e7ff9c4a3b768874835a3e92e
#   reported that Ubuntu's PAM configuration doesn't include pam_limits.so, and as a result the # of file
#   descriptors are forced to 1024 regardless of /etc/security/limits.conf
MAXOPENFILES=8192

# set the umask to control permission bits of files that Jenkins creates.
#   027 makes files read-only for group and inaccessible for others, which some security sensitive users
#   might consider benefitial, especially if Jenkins runs in a box that's used for multiple purposes.
#   Beware that 027 permission would interfere with sudo scripts that run on the master (JENKINS-25065.)
#
#   Note also that the particularly sensitive part of $JENKINS_HOME (such as credentials) are always
#   written without 'others' access. So the umask values only affect job configuration, build records,
#   that sort of things.
#
#   If commented out, the value from the OS is inherited,  which is normally 022 (as of Ubuntu 12.04,
#   by default umask comes from pam_umask(8) and /etc/login.defs

# UMASK=027

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


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

# arguments to pass to jenkins.
# --javahome=$JAVA_HOME
# --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"

Everthing seems fine in this file and war file is also there on the given location.

When I restarted the server 3-4 times, it started opening up again. But this problem is still coming again and again. I have to restart the server every time to open Jenkins.

Can someone help me in locating this issue and tell how to resolve it.

3 Answers

I received this error while running Jenkins on AWS EC2 and tried to reach it from outside (an instance from internal network in my case).

When I ran curl localhost:8080 from inside the Jenkins server all was fine, but when I did the same from an instance from the internal network I've got the mentioned refused to connect on port 8080 error.

The solution was to vim /etc/sysconfig/jenkins and change:

JENKINS_LISTEN_ADDRESS="127.0.0.1"

To:

JENKINS_LISTEN_ADDRESS="0.0.0.0"

It took me a while to figure this one out. For me, it started happening after changing my Windows password. The solution was to update the Credentials for Jenkins Service.

  1. In Windows search bar, type services then enter.
  2. Then scroll down to Jenkins and double-click on it.
  3. In Jenkins Properties, select tab "Log On".
  4. Select Check box "This account"
  5. Update your username and password.

Voila! Now Jenkins web can connect to the Jenkins machine via Jenkins service.

Related