Let Jenkins Hit Itself in the Head without Fear (a.k.a. Restart Safely)

Stephen Connolly's picture

Overview

Jenkins

While recent improvements in Jenkins have removed some of the need for restarting, there will always be times when you need to restart. If your Jenkins instance is busy, running lots of jobs on multiple nodes, finding a window in time when you can restart safely because there are no running jobs can be next to near impossible. You could use the “Prepare for Shutdown” management option to stop new jobs from being scheduled, but then you have to remember to actually restart the Jenkins instance… and if a 36h build job is 15h in, chances are you will forget to login in 17h to restart the instance so that new builds can start again and Jenkins can keep your codebase’s back safe from developers breaking tests.

Enter the Safe Restart Plugin, which will wait those 17h for you and then restart Jenkins on your behalf.

Stable Release Versions

The latest release is 0.2 which was released in September 2011 and has no known issues.

Requirements for Plugin-Use

Jenkins 1.421 or newer.

Step-by-Step Instructions on How to Use the Safe Restart Plugin

Installation

Safe Restart Plugin Installation

  1. Go to your Jenkins instances root page.
  2. If your Jenkins instance has security enabled, login as a user who has the Overall | Administer permission.
  3. Select the Manage Jenkins link on the left-hand side of the screen.
  4. Select the Manage Plugins link.
  5. On the Available tab, select the SafeRestart Plugin and click the Download and Install button at the bottom of the page.
  6. (If you are using a version of Jenkins prior to 1.442) Restart Jenkins once the plugins are downloaded.

Configuration
Nothing to configure.

Using

  1. Click on the Restart Safely button.
    Safe Restart Plugin configuration
  2. Click on Yes.
    Safe Restart Plugin configuration
  3. Go make a cup of coffee.

Tips & Tricks

  • Note this plugin just puts a link on the main page, Jenkins’ core functionality provides the safe-restart functionality, i.e. you can still use the http://jenkins-url/safeRestart link to restart safely without installing this plugin.

Known Issues

  • If your Jenkins instance’s servlet container does not support a web application restarting its own context, then this plugin cannot provide restart functionality, and the “Restart Safely” link will not appear.

Relevant Documentation

- Stephen Connolly, Elite Developer and Architect
CloudBees
www.cloudbees.com

 

Blog Categories: 

Comments

Can this safe restart be scheduled as a Jenkins job? e.g. to restart automatically every weekend? Thanks for your time,
Stephen Connolly's picture

The safe restart is not a job type, so it cannot take advantage of the Jenkins scheduling functionality. With Jenkins Operations Center by CloudBees, you can create a cluster operation that will do a safe restart of all or specific client masters and then schedule that operation to run periodically. Alternatively, if you don't have Jenkins Operations Center then you can use the Jenkins API token for a Jenkins Admin user and CURL to have a build job that loops back into Jenkins and triggers a safe restart. You will need to be very careful about who has permissions on that job as it would be exposing the API token in plain text within the console log and anyone who has that API token would have admin rights in your Jenkins with that token... but perhaps you could find a way of working around that issue

Add new comment