Skip to content

Commit

Permalink
Extend startup notification timeout as each initialization milestone …
Browse files Browse the repository at this point in the history
…is attained (jenkinsci#6237)

(cherry picked from commit 3866e93)
  • Loading branch information
basil authored and MarkEWaite committed Mar 4, 2022
1 parent affedf2 commit 256d373
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/src/main/java/hudson/lifecycle/Lifecycle.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.io.UncheckedIOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
Expand Down Expand Up @@ -276,6 +277,16 @@ public void onStop(@NonNull String user, @CheckForNull String remoteAddr) {
}
}

/**
* Tell the service manager to extend the startup or shutdown timeout. The value specified is a
* time during which either {@link #onExtendTimeout(long, TimeUnit)} must be called again or
* startup/shutdown must complete.
*
* @param timeout The amount by which to extend the timeout.
* @param unit The time unit of the timeout argument.
*/
public void onExtendTimeout(long timeout, @NonNull TimeUnit unit) {}

/**
* Called when Jenkins service state has changed.
*
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/java/hudson/lifecycle/SystemdLifecycle.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.kohsuke.accmod.Restricted;
Expand Down Expand Up @@ -46,6 +47,12 @@ public void onStop(@NonNull String user, @CheckForNull String remoteAddr) {
notify("STOPPING=1");
}

@Override
public void onExtendTimeout(long timeout, @NonNull TimeUnit unit) {
super.onExtendTimeout(timeout, unit);
notify(String.format("EXTEND_TIMEOUT_USEC=%d", unit.toMicros(timeout)));
}

@Override
public void onStatusUpdate(String status) {
super.onStatusUpdate(status);
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/java/jenkins/model/Jenkins.java
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,7 @@ private boolean containsLinkageError(Throwable x) {
@Override
protected void onInitMilestoneAttained(InitMilestone milestone) {
initLevel = milestone;
getLifecycle().onExtendTimeout(EXTEND_TIMEOUT_SECONDS, TimeUnit.SECONDS);
if (milestone == PLUGINS_PREPARED) {
// set up Guice to enable injection as early as possible
// before this milestone, ExtensionList.ensureLoaded() won't actually try to locate instances
Expand Down Expand Up @@ -5519,6 +5520,12 @@ public boolean shouldShowStackTrace() {
@SuppressFBWarnings(value = "MS_SHOULD_BE_FINAL", justification = "for script console")
public static boolean AUTOMATIC_AGENT_LAUNCH = SystemProperties.getBoolean(Jenkins.class.getName() + ".automaticAgentLaunch", true);

/**
* The amount of time by which to extend the startup notification timeout as each initialization milestone is attained.
*/
@SuppressFBWarnings(value = "MS_SHOULD_BE_FINAL", justification = "for script console")
public static /* not final */ int EXTEND_TIMEOUT_SECONDS = SystemProperties.getInteger(Jenkins.class.getName() + ".extendTimeoutSeconds", 15);

private static final Logger LOGGER = Logger.getLogger(Jenkins.class.getName());
private static final SecureRandom RANDOM = new SecureRandom();

Expand Down

0 comments on commit 256d373

Please sign in to comment.