<p>To restart Jenkins manually, you can use either of the following commands (by entering their URL in a browser):</p>

<p><code>(jenkins_url)/safeRestart</code> - Allows all running jobs to complete. New jobs will remain in the queue to run after the restart is complete.</p>

<p><code>(jenkins_url)/restart</code> - Forces a restart without waiting for builds to complete.</p>

CC BY-SA 4.0
2019-01-11T09:47:49.933Z
2019-01-11T09:47:49.933Z
Subhash
<p>I think this is a real problem that many are trying to solve. There are at times where it is preferable to restart Jenkins upon plugin installation. One of the suggestions that I can provide based on my experience is to:</p>

<ul>
<li>Restrict access to the admin module so that not every developer can install plugins</li>
<li>Instruct developers on the downtime and inform them ahead of time</li>
<li>Install all the required plugins in bulk and restart Jenkins</li>
<li>Inform the developers that Jenkins is ready for use</li>
</ul>

<p>I understand that this requires a manual effort and coordination. But this has worked so far so well in our project, thought no harm in mentioning.</p>

CC BY-SA 4.0
2018-07-17T11:01:31.907Z
2018-07-17T11:01:31.907Z
Karthik Venkatesan
<p>Navigate to the <strong>Plugin Manager</strong>, then click on the <strong>Installed</strong> tab and scroll to the bottom. There should be a button there that says something along the lines of <strong>Restart Jenkins once no jobs are running</strong>.</p>

CC BY-SA 4.0
2021-01-20T03:21:53.243Z
2021-01-20T03:21:53.243Z
Kyle Taylor
<p>Visiting <a href="https://youjenkinsdomain/safeRestart" rel="noreferrer">https://youjenkinsdomain/safeRestart</a> will set it in the mode when it waits for jobs to stop and then restarts.</p>

CC BY-SA 4.0
2019-01-09T02:30:38.267Z
I needed to use this specific answer when our Jenkins server bugged out and failed to restart when a plugin required it.
kayleeFrye_onDeck
CC BY-SA 3.0
2018-01-18T17:32:32.357Z
2018-01-18T17:32:32.357Z
Nakilon
<p>You can execute the safeRestart command using either the Jenkins Rest API (<em>[jenkins_url]/safeRestart</em>) or you can execute the command via the <a href="https://wiki.jenkins.io/display/JENKINS/Jenkins+CLI" rel="noreferrer">Jenkins CLI</a>.</p>

<pre><code>sudo /etc/init.d/jenkins safeRestart
</code></pre>

<blockquote>
  <p>Running a CLI command </p>
  
  <p>The general syntax is as follows (the design is
  similar to tools like svn/git):</p>
  
  <p>java -jar jenkins-cli.jar [-s JENKINS_URL] command [options...]
  [arguments...] </p>
  
  <p>JENKINS_URL can be specified via the environment
  variable $JENKINS_URL. This environment variable is automatically set
  when Jenkins fork a process during builds, which allows you to use
  Jenkins CLI from inside the build without explicitly configuring the
  URL.</p>
</blockquote>

<p>NOTE: When running the safeRestart command, any jobs set to be executed during the restart will be queued up and executed when the server is back online. Make sure this does not cause any conflicts upon reboot!</p>

CC BY-SA 4.0
2021-08-09T15:51:20.253Z
On my (Debian) system, /etc/init.d/jenkins does not have a "safeRestart" option. That startup script isn't related to either the Rest API or the Jenkins CLI
Michael Firth
CC BY-SA 4.0
2024-02-27T18:30:30.350Z
on Ubuntu 20.04LTS updated/upgraded to today's date, jenkins version 2.440.1 rejects the `safeRestart` argument. This is the help message given in response is: `Usage: /etc/init.d/jenkins {start|stop|status|restart|try-restart|force-reload}`. I used `force-reload` successfully.
Pablo Adames
CC BY-SA 4.0
2018-01-17T16:54:47.053Z
2018-07-16T14:03:14.520Z
2018-07-16T14:03:14.520Z
Preston Martin
<p>Visiting "<a href="https://jenkins/safeRestart" rel="nofollow noreferrer">https://jenkins/safeRestart</a>" does not wait for "jobs/builds" to be finished completely in case of pipeline jobs. </p>

<p>It seems to wait for steps to finish and  perform jenkins restart and resume the pipline after jenkins have came up again. </p>

CC BY-SA 4.0
2018-06-28T14:08:53.920Z
I guess this is meant as a comment to the answer of @Nakilon?
hagello
CC BY-SA 3.0
2018-04-18T09:57:44.943Z
2018-04-18T09:57:44.943Z
Muhammad Faizan-Ul-Haq
<p>If you navigate to <code>$YOUR_JENKINS_URL/updateCenter/</code> you should see the following page: <img src="https://i.sstatic.net/dbK3X.png" alt=""></p>

