86

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.

user1164061
  • 4,222
  • 13
  • 48
  • 74
  • 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 '12 at 22:24
  • both i.e not shutdown if its in the middle of a build and shut down cleanly – user1164061 Apr 23 '12 at 17:17
  • [Similar Question](http://stackoverflow.com/questions/10698419/how-can-a-jenkins-user-authentication-details-be-passed-to-a-script-which-uses) – lindon fox Jul 25 '14 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: https://github.com/jenkinsci/jenkins-scripts/blob/master/scriptler/clearBuildQueue.groovy – Mike D Aug 10 '15 at 16:48

9 Answers9

127

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

This page shows how to use URL commands.

gunr2171
  • 16,104
  • 25
  • 61
  • 88
tcbcw
  • 1,507
  • 2
  • 10
  • 4
  • URL Options http://[jenkins-server]/[command] where [command] can be exit shutdown jenkins restart restart jenkins reload to reload the configuration – lft93ryt Dec 30 '17 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.

mcane
  • 1,696
  • 1
  • 15
  • 25
30
  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.
mabraham
  • 2,806
  • 3
  • 28
  • 25
Muthaiah PL
  • 1,048
  • 3
  • 15
  • 26
  • 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). FYI safe-shutdown no longer works. – Colin Jan 19 '18 at 05: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

Francisco
  • 3,980
  • 1
  • 23
  • 27
  • /safe-restart does not work with my Jenkins installation. Does it come with a particular version or plugin? – Lordalcol Sep 19 '13 at 13:53
  • 4
    Apparently with Jenkins version 1.5+ there is a /safeRestart supported URL. – Lordalcol Sep 19 '13 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 '14 at 05: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.

gareth_bowles
  • 20,760
  • 5
  • 52
  • 82
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

sti
  • 11,047
  • 1
  • 27
  • 27
  • ...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 '17 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
Noam Manos
  • 15,216
  • 3
  • 86
  • 85
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.

Paul
  • 7,155
  • 8
  • 41
  • 40
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.

Shaiju T
  • 6,201
  • 20
  • 104
  • 196