Jenkins

How to Restart Jenkins on Linux

When working with Jenkins, you may come across some instances where you need to restart the Jenkins server. An example of such a scenario is after installing or updating a specific plugin. Another case is after making changes to the Jenkins server.

In this tutorial, we will learn the various methods that you can use to restart the Jenkins server on Linux.

We tested this tutorial on the latest version of Jenkins and Debian 11 server. Feel free to replicate a similar environment.

Restarting Jenkins from the Jenkins Instance

One method that you can use to restart the Jenkins server is using various Jenkins endpoints. Jenkins allows you to navigate to specific URL endpoints to perform some actions such as starting, stopping, and restarting the Jenkins instance.

The accepted commands and endpoints are as shown in the following:

  1. quietDown – This command allows you to put Jenkins in a quiet mode in preparation for a restart. In silent mode, Jenkins does not start any build (even scheduled).
  2. cancelQuietDown – This cancels the quiet mode from the Jenkins instance.
  3. safeExit – The safeExit command puts the Jenkins instance in quiet mode, but it waits for any existing build to be finished before shutting down the instance.
  4. safeRestart – This command allows the Jenkins instance to complete any existing builds before performing a full restart.

It is good to remember that the commands require permission to execute. You can access these commands by navigating to the Jenkins URL/commandName as shown in the following:

http://localhost:8080/quietDown
http://localhost:8080/cancelQuietDown
http://localhost:8080/safeExit
http://localhost:8080/safeRestart
http://localhost:8080/restart
http://localhost:8080/exit

To restart Jenkins, navigate to your Jenkins instance URL/restart or safeRestart to perform a force or graceful restart, respectively.

Click “Yes” to confirm and restart Jenkins.

Managing Jenkins via the Remote API

We can also stop or restart the Jenkins instance using the remote API endpoints. The syntax for each command is as provided in the following:

curl -X POST -u <user>:<password> http://localhost:8080/restart
curl -X POST -u <user>:<password> http://localhost:8080/safeRestart
url -X POST -u <user>:<password> http://localhost:8080/exit
curl -X POST -u <user>:<password> http://localhost:8080 safeExit
curl -X POST -u <user>:<password> http://localhost:8080/quietDown
curl -X POST -u <user>:<password> http://localhost:8080/cancelQuietDown

You can also use wget instead of CURL, as shown in the following example:

$ wget --user=<user> --password=<password> http://localhost:8080/restart
$ wget --user=<user> --password=<password> http://localhost:8080/safeRestart
$ wget --user=<user> --password=<password> $ http://localhost:8080/exit
$ wget --user=<user> --password=<password> http://localhost:8080/safeExit
$ wget --user=<user> --password=<password> http://localhost:8080/quietDown
$ wget --user=<user> --password=<password> http://localhost:8080/cancelQuietDown

NOTE: Depending on the system configuration and the security measures, you may need to provide the Jenkins Crumb Header in your request. Check the documentation to learn more about that.

Managing the Jenkins Server via CLI

You can also use the Jenkins CLI to start, stop, or restart the Jenkins server. The commands are as follows:

java -jar jenkins-cli.jar -s http://localhost:8080/ restart
java -jar jenkins-cli.jar -s http://localhost:8080/ safe-restart
java -jar jenkins-cli.jar -s http://localhost:8080/ shutdown
java -jar jenkins-cli.jar -s http://localhost:8080/ safe-shutdown
java -jar jenkins-cli.jar -s http://localhost:8080/ quiet-down
java -jar jenkins-cli.jar -s http://localhost:8080/ cancel-quiet-down

Managing the Jenkins Server via Systemd

You can also use the systemd commands to start, stop, or restart the Jenkins service as shown in the following:

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

For systemctl, run the following command:

$ sudo systemctl start jenkins.service
$ sudo systemctl stop jenkins.service
$ sudo systemctl restart jenkins.service

There you have it!

Conclusion

You came across four main methods that you can use to start, stop, or restart the Jenkins service.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list