forked from jenkinsci/jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Notify
systemd(1)
about start-up completion and other service statu…
…s changes (jenkinsci#6228) (cherry picked from commit 405e977)
- Loading branch information
1 parent
8af9422
commit affedf2
Showing
4 changed files
with
131 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
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.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 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