<p>Here you can check <code>Restart Jenkins when installation is complete and no jobs are running</code> which should be fairly safe.</p>

CC BY-SA 3.0
2018-01-17T16:36:52.030Z
It's my understanding that restart only happens if plugins are in the process of installing... there's no way to force that restart to happen without installing plugins, is there?
Alex
CC BY-SA 3.0
2018-01-17T17:01:48.203Z
@Alex I just tested it on my instance and for me it seems to always work, regardless of plugin installation. According to https://stackoverflow.com/a/8077830 there should also be a `/safeRestart` and `/restart` endpoints.
eyalzek
CC BY-SA 3.0
2018-01-17T17:56:04.753Z
But isn't the question about restarting while jobs are running?
Dan Cornilescu
CC BY-SA 3.0
2018-01-18T17:09:24.780Z
@DanCornilescu the question states:`IE: wait for current jobs to finish before going down, and keep track of queued jobs to start once Jenkins comes back up.`, this is exactly what happens when you check that box.
eyalzek
CC BY-SA 3.0
2018-01-18T17:47:48.543Z
I was asking as the question also states `Jenkins without jobs running in three days` - which means there will be an impact as some jobs will be delayed. But still, better than losing jobs.
Dan Cornilescu
CC BY-SA 3.0
2018-01-18T17:50:47.603Z
@eyalzek you're right, it works exactly as intended. Thanks!
Alex
CC BY-SA 4.0
2024-05-14T20:23:24.887Z
There appears to be a duplicate path: manage/pluginManager/updates/ seems to be the same as /updateCenter.
Elijah Lynn
CC BY-SA 3.0
2018-01-17T16:22:10.163Z
2018-01-17T16:22:10.163Z
eyalzek
<p>I need to make some configuration changes on our Jenkins instance that will involve restarting Jenkins a couple of times. However, our developers are committing frequently enough that I haven't seen Jenkins without jobs running in three days. </p>

<p>Is there a native way (either through the GUI or via command line) to safe-restart Jenkins? IE: wait for current jobs to finish before going down, and keep track of queued jobs to start once Jenkins comes back up. </p>

<p>I know there's a <a href="https://wiki.jenkins.io/display/JENKINS/SafeRestart+Plugin" rel="noreferrer">plugin</a> but in order to install it I need to restart Jenkins...</p>

CC BY-SA 3.0
2018-01-17T16:47:56.443Z
Guess from the top of my head, but isn't disabling the slaves an option ? (as far as I remember it doesn't stop ongoing jobs but prevent additional jobs in the queue to be launched)
Tensibai
CC BY-SA 3.0
2018-01-18T18:58:29.060Z
In theory, with a properly configured Jenkins instance running Pipeline jobs, you can restart the master or slave nodes whenever you would like.  My experience says otherwise, however.
jayhendren
CC BY-SA 4.0
2019-02-20T23:46:17.717Z
Jenkins is designed to not be affected by restarts. From my experience, it's possible that a build might fail due to a restart, but they are rare. Where I work we used to have to restart Jenkins regularly. We have every kind of job you can imagine, some small, some huge. Only once did we see a build fail where a pickle was not being rehydrated. After that, we always do safe restarts now.
Gi0rgi0s
CC BY-SA 4.0
2021-11-19T19:43:53.373Z
"a pickle was not being rehydrated" o_O
Cody
<jenkins>
How to safe restart Jenkins?
Alex
# How to safe restart Jenkins?

(Asked by: username_0 on 2018-01-17)

I need to make some configuration changes on our Jenkins instance that will involve restarting Jenkins a couple of times. However, our developers are committing frequently enough that I haven't seen Jenkins without jobs running in three days.

Is there a native way (either through the GUI or via command line) to safe-restart Jenkins? IE: wait for current jobs to finish before going down, and keep track of queued jobs to start once Jenkins comes back up.

I know there's a [plugin](https://wiki.jenkins.io/display/JENKINS/SafeRestart+Plugin) but in order to install it I need to restart Jenkins...

**Tags:** jenkins

> **Comments:**
> **username_1**: Guess from the top of my head, but isn't disabling the slaves an option ? (as far as I remember it doesn't stop ongoing jobs but prevent additional jobs in the queue to be launched)  
> **username_2**: In theory, with a properly configured Jenkins instance running Pipeline jobs, you can restart the master or slave nodes whenever you would like.  My experience says otherwise, however.  
> **username_3**: Jenkins is designed to not be affected by restarts. From my experience, it's possible that a build might fail due to a restart, but they are rare. Where I work we used to have to restart Jenkins regularly. We have every kind of job you can imagine, some small, some huge. Only once did we see a build fail where a pickle was not being rehydrated. After that, we always do safe restarts now.  
> **username_4**: "a pickle was not being rehydrated" o_O  

