forked from jenkinsci/jenkins
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into update-forms-2
- Loading branch information
Showing
43 changed files
with
571 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package hudson.lifecycle; | ||
|
||
import com.sun.jna.LastErrorException; | ||
import com.sun.jna.Library; | ||
import com.sun.jna.Native; | ||
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; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
/** | ||
* {@link Lifecycle} that delegates its responsibility to {@code systemd(1)}. | ||
* | ||
* @author Basil Crow | ||
*/ | ||
@Restricted(NoExternalUse.class) | ||
@Extension(optional = true) | ||
public class SystemdLifecycle extends ExitLifecycle { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(SystemdLifecycle.class.getName()); | ||
|
||
interface Systemd extends Library { | ||
Systemd INSTANCE = Native.load("systemd", Systemd.class); | ||
|
||
int sd_notify(int unset_environment, String state) throws LastErrorException; | ||
} | ||
|
||
@Override | ||
public void onReady() { | ||
super.onReady(); | ||
notify("READY=1"); | ||
} | ||
|
||
@Override | ||
public void onReload(@NonNull String user, @CheckForNull String remoteAddr) { | ||
super.onReload(user, remoteAddr); | ||
notify("RELOADING=1"); | ||
} | ||
|
||
@Override | ||
public void onStop(@NonNull String user, @CheckForNull String remoteAddr) { | ||
super.onStop(user, 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); | ||
notify(String.format("STATUS=%s", status)); | ||
} | ||
|
||
private static synchronized void notify(String message) { | ||
try { | ||
Systemd.INSTANCE.sd_notify(0, message); | ||
} catch (LastErrorException e) { | ||
LOGGER.log(Level.WARNING, null, e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.