bridgev2/mxmain: add systemd Type=notify support#500
Open
Deln0r wants to merge 1 commit into
Open
Conversation
Megabridge bridges started under a systemd unit with `Type=notify`
currently never report readiness or accept watchdog supervision,
which forces operators to fall back to `Type=simple` and lose the
ability to distinguish startup failures from runtime failures.
Add three small helpers in bridgev2/matrix/mxmain that wrap the
already-available coreos/go-systemd v22 daemon package:
sdNotifyReady - sends READY=1 once the bridge has finished
starting up.
sdNotifyStopping - sends STOPPING=1 just before the graceful
shutdown begins.
startSdWatchdog - pings WATCHDOG=1 at half the configured
interval, returning a stop function that
blocks until the pinger has exited.
All three calls are no-ops when the process is not running under
a systemd unit (the daemon package returns false without error in
that case), so non-systemd deployments are unaffected.
BridgeMain.Run is updated to call the helpers around the
WaitForInterrupt block. coreos/go-systemd is already a transitive
dependency, so go.mod is unchanged.
Closes mautrix#437.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #437.
Summary
Megabridge bridges started under a systemd unit with
Type=notifycurrently never report readiness or accept watchdog supervision. Operators have to fall back toType=simpleand lose the ability to distinguish startup failures from runtime failures.This PR adds three small helpers in
bridgev2/matrix/mxmainthat wrap the already-vendoredcoreos/go-systemd/v22/daemonpackage:sdNotifyReadyBridgeMain.Start()READY=1sdNotifyStoppingBridgeMain.Stop()STOPPING=1startSdWatchdogsdNotifyReadyWATCHDOG=1at half the configured interval, returns a stop functionAll three calls are no-ops when the process is not running under a systemd unit, so non-systemd deployments are unaffected.
Dependency
github.com/coreos/go-systemd/v22is already ingo.sumas a transitive dependency.go.modis unchanged.Test plan
A new
TestSdNotifyHelpersAreNoOpWithoutSystemdinbridgev2/matrix/mxmain/systemd_test.goverifies that the helpers do not panic, do not block, and return a usable stop function whenNOTIFY_SOCKET/WATCHDOG_USECare unset.Scope
This PR only touches
bridgev2/matrix/mxmain.BridgeMain.Run. Bridges that drive their own main loop directly (withoutBridgeMain.Run) can call the helpers from their own equivalent ofRunif they want the same behavior.