A pure-Ruby implementation of sd_notify(3) that can be used to communicate state changes of Ruby programs to systemd.
Refer to the API documentation for more info.
Install ruby-sdnotify:
$ gem install sd_notify
If you're using Bundler, add it to your Gemfile:
gem "sd_notify"
The API is mostly tied to the official implementation, therefore refer to the sd_notify(3) man pages for detailed description of how the notification mechanism works.
An example involving a dummy workload (assuming the program is shipped as a systemd service):
require "sd_notify"
puts "Hello! Booting..."
# doing some initialization work...
sleep 2
# notify systemd that we're ready
SdNotify.ready
sum = 0
5.times do |i|
# doing our main work...
sleep 1
sum += 1
# notify systemd of our progress
SdNotify.status("{sum} jobs completed")
end
puts "Finished working. Shutting down..."
# notify systemd we're shutting down
SdNotify.stopping
# doing some cleanup work...
sleep 2
puts "Bye"
ruby-sdnotify is licensed under MIT. See LICENSE.