How to shutdown my Jenkins safely?

Jenkins

Jenkins Problem Overview


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.

Jenkins Solutions


Solution 1 - Jenkins

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

This page shows how to use URL commands.

Solution 2 - Jenkins

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.

Solution 3 - Jenkins

  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.

Solution 4 - Jenkins

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

Solution 5 - Jenkins

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.

Solution 6 - Jenkins

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

Solution 7 - Jenkins

Create a Jenkins Job that runs on Master:

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

Solution 8 - Jenkins

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.

Solution 9 - Jenkins

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1164061View Question on Stackoverflow
Solution 1 - JenkinstcbcwView Answer on Stackoverflow
Solution 2 - JenkinsmcaneView Answer on Stackoverflow
Solution 3 - JenkinsMuthaiah PLView Answer on Stackoverflow
Solution 4 - JenkinsFranciscoView Answer on Stackoverflow
Solution 5 - Jenkinsgareth_bowlesView Answer on Stackoverflow
Solution 6 - JenkinsstiView Answer on Stackoverflow
Solution 7 - JenkinsNoam ManosView Answer on Stackoverflow
Solution 8 - JenkinsPaulView Answer on Stackoverflow
Solution 9 - JenkinsShaiju TView Answer on Stackoverflow