1

There is an existing question here on how to safely restart Jenkins:

How to safe restart Jenkins?

However, all the answers are either HTTP(s) options or using the jenkins-cli.jar CLI route.

I want to be able to safely restart the Jenkins environment from a script running on the Master host (a Debian Linux system, the script is running from 'cron' as root)

The Jenkins GUI is using LDAP via the company Active Directory to manage logins, so creating an extra user for this is non trivial (and I don't want to have an extra user open to HTTP Jenkins access if I don't absolutely have to), and using the original default "admin" user isn't possible because Jenkins only allows login from one "security realm".

The scripts are able to uncleanly restart Jenkins (because they can restart the processes), but surely it is possible to signal a clean restart somehow.

One of the answers in the linked question suggests "/etc/init.d/jenkins safeRestart", but that isn't a valid command.

1 Answer 1

1

Assuming Jenkins is installed via a package which installs a systemd unit file:

systemctl restart jenkins
6
  • That restarts Jenkins, but it isn't a safe restart. All currently running jobs are aborted in a non-graceful way. Aug 13, 2021 at 10:33
  • That's not the case for my instance of Jenkins (2.289.3). If I restart Jenkins with systemd (i.e. the command in my answer), any jobs which were running before the restart are resumed after Jenkins comes back online.
    – jayhendren
    Aug 16, 2021 at 23:00
  • And after the restart, in my build output, I see (for instance) Resuming build at Mon Aug 16 16:58:58 MDT 2021 after Jenkins restart.
    – jayhendren
    Aug 16, 2021 at 23:02
  • I don't see how that can be true in the generic case - my jobs are running on "agent" systems via custom build scripts. Jenkins could in theory restart the jobs after an "unclean" restart via systemd, but I don't see how it could resume them. As some of my jobs take 4 hours to run, having it restart it when it is 90% finished wouldn't be great. Sep 27, 2021 at 10:15
  • Are you running Pipeline jobs, or Freestyle? Pipeline jobs are robust against Jenkins master restarts, but I don't know about Freestyle jobs.
    – jayhendren
    Sep 27, 2021 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.