Module: Puma::SdNotify
Relationships & Source Files | |
Namespace Children | |
Exceptions:
| |
Defined in: | lib/puma/sd_notify.rb |
Overview
The MIT License
Copyright © 2017-2022 Agis Anastasopoulos
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This is a copy of github.com/agis/ruby-sdnotify as of commit cca575c The only changes made was “rehoming” it within the ::Puma
module to avoid namespace collisions and applying standard’s code formatting style.
SdNotify
is a pure-Ruby implementation of sd_notify(3). It can be used to notify systemd about state changes. Methods of this package are no-op on non-systemd systems (eg. Darwin).
The API maps closely to the original implementation of sd_notify(3), therefore be sure to check the official man pages prior to using SdNotify
.
Constant Summary
-
ERRNO =
# File 'lib/puma/sd_notify.rb', line 47"ERRNO="
-
FDSTORE =
# File 'lib/puma/sd_notify.rb', line 50"FDSTORE=1"
-
MAINPID =
# File 'lib/puma/sd_notify.rb', line 48"MAINPID="
-
READY =
# File 'lib/puma/sd_notify.rb', line 43"READY=1"
-
RELOADING =
# File 'lib/puma/sd_notify.rb', line 44"RELOADING=1"
-
STATUS =
# File 'lib/puma/sd_notify.rb', line 46"STATUS="
-
STOPPING =
# File 'lib/puma/sd_notify.rb', line 45"STOPPING=1"
-
WATCHDOG =
# File 'lib/puma/sd_notify.rb', line 49"WATCHDOG=1"
Class Attribute Summary
-
.watchdog? ⇒ Boolean
readonly
If the $WATCHDOG_USEC environment variable is set, and the $WATCHDOG_PID variable is unset or set to the PID of the current process.
Class Method Summary
- .errno(errno, unset_env = false)
- .fdstore(unset_env = false)
- .mainpid(pid, unset_env = false)
-
.notify(state, unset_env = false) ⇒ Fixnum?
Notify systemd with the provided state, via the notification socket, if any.
- .ready(unset_env = false)
- .reloading(unset_env = false)
- .status(status, unset_env = false)
- .stopping(unset_env = false)
- .watchdog(unset_env = false) readonly
Class Attribute Details
.watchdog? ⇒ Boolean
(readonly)
Unlike sd_watchdog_enabled(3), this method does not mutate the environment.
If the $WATCHDOG_USEC environment variable is set, and the $WATCHDOG_PID variable is unset or set to the PID of the current process
# File 'lib/puma/sd_notify.rb', line 97
def self.watchdog? wd_usec = ENV["WATCHDOG_USEC"] wd_pid = ENV["WATCHDOG_PID"] return false if !wd_usec begin wd_usec = Integer(wd_usec) rescue return false end return false if wd_usec <= 0 return true if !wd_pid || wd_pid == $$.to_s false end
Class Method Details
.errno(errno, unset_env = false)
.fdstore(unset_env = false)
[ GitHub ].mainpid(pid, unset_env = false)
.notify(state, unset_env = false) ⇒ Fixnum
?
Notify systemd with the provided state, via the notification socket, if any.
Generally this method will be used indirectly through the other methods of the library.
# File 'lib/puma/sd_notify.rb', line 132
def self.notify(state, unset_env=false) sock = ENV["NOTIFY_SOCKET"] return nil if !sock ENV.delete("NOTIFY_SOCKET") if unset_env begin Addrinfo.unix(sock, :DGRAM).connect do |s| s.close_on_exec = true s.write(state) end rescue StandardError => e raise NotifyError, "#{e.class}: #{e.}", e.backtrace end end