How to restart Jenkins manually?
Asked Answered
S

31

815

I've just started working with Jenkins and have run into a problem. After installing several plugins it said it needs to be restarted and went into a "shutting down" mode, but never restarts.

How do I do a manual restart?

Stratification answered 9/11, 2011 at 22:32 Comment(3)
Note: "Jenkins is Shutting Down" doesn't actually shut down, it just notifies the various users that might want to build something that Jenkins is gonna be restarted soon.Ensnare
Something to note that I didnt notice that anyone else mentioned...If you put Jenkins in shutdown mode it doesnt actually shut down, which has been mentioned. What wasn't noted is that it stops new builds from starting. If you need to let a build complete before you restart you should put Jenkins in shutdown mode, let your build finish, and then do your "restart" with whatever method you choose from above.Lankford
Since version 1.442 Jenkins doesn't require to be restarted after installing new plug-in(s), use “Install without restart”. Unfortunately this feature will not work for update or uninstall.Labiovelar
S
2299

To restart Jenkins manually, you can use either of the following commands (by entering their URL in a browser):

(jenkins_url)/safeRestart - Allows all running jobs to complete. New jobs will remain in the queue to run after the restart is complete.

(jenkins_url)/restart - Forces a restart without waiting for builds to complete.

Stockbroker answered 10/11, 2011 at 10:8 Comment(18)
Is there an equivalen of the safeRestart but done using Shell command?Obvert
For safeRestart, see https://mcmap.net/q/53760/-how-to-restart-jenkins-manually java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -s http://localhost:8080/ safe-restart (if installed by rpm or deb, otherwise adjust accordingly).Indene
This causes a RestartNotSupportedException in Jenkins 1.532.1 with IcedTea 2.3.9. sudo /etc/init.d/jenkins restart worked for me though.Ameline
Neither restart nor safeRestart work in Windows, it throws a RestartNotSupportedException. I had to restart the whole Tomcat (ugly option, I know)Velure
Tip: if you are using the Workflow plugin, restart will not kill running Workflow builds. In version 1.8 or later (requires Jenkins 1.609.1 or later), safeRestart will also go ahead and restart Jenkins even while Workflow builds are in progress (after any “traditional” builds complete).Katinakatine
In Windows, use the Windows service rather than the command line.Linell
@Linell I agree. They mention the commands here: https://mcmap.net/q/55132/-start-stop-and-restart-jenkins-service-on-windows More details on installing as a service can be found here: wiki.jenkins-ci.org/display/JENKINS/…Recognizor
@Linell no side effects from restarting the Jenkins service so long as everything is idling and no pending changes have not yet been saved right?Telmatelo
Are there any internal links from jenkins to do this instead of rememebering magic url's?Chinch
do you know if doing the 2nd (unsafe option) in any way differs from simply rebooting the web server container that the Jenkins runs out of (e.g. Tomcat, Glassfish etc)?Northerner
In Linux, you have the service jenkins restart option, if you installed Jenkins with System V init scripts.Rastus
Is this not available in the web gui?Illiquid
Be aware if Jenkins is deployed as a ".war" file within a running Tomcat, a Jenkins restart also restarts any other .war files in that Tomcat instance.Chinch
Is there no Button for that?Eclectic
service jenkins restart solved my docker socket problem while restarting from browser did not.Flame
How long does it usually take? I am waiting for 10 min already...Highcolored
This is a handy way, especially if you don't have access to the Node where jenkins is actually running...Tine
There is a Plugin called "Safe Restart Plugin" that you can install without restarting Jenkins. After installation you have a "Restart Safely" link on the "Manage Jenkins" page.Wordy
C
217

If you installed as a rpm or deb, then service jenkins restart will work also.

Chisel answered 17/11, 2011 at 15:34 Comment(0)
H
132

This answer is very out of date: it predates the adoption of systemd for Debian and its derivatives. For modern Debian derived systems, see the Aamir's more recent answer.

On Ubuntu or Debian, when installed through apt-get/dpkg:

$ sudo /etc/init.d/jenkins restart
Usage: /etc/init.d/jenkins {start|stop|status|restart|force-reload}
Helm answered 14/9, 2012 at 13:36 Comment(1)
https://support.cloudbees.com/hc/en-us/articles/216118748-How-to-Start-Stop-or-Restart-your-Instance- says IMPORTANT : Do not launch methods start|stop|restart manually as $sudo /etc/init.d/jenkins start|stop|restart because it makes your service unreliable as it picks up the environment from the root user as opposed to a clean reliable blank environment that is set by the init launchers (service / systemctl).Calamine
L
109

The SafeRestart Plugin needs to be mentioned. It is pretty useful (Restart Safely). It adds a link to be able to restart from the main menu:

Enter image description here

Locke answered 27/5, 2015 at 7:24 Comment(2)
I often use this feature for plugin installs.Gaston
Bizarre that this plugin is not included by default.Herrin
M
91

The below commands worked for me in Red Hat Linux and should work for Ubuntu also.

  • To know the status of Jenkins:

    sudo service jenkins status
    
  • To start the Jenkins:

    sudo service jenkins start
    
  • To stop the Jenkins:

    sudo service jenkins stop
    
  • To restart the Jenkins:

    sudo service jenkins restart
    

