Scheduled Safe Restart

1,483 views
Skip to first unread message

AndyB

unread,
Feb 27, 2014, 5:18:23 AM2/27/14
to jenkins...@googlegroups.com
Hi,

Could you tell me if it's possible to schedule a regular safe-restart of Jenkins? I have the safe-restart plugin which works fine, but I'd like to have Jenkins do a safe-restart over the weekend when it's generally idle. I looked at the command line interface but I can't use that as it requires either storing a password in a file or passing a password on the command line, neither of which is doable in our environment. Is there a way to schedule an automatic safe restart from within Jenkins? I guess the problem is that if it's a job the restart will block 'til the job itself is completed, causing a deadlock. Can anyone suggest a way to achieve this?

Thanks,
Andy

Daniel Beck

unread,
Feb 27, 2014, 5:39:45 AM2/27/14
to jenkins...@googlegroups.com
You can also use an SSH key for authentication with jenkins-cli.jar (configure the key in the Jenkins user configuration), so if "environment" refers to non-technical reasons, that would be an option.

Then there's the REST API. POST to /safeRestart to perform that action. For authentication, use the API key of the user account in Jenkins instead of a password.

If you use the Groovy plugin, you could create a job that performs safeRestart in a System Groovy build step with 'jenkins.model.Jenkins.instance.safeRestart()'. Schedule as you would any other job.
> --
> You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Baptiste Mathus

unread,
Feb 28, 2014, 2:41:08 AM2/28/14
to jenkins...@googlegroups.com

Just out of curiosity, why do you want to automate that restart?

--

AndyB

unread,
Feb 28, 2014, 7:48:58 AM2/28/14
to jenkins...@googlegroups.com, m...@beckweb.net

Hi Daniel,

Yes 'environment' refers to policies. Saving a key should be acceptable. I'll give that a go, thanks.  Re. creating a job to do this, I'll try that, but I suspect that the safe-restart waits for no jobs to be running (that's the whole point of it after all), so issuing from a job might not work.

Thanks
Andy

AndyB

unread,
Feb 28, 2014, 7:58:14 AM2/28/14
to jenkins...@googlegroups.com, bma...@batmat.net

Hi Baptiste.

>Just out of curiosity, why do you want to automate that restart?

I find Jenkins slows down after running for awhile (a week or so) and a restart usually fixes this. I've used the monitoring plugin to try to identify issues but I haven't spotted anything other than response times slowly increasing over time. Forcing garbage collection etc., seem to help a little, but so far the best solution is simply to restart. If I can schedule that over the weekend that should work well.  But yes, you are correct to ask why I need to do this as it shouldn't really be required. I'll continue to try and track down the root cause, but in the meantime this should help.

Thanks
Andy

Daniel Beck

unread,
Feb 28, 2014, 3:15:53 PM2/28/14
to jenkins...@googlegroups.com, AndyB
The job starts before it issues the safe restart command (obviously), then it finishes, then Jenkins restarts. I've tested this before posting.

AndyB

unread,
Mar 1, 2014, 10:11:11 AM3/1/14
to jenkins...@googlegroups.com, AndyB, m...@beckweb.net


>The job starts before it issues the safe restart command (obviously), then it finishes, then Jenkins restarts. I've tested this before posting. 

Sounds perfect, thanks for checking!

Andy

Christian Willman

unread,
Mar 6, 2014, 3:57:58 AM3/6/14
to jenkins...@googlegroups.com, m...@beckweb.net
Precisely what we do. Every morning we run a scheduled job to grab and install our master list of Jenkins plugins and then trigger a safeRestart via a System Groovy build step. Works like a charm and hasn't failed us in over six months.

One thing to watch out for: if your developers have a rogue job, perhaps one with a broken, never-ending test, then you might come in Monday morning to a Jenkins instance still stuck in quiet mode with a full build queue. The queue will persist a restart but it's not good, especially if other teams are relying on Jenkins to deploy to regions or perform critical tests over the weekend. If a team is guilty of preventing a restart then we move their job(s) to a purgatory until they fix the problem. You could also use the build timeout plugin I guess.
Reply all
Reply to author
Forward
0 new messages