How to Start, Stop or Restart your Instance?

Article ID:216118748
3 minute readKnowledge base

Issue

  • How do I start Jenkins?

  • How do I stop Jenkins?

  • How do I restart Jenkins?

Resolution

Administration from Jenkins

The easiest way to stop/restart a Jenkins instance is through the instance itself. In addition to the basic stop and restart commands Jenkins provides a set of commands to safely stop/restart Jenkins by putting it in a quiet mode.

  • quietDown: Put Jenkins in a Quiet mode, in preparation for a restart. In that mode Jenkins don’t start any build

  • cancelQuietDown: Cancel the effect of the "quiet-down" command

  • safeRestart: Puts Jenkins into the quiet mode, wait for existing builds to be completed, and then restart Jenkins

  • safeExit: Puts Jenkins into the quiet mode, wait for existing builds to be completed, and then shut down Jenkins

These commands obey the security rules defined by the Authorization Strategy set up in Jenkins. Only user(s) with the required permission can use the following commands:

URL

https://<jenkins.server>/restart
https://<jenkins.server>/safeRestart
https://<jenkins.server>/exit
https://<jenkins.server>/safeExit
https://<jenkins.server>/quietDown
https://<jenkins.server>/cancelQuietDown

Remote API

URL can be invoked by a Remote API.

Using wget:

$ wget --user=<user> --password=<password> https://<jenkins.server>/restart
$ wget --user=<user> --password=<password> https://<jenkins.server>/safeRestart
$ wget --user=<user> --password=<password> https://<jenkins.server>/exit
$ wget --user=<user> --password=<password> https://<jenkins.server>/safeExit
$ wget --user=<user> --password=<password> https://<jenkins.server>/quietDown
$ wget --user=<user> --password=<password> https://<jenkins.server>/cancelQuietDown

Using cURL:

$ curl -X POST -u <user>:<password> https://<jenkins.server>/restart
$ curl -X POST -u <user>:<password> https://<jenkins.server>/safeRestart
$ curl -X POST -u <user>:<password> https://<jenkins.server>/exit
$ curl -X POST -u <user>:<password> https://<jenkins.server>/safeExit
$ curl -X POST -u <user>:<password> https://<jenkins.server>/quietDown
$ curl -X POST -u <user>:<password> https://<jenkins.server>/cancelQuietDown

Jenkins CLI:

$ java -jar jenkins-cli.jar -s https://<jenkins-server>/ restart
$ java -jar jenkins-cli.jar -s https://<jenkins-server>/ safe-restart
$ java -jar jenkins-cli.jar -s https://<jenkins-server>/ shutdown
$ java -jar jenkins-cli.jar -s https://<jenkins-server>/ safe-shutdown
$ java -jar jenkins-cli.jar -s https://<jenkins-server>/ quiet-down
$ java -jar jenkins-cli.jar -s https://<jenkins-server>/ cancel-quiet-down

System Administration

It is obviously possible to administrate the Jenkins process itself. This is the case, for example, when a machine needs to be restarted or upgraded. It is worth to mention that quiet-down is not available in that case. Only users with the required system permissions should be able to run the following commands.

Unix-based

You installed Jenkins on a Debian-based or a Fedora-based distribution, you can use the following commands:

$ sudo service jenkins restart
$ sudo service jenkins stop
$ sudo service jenkins start

Or in the latest distribution of Linux:

$ sudo systemctl start jenkins.service
$ sudo systemctl stop jenkins.service
$ sudo systemctl restart jenkins.service
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).

Windows

You installed Jenkins as a service on Windows, you can either use the UI component Services manager (by running services.msc) or you can use the following command:

$ C:\Program Files (x86)\Jenkins>jenkins.exe start
$ C:\Program Files (x86)\Jenkins>jenkins.exe stop
$ C:\Program Files (x86)\Jenkins>jenkins.exe restart

Tomcat

You deployed Jenkins on a Tomcat application server, you can start/stop the application server itself.

Tomcat as a Unix service:

$ service tomcat7 start
$ service tomcat7 stop
$ service tomcat7 restart

Tomcat as a Windows service:

$ <tomcat.home>/bin/Tomcat.exe start
$ <tomcat.home>/bin/Tomcat.exe stop

Tomcat running Mac/Linux/Unix binaries:

$ $CATALINA_HOME/bin/startup.sh
$ $CATALINA_HOME/bin/shutdown.sh

Tomcat running Windows binaries:

$ %CATALINA_HOME%\bin\startup.bat
$ %CATALINA_HOME%\bin\shutdown.bat

However, if several applications are deployed on your application server, it is preferable to manage the Jenkins application independently rather than restarting all applications. The following URLs shows how to start/stop/restart an application like jenkins deployed on a Tomcat server.

Tomcat 7+:

https://<tomcat-server>:8080/manager/text/stop?path=/jenkins
https://<tomcat-server>:8080/manager/text/start?path=/jenkins
https://<tomcat-server>:8080/manager/text/reload?path=/jenkins