Demo on command prompt:

[root@varunHome]# sudo service jenkins status
jenkins (pid  7468) is running...

[root@varunHome]# sudo service jenkins stop
Shutting down Jenkins               [  OK  ]

[root@varunHome]# sudo service jenkins start
Starting Jenkins                    [  OK  ]

[root@varunHome]# sudo service jenkins restart
Shutting down Jenkins               [  OK  ]

Starting Jenkins                    [  OK  ]
[root@varunHome]#

The folks who are using windows

Open Console/Command line --> Go to your Jenkins installation directory. Execute the following commands respectively:

To stop:
jenkins.exe stop

To start:
jenkins.exe start

To restart:
jenkins.exe restart
Malchy answered 2/7, 2015 at 9:13 Comment(0)
P
40

On Windows, if you installed it as a service, go to Services (StartRun: services.msc), find Jenkins, right click → Restart.

If it does not help (UI is not responding) open the Windows Task Manager → Processes, kill the java.exe process, and restart the service once again.

Peduncle answered 5/12, 2012 at 13:32 Comment(2)
trying to reach /safeRestart on windows will lead to: javax.servlet.ServletException: hudson.lifecycle.RestartNotSupportedException: Default Windows lifecycle does not support restart.Laurustinus
When /safeRestart is unavailable, use /safeExit before manually restarting.Katinakatine
K
37

You have many options to restart Jenkins manually, but mainly two (URL or command line):

  • Alternative 1: Using the Jenkins installation URL:

    Jenkins_URL/restart.

    Example: http://jenkinsserver.com/restart

    This type of restart forces a restart without waiting for builds to complete.

    If you need to wait for the jobs endings you can use:

    Jenkins_URL/safeRestart.

    Example: http://jenkinsserver.com/safeRestart

  • Alternative 2: Using the command line, depending on your Jenkins installation.

    • If you're installing using rpm or deb package or you have the Jenkins installation in Red Hat, Ubuntu, or Debian, you can use these commands:

    • sudo service jenkins restart

      This restart Jenkins in one step.

    • sudo service jenkins stop and sudo service jenkins start,

      This restart Jenkins in two steeps.

      Note: if you need to check the Jenkins status, you can use this command: sudo service jenkins status

    • If you are using CentOS, you can use this command:

      sudo systemctl restart jenkins
      

      Note: if you need to check the Jenkins status, you can use this command: sudo systemctl status Jenkins

Ku answered 12/2, 2018 at 14:2 Comment(0)
C
20

This can also be done using the Jenkins CLI:

java -jar jenkins-cli.jar -s http://[jenkins-server]/ restart

The jenkins-cli.jar file along with a full list of commands are available at http://[jenkins-server]/cli.

Chalaza answered 16/3, 2012 at 0:42 Comment(0)
N
19

If you're running Jenkins on Mac OS X then you can manually stop the service by executing this command:

sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist
Navvy answered 6/8, 2014 at 13:16 Comment(1)
you can then restart using loadTorhert
M
13

If you want to just reload the configuration file, one can do

    <jenkins_url>/reload

This is quicker if you have made some small change in the configuration file, like config.xml directly in the file system or made copies of the job through the filesystem (not through the browser).

Monteria answered 7/12, 2015 at 20:52 Comment(0)
C
10

Use the command line interface:

java -jar jenkins-cli.jar -s http://jenkins.example.com:8080/ -i /root/.ssh/id_rsa safe-restart
Cathrine answered 21/3, 2013 at 18:28 Comment(0)
F
10

It depends on how Jenkins has been started.

  • As a service: sudo service jenkins restart, sudo /etc/init.d/jenkins restart, etc.

  • As a web application in a Tomcat installation: restart your Tomcat, or just restart the application in Tomcat. Go to http://<tomcat-server>:8080/manager/list or after authentication hit http://<tomcat-server>:8080/manager/stop?path=/myapp+ http://<tomcat-server>:8080/manager/start?path=/myapp.

  • Launched with just java -jar: kill it (kill -9 <pid>), and relaunch it.

  • Launched with java -jar, but from a supervisor: supervisorctl restart jenkins

Foreland answered 12/2, 2015 at 8:53 Comment(2)
Just pick you use case nice answer !!Jovanjove
can we use these options to automatically identify if jenkins is not responding and can restart when its not responding ?Palatial
T
9

On Windows

Go to the Jenkins installation, open the cmd and run:

  • To stop:

     jenkins.exe stop
    
  • To start:

     jenkins.exe start
    
  • To restart:

     jenkins.exe restart
    
Thorner answered 6/1, 2016 at 3:58 Comment(0)
B
8

If you are running Jenkins in FreeBSD(OS):

/usr/local/etc/rc.d/jenkins restart
Bigot answered 29/9, 2012 at 5:37 Comment(0)
G
8

Sometimes there will be some stale Jenkins processes, so ps -ef | grep jenkins kill all of them. Restart as described in previous answers, and it will be clean.

ps -ef | grep jenkins
sudo kill -kill <pid>
Glasswork answered 26/6, 2013 at 3:53 Comment(0)
F
6

For Mac

###Stop Jenkins###

sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist

###Start Jenkins###

sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist

For a homebrew installed jenkins, use the following:

Starting:

brew services restart jenkins-lts

Stopping:

brew services stop jenkins-lts
Frigate answered 26/2, 2017 at 5:13 Comment(0)
C
6

For a modern Linux system that uses systemd (including CentOS, Debian):

sudo systemctl restart jenkins

sudo systemctl status Jenkins

Jenkins will be active and up and running on some PID.

Chandelle answered 25/8, 2017 at 8:25 Comment(0)
N
5

If you are able to access it in a web browser, just add /restart, for example, localhost:8080/restart.

If you are running it as a service then log in to your server and execute the command:

sudo service jenkins stop/start
Newhouse answered 18/4, 2017 at 20:29 Comment(0)
R
4

For restarting Jenkins manually using the browser:

Enter your www.jenkins-ip/restart (for example, http://localhost:8080/restart) in the browser. Jenkins will restart and load the login page automatically after restart.

Ripsaw answered 27/2, 2017 at 11:48 Comment(0)
G
3

If it is deployed as a war file then restart the application server, for example, Tomcat.

Glasswork answered 23/2, 2012 at 23:4 Comment(0)
C
3

Several people have mentioned the need to restart the servlet container if Jenkins is not running as a standalone. But Tomcat (or what is being used) doesn't need to be restarted. Tomcat can force a restart of the Jenkins context if your Jenkins restart is hung.

But to address another comment, when you put Jenkins in the "shutting down" mode it will not actually shut down. It stops new jobs from executing and place a giant red banner on the system pages so everyone knows that the administrator wants to take it down eventually. There are plugins to trigger a servlet container restart for that context after all builds are completed.

The alternative is to wait till the last running job completes, then manually kick over Jenkins from the container (or via the command line options that others have mentioned for the standalone Jenkins install).

Confessedly answered 4/5, 2015 at 3:26 Comment(0)
I
3

If it is in a Docker container, you can just restart your container. Let's assume the container name is jenkins, so you can do:

docker restart jenkins

Or

docker stop jenkins
docker start jenkins
Inflexible answered 18/5, 2018 at 9:27 Comment(1)
Important! On docker - Jenkins data must be persistent (you might lose running jobs, resources, builds, data etc...) Therefore be cautious ,you better NOT using "restart" and DO use stop and start on docker image. the solution would be: sudo docker ps -> sudo docker stop <dockerImageID> -> sudo docker start <dockerImageID>Satellite
G
2

JenkinURL/restart will do the restart.


/usr/local/etc/rc.d/jenkins restart
Giacomo answered 23/7, 2014 at 20:42 Comment(1)
But /usr/local/etc/rc.d/jenkin is not a URL(?). Can you elaborate?Corrie
F
2

From the terminal:

sudo service jenkins restart

Or jenkinsurl/restart.

Fpc answered 26/12, 2016 at 6:1 Comment(0)
I
1

Try the below. It worked for me.

sudo service jenkins status  

It will give you PID of Jenkins. Now do a

kill -15 [PID]

sudo service jenkins start
Inexplicit answered 25/1, 2014 at 7:53 Comment(2)
Wondering why you don't just do "(sudo) service jenkins restart" ?Circlet
Yes, absolutely correct but I have faced issue ,sometimes in which it doesn't worked for me.Inexplicit
I
1

If nothing works then find the Jenkins process by

ps aux | grep java

and then kill it:

kill -9 [PID]

sudo service jenkins start

Edit : Look for the java process which is related to jenkins

Ihs answered 17/6, 2014 at 4:24 Comment(1)
quite dangerous to just search for java processes, don't you think? One should grep for something more jenkins specific imo.Tellez
C
1

Browse http://[jenkins-server-url]/updateCenter/ and just check 'restart jenkins'

Crammer answered 12/1, 2018 at 1:35 Comment(0)
W
1

Windows

Run services.msc and restart:

Enter image description here

Windflower answered 12/7, 2018 at 13:27 Comment(0)
C
0

If you are running Jenkins as a server on a Windows machine, then open Task Manager and switch to the service tab. Search for Jenkins and restart it.

Colloquy answered 2/8, 2017 at 6:39 Comment(0)
I
0

If you have no permissions or access to the command line directly, you can do e.g. one of the following:

  1. Create a job with shell/batch step that will trigger a restart from the Jenkins installation folder
  2. Install/update some plugin while checking "restart after installation" (at least this works in old versions)

Both above are hacks, but I actively used them in a very restricted environment where no one wanted me to restart Jenkins, huh.

Ise answered 1/12, 2017 at 8:45 Comment(0)
P
-2

jenkins_url/restart is the safest way of doing it.

For service- Service Jenkins restart.

Plotkin answered 15/11, 2017 at 18:38 Comment(1)
What do you mean by "For service- Service Jenkins restart."?Corrie

© 2022 - 2024 — McMap. All rights reserved.