@@ -0,0 +1,2586 @@
+/*%0A * The MIT License%0A *%0A * Copyright 2018 Alon Bar-Lev %3Calon.barlev@gmail.com%3E%0A *%0A * Permission is hereby granted, free of charge, to any person obtaining a copy%0A * of this software and associated documentation files (the %22Software%22), to deal%0A * in the Software without restriction, including without limitation the rights%0A * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell%0A * copies of the Software, and to permit persons to whom the Software is%0A * furnished to do so, subject to the following conditions:%0A *%0A * The above copyright notice and this permission notice shall be included in%0A * all copies or substantial portions of the Software.%0A *%0A * THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR%0A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,%0A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE%0A * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER%0A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,%0A * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN%0A * THE SOFTWARE.%0A */%0Apackage hudson.lifecycle;%0A%0Aimport hudson.Extension;%0A%0Aimport org.kohsuke.accmod.Restricted;%0Aimport org.kohsuke.accmod.restrictions.NoExternalUse;%0A%0Aimport java.util.logging.Level;%0Aimport java.util.logging.Logger;%0A%0Aimport jenkins.model.Configuration;%0Aimport jenkins.model.Jenkins;%0A%0A/**%0A * %7B@link Lifecycle%7D that delegates the responsibility to restart Jenkins to an external%0A * watchdog such as SystemD or OpenRC.%0A *%0A * %3Cp%3E%0A * Restart by exit with specific code.%0A *%0A * @author Alon Bar-Lev%0A */%0A@Restricted(NoExternalUse.class)%0A@Extension%0Apublic class ExitLifecycle extends Lifecycle %7B%0A%0A    private static final Logger LOGGER = Logger.getLogger(ExitLifecycle.class.getName());%0A%0A    private static final String EXIT_CODE_ON_RESTART = %22exitCodeOnRestart%22;%0A    private static final String DEFAULT_EXIT_CODE = %225%22;%0A%0A    private Integer exitOnRestart;%0A%0A    public ExitLifecycle() %7B%0A        exitOnRestart = Integer.parseInt(Configuration.getStringConfigParameter(EXIT_CODE_ON_RESTART, DEFAULT_EXIT_CODE));%0A    %7D%0A%0A    @Override%0A    public void restart() %7B%0A        Jenkins jenkins = Jenkins.getInstanceOrNull(); // guard against repeated concurrent calls to restart%0A%0A        try %7B%0A            if (jenkins != null) %7B%0A                jenkins.cleanUp();%0A            %7D%0A        %7D catch (Exception e) %7B%0A            LOGGER.log(Level.SEVERE, %22Failed to clean up. Restart will continue.%22, e);%0A        %7D%0A%0A        System.exit(exitOnRestart);%0A    %7D%0A%7D%0A

Introduce exit lifecycle to exit instead of restart