Project

sd_notify

0.35
No release in over 3 years
Low commit activity in last 3 years
sd_notify can be used to notify systemd about various service status changes of Ruby programs
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

ruby-sdnotify

Gem Version Build status Documentation License

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.

Getting started

Install ruby-sdnotify:

$ gem install sd_notify

If you're using Bundler, add it to your Gemfile:

gem "sd_notify"

Usage

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"

License

ruby-sdnotify is licensed under MIT. See LICENSE.