---

## 7 answers

### Answer by username_15 on 2018-01-17. Score: 23 | Accepted answer

If you navigate to `$YOUR_JENKINS_URL/updateCenter/` you should see the following page: ![](https://i.sstatic.net/dbK3X.png)

Here you can check `Restart Jenkins when installation is complete and no jobs are running` which should be fairly safe.

> **Comments:**
> **username_0**: It's my understanding that restart only happens if plugins are in the process of installing... there's no way to force that restart to happen without installing plugins, is there?  
> **username_15**: @username_0 I just tested it on my instance and for me it seems to always work, regardless of plugin installation. According to https://stackoverflow.com/a/8077830 there should also be a `/safeRestart` and `/restart` endpoints.  
> **username_16**: But isn't the question about restarting while jobs are running?  
> **username_15**: @DanCornilescu the question states:`IE: wait for current jobs to finish before going down, and keep track of queued jobs to start once Jenkins comes back up.`, this is exactly what happens when you check that box.  
> **username_16**: I was asking as the question also states `Jenkins without jobs running in three days` - which means there will be an impact as some jobs will be delayed. But still, better than losing jobs.  
> **username_0**: @username_15 you're right, it works exactly as intended. Thanks!  
> **username_17**: There appears to be a duplicate path: manage/pluginManager/updates/ seems to be the same as /updateCenter.  

---

### Answer by username_8 on 2018-01-18. Score: 35

Visiting <https://youjenkinsdomain/safeRestart> will set it in the mode when it waits for jobs to stop and then restarts.

> **Comments:**
> **username_9**: I needed to use this specific answer when our Jenkins server bugged out and failed to restart when a plugin required it.  

---

### Answer by username_10 on 2018-01-17. Score: 12

You can execute the safeRestart command using either the Jenkins Rest API ([jenkins_url]/safeRestart) or you can execute the command via the Jenkins CLI.
sudo /etc/init.d/jenkins safeRestart


Running a CLI command 
The general syntax is as follows (the design is
  similar to tools like svn/git):
java -jar jenkins-cli.jar [-s JENKINS_URL] command [options...]
  [arguments...] 
JENKINS_URL can be specified via the environment
  variable $JENKINS_URL. This environment variable is automatically set
  when Jenkins fork a process during builds, which allows you to use
  Jenkins CLI from inside the build without explicitly configuring the
  URL.

NOTE: When running the safeRestart command, any jobs set to be executed during the restart will be queued up and executed when the server is back online. Make sure this does not cause any conflicts upon reboot!

> **Comments:**
> **username_11**: On my (Debian) system, /etc/init.d/jenkins does not have a "safeRestart" option. That startup script isn't related to either the Rest API or the Jenkins CLI  
> **username_12**: on Ubuntu 20.04LTS updated/upgraded to today's date, jenkins version 2.440.1 rejects the `safeRestart` argument. This is the help message given in response is: `Usage: /etc/init.d/jenkins {start|stop|status|restart|try-restart|force-reload}`. I used `force-reload` successfully.  

---

### Answer by username_5 on 2019-01-11. Score: 5

To restart Jenkins manually, you can use either of the following commands (by entering their URL in a browser):

`(jenkins_url)/safeRestart` - Allows all running jobs to complete. New jobs will remain in the queue to run after the restart is complete.

`(jenkins_url)/restart` - Forces a restart without waiting for builds to complete.


---

### Answer by username_6 on 2018-07-17. Score: 2

I think this is a real problem that many are trying to solve. There are at times where it is preferable to restart Jenkins upon plugin installation. One of the suggestions that I can provide based on my experience is to:

* Restrict access to the admin module so that not every developer can install plugins
* Instruct developers on the downtime and inform them ahead of time
* Install all the required plugins in bulk and restart Jenkins
* Inform the developers that Jenkins is ready for use

I understand that this requires a manual effort and coordination. But this has worked so far so well in our project, thought no harm in mentioning.


---

### Answer by username_7 on 2021-01-20. Score: 2

Navigate to the **Plugin Manager**, then click on the **Installed** tab and scroll to the bottom. There should be a button there that says something along the lines of **Restart Jenkins once no jobs are running**.


---

### Answer by username_13 on 2018-04-18. Score: 1

Visiting "<https://jenkins/safeRestart>" does not wait for "jobs/builds" to be finished completely in case of pipeline jobs.

It seems to wait for steps to finish and perform jenkins restart and resume the pipline after jenkins have came up again.

> **Comments:**
> **username_14**: I guess this is meant as a comment to the answer of @username_8?  

---

