1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
# ruby-sdnotify
[](https://badge.fury.io/rb/sd_notify)
[](https://travis-ci.org/agis/ruby-sdnotify)
[](http://www.rubydoc.info/github/agis/ruby-sdnotify)
[](LICENSE)
A pure-Ruby implementation of [sd_notify(3)](https://www.freedesktop.org/software/systemd/man/sd_notify.html) that can be used to
communicate state changes of Ruby programs to [systemd](https://www.freedesktop.org/wiki/Software/systemd/).
Refer to the [API documentation](http://www.rubydoc.info/github/agis/ruby-sdnotify) for more info.
## Getting started
Install ruby-sdnotify:
```shell
$ gem install sd_notify
```
If you're using Bundler, add it to your Gemfile:
```ruby
gem "sd_notify"
```
## Usage
The [API](http://www.rubydoc.info/github/agis/ruby-sdnotify) is mostly tied to
the official implementation, therefore refer to the [sd_notify(3) man pages](https://www.freedesktop.org/software/systemd/man/sd_notify.html)
for detailed description of how the notification mechanism works.
An example involving a dummy workload (assuming the program is shipped as a
systemd service):
```ruby
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](LICENSE).
|