-
-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatically send status notifications to systemd #1029
Merged
bensheldon
merged 12 commits into
bensheldon:main
from
Mr0grog:1027-if-you-use-systemd-it-would-be-nice-to-get-notified
Aug 6, 2023
Merged
Automatically send status notifications to systemd #1029
bensheldon
merged 12 commits into
bensheldon:main
from
Mr0grog:1027-if-you-use-systemd-it-would-be-nice-to-get-notified
Aug 6, 2023
Conversation
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 adds a somewhat naive `SystemdService` class that will send appropriate notifications to systemd or do nothing if it doesn't detect that the process is being run by systemd. It pretty much just notifies that the process is ready, is stopping, and actively notifies the watchdog while it's running. It doesn't reach into the actual job system to check that things are OK, or hook into ActiveSupport notifications to tell systemd about other events (like restarting/reloading). Fixes bensheldon#1027.
Stubbed constants are very not cool as far as Sorbet is concerned, so the way I wrote these tests before broke the linter. OTOH, trying to figure out how to make this acceptable did get some slightly nicer test setup.
Mr0grog
commented
Aug 5, 2023
Mr0grog
commented
Aug 5, 2023
To your other questions:
|
OK, I moved the |
It's good to know why these are skipped so we can stop skipping them in the future if the JRuby issue is fixed (or someone figures out a workaround).
anthonyroussel
added a commit
to lafourmiliere-benevolat/capistrano-good_job
that referenced
this pull request
Jan 14, 2024
Available since Good Job v3.17 See bensheldon/good_job#1029
anthonyroussel
added a commit
to lafourmiliere-benevolat/capistrano-good_job
that referenced
this pull request
Jan 14, 2024
Available since Good Job v3.17 See bensheldon/good_job#1029
anthonyroussel
added a commit
to lafourmiliere-benevolat/capistrano-good_job
that referenced
this pull request
Jan 15, 2024
Available since Good Job v3.17 See bensheldon/good_job#1029
anthonyroussel
added a commit
to lafourmiliere-benevolat/capistrano-good_job
that referenced
this pull request
Jan 15, 2024
Available since Good Job v3.17 See bensheldon/good_job#1029
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.
This adds built-in support for sending service status information to systemd as well as systemd’s watchdog (where it expects you to ping it every N seconds to let it know your process isn’t stuck and in need of a restart). It also adds an example systemd configuration file in
examples/systemd/goodjob.service
. Fixes #1027.This works, but I’m not sure whether it’s totally ready. Some questions I was left with:
In Add systemd/sd_notify support to CLI #1027, you asked to vendor the sd_notify gem, which I did. It looks like this is the first vendored dependency, so I looked around and saw that Rubocop was already configured to expect a top-level
vendor
directory, so I put it there. However, that meant I had to add that directory to the.gemspec
file, and also add arequire_relative
call in alib
file, which seems non-ideal. Should this go somewhere else?lib/good_job/vendor/<filename>
lib/good_job/<filename>
, undifferentiated from other library filessorbet/tapioca/require.rb
is missing some things thatbin/tapioca require
wants to add. I added the minimum needed to make Sorbet happy, but not sure it should be further updated to reflect what the command-line tools would otherwise add to it.Logging: is using ActiveSupport notifications and adding methods to
GoodJob::LogSubscriber
for logging correct? I originally tried to useGoodJob.logger
(based onconfiguration.rb
andprobe_server.rb
) but realized that neither outputs to STDOUT nor tags the log lines. I feel a little awkward about stuff that should be very narrowly scoped to the CLI executable leaking out into a place for handling more generic events across the library.The way watchdog support works is a little naive — it just starts a thread that sends notifications on a timer without checking anything. I think this is ok for a start (it’s the same as Sidekiq and Puma), but ideally, it would either:
But really if you’re already confident that the GoodJob CLI crashes or gracefully exits anytime you’d need systemd to restart it, then the current behavior is fine.
Relatedly, I kind of wondered if the CLI should use ActiveSupport notifications to signal status things, and both this and the Probe Server should subscribe to those instead of being managed directly in
GoodJob::CLI#start
. But that seemed like growing the scope of this change unnecessarily.(One thing this immediately would get is notification about the
scheduler_restart_pools
event. Systemd has aRELOADING
notification GoodJob would ideally send it when this happens. But GoodJob also already write a log about that, so it’s probably not a big deal.)I cribbed a lot from Sidekiq and from @Roko131’s example in Add systemd example at documentation #988; I don’t know if I should credit those (particularly Sidekiq, as a separate project) somehow. I don’t think that’s super important for an example config file like this, but figure it’s worth calling out.
(Also, some stuff in both of those seemed out of date and I cleaned it up — on Ubuntu 22, systemd screamed at me about using syslog, which is apparently no longer supported. You’re supposed to use journal now.)
I named the example service
goodjob
to match the example rc.d configuration. But I kind of intuitively though maybe it should begood_job
? Not really a big deal.