Is it safe to restart jenkins from within a job using this groovy code?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Is it safe to restart jenkins from within a job using this groovy code?

eyoungqu
Folks,

I have been asked to schedule a restart of jenkins once a
week.  I do not want to restart if a job a running, and unfortunately,
I do not have access to the jenkins CLI to issue a restart command.
So, I came up with the following groovy script that gets invoked from
a jenkins job:

Execute system Groovy script:
   Groovy Command:
      import hudson.model.*;
      Hudson.instance.doSafeRestart(null, null);

It seems to work correctly on my test system with Jenkins 1.399.  A
co-
worker is stating that is works most of time on while testing on an
older version of hudson.  (I believe it it Hudson 1.395) Here is the
issue he is
encountering:

Sometimes it (hudson) is not able to attach the correct PID and not
able to access Hudson after the restart

So, I am curious if my Groovy Script implementation should reliable
work?  Or, is this untested waters.

Eric