Last active
May 12, 2017 12:37
-
-
Save mostlyobvious/e0edc1d2ea2771033e92 to your computer and use it in GitHub Desktop.
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
require 'socket' | |
require 'logger' | |
STDOUT.sync = true | |
logger = Logger.new(STDOUT) | |
watchdog_timeout = (ENV['WATCHDOG_USEC'].to_i / 1_000_000) | |
sd_notify_socket = Socket.new(Socket::AF_UNIX, Socket::SOCK_DGRAM) | |
sd_notify_socket.connect(Addrinfo.unix(ENV['NOTIFY_SOCKET'])) | |
loop do | |
readable, writable, _ = IO.select([], [], [], watchdog_timeout - 1) | |
# handle readable descriptors | |
# handle writable descriptors | |
logger.info('watchdog') | |
sd_notify_socket.write('WATCHDOG=1') | |
end |
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
[Unit] | |
Description=Sample watchdog | |
[Service] | |
User=myapp | |
ExecStart=/srv/myapp/.rubies/ruby-2.3.0/bin/ruby /srv/myapp/watchdog.rb | |
WatchdogSec=10s | |
Restart=on-failure | |
# Uncomment to have no mercy over limit of failures | |
# | |
# StartLimitInterval=5min | |
# StartLimitBurst=4 | |
# StartLimitAction=reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment