87

I run Jenkins in its own container. I use the command "nohup java -jar jenkins.war --httpsPort=8443".

How do I shut it down safely? Right now, I use the kill command to kill the process.

4
  • Please define what you mean by "safely". Do you mean that Jenkins would not shut down if it is in the middle of a build? Or merely that Jenkins shuts down cleanly without corrupting any config files?
    – sti
    Apr 21, 2012 at 22:24
  • both i.e not shutdown if its in the middle of a build and shut down cleanly Apr 23, 2012 at 17:17
  • Similar Question
    – lindon fox
    Jul 25, 2014 at 10:42
  • 5
    Missing in all the answers on this page is http://yourjenkins/quietDown. This will ensure new builds don't run but keeps existing builds running. Also, when you bring up your Jenkins, you might want to flush the queue: github.com/jenkinsci/jenkins-scripts/blob/master/scriptler/…
    – Mike D
    Aug 10, 2015 at 16:48

9 Answers 9

129

Use http://[jenkins-server]/exit

This page shows how to use URL commands.

1
  • URL Options http://[jenkins-server]/[command] where [command] can be exit shutdown jenkins restart restart jenkins reload to reload the configuration
    – lft93ryt
    Dec 30, 2017 at 15:50
64

If you would like to stop jenkins and all its services on the server using Linux console (e.g. Ubuntu), run:

service jenkins start/stop/restart

This is useful when you need to make an image/volume snapshot and you want all services to stop writing to the disk/volume.

1
  • 5
    This answer assumes that Jenkins was installed using the Debian or RPM package, which isn't always the case. Jun 21, 2017 at 20:43
31
  1. jenkinsUrl/safeRestart - Let you to wait for running JOBS to get complete and do a RESTART.
  2. jenkinsUrl/restart - Do a restart immediately without waiting for the jobs which are running currently.
  3. jenkinsUrl/exit - It stops/shutdown the JENKINS services
  4. jenkinsUrl/reload - To reload the configuration changes.
1
  • 4
    Why the heck did they make it safeRestart and then safe-shutdown instead of safeShutdown? It's inconsistencies like these that drive a dev up the wall (and force us to look everything up on StackOverflow). </rant> FYI safe-shutdown no longer works.
    – Colin
    Jan 19, 2018 at 5:48
25

The full list of commands is available at http://your-jenkins/cli

The command for a clean shutdown is http://your-jenkins/safe-shutdown

You may also want to use http://your-jenkins/safe-restart

3
  • /safe-restart does not work with my Jenkins installation. Does it come with a particular version or plugin?
    – Lordalcol
    Sep 19, 2013 at 13:53
  • 4
    Apparently with Jenkins version 1.5+ there is a /safeRestart supported URL.
    – Lordalcol
    Sep 19, 2013 at 14:31
  • 11
    To safely (e.g. wait for jobs) restart - http://your-jenkins/safeRestart. To safely exit - http://your-jenkins/safeExit
    – kevinmm
    Sep 25, 2014 at 5:43
19

Yes, kill should be fine if you're running Jenkins with the built-in Winstone container. This Jenkins Wiki page has some tips on how to set up control scripts for Jenkins.

0
8

You can kill Jenkins safely. It will catch SIGTERM and SIGINT and perform an orderly shutdown. However, if Jenkins was in the middle of building something, it will abort the builds and they will show up gray in the status display.

If you want to avoid this, you must put Jenkins into shutdown mode to prevent it from starting new builds and wait until currently running builds are done before killing Jenkins.

You can also use the Jenkins command line interface and tell Jenkins to safe-shutdown, which does the same. You can find more info on Jenkins cli at http://YOURJENKINS/cli

1
  • ...and it seems that if it fails to respond to SIGINT and SIGTERM, then perhaps SIGKILL is justified (although probably not 'safe').
    – sage
    Jun 20, 2017 at 22:38
2

Create a Jenkins Job that runs on Master:

java -jar "%JENKINS_HOME%/war/WEB-INF/jenkins-cli.jar" -s "%JENKINS_URL%" safe-restart
2

You can also look in the init script area (e.g. centos vi /etc/init.d/jenkins ) for details on how the service is actually started and stopped.

1

Immediately shuts down Jenkins server.

In Windows CMD.exe, Go to folder where jenkins-cli.jar file is located.

C:\Program Files (x86)\Jenkins\war\WEB-INF

Use Command to Safely Shutdown

java -jar jenkins-cli.jar -s http://localhost:8080 safe-shutdown --username "YourUsername" 
--password "YourPassword"

The full list of commands is available at http://localhost:8080/cli

Credits to Francisco post for cli commands.

Reference:

1.

Hope helps someone.

2
  • 1
    I do not find this folder on Windows 10 Home. C:\Program Files (x86)\Jenkins
    – likejudo
    Feb 1, 2021 at 17:35
  • @likejudo, then go to any other C:\Program Files folder on Windows 10 were Jenkins is installed.
    – Shaiju T
    Feb 1, 2021 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.