Skip to content

Instantly share code, notes, and snippets.

@mostlyobvious
Last active May 12, 2017 12:37
Show Gist options
  • Save mostlyobvious/e0edc1d2ea2771033e92 to your computer and use it in GitHub Desktop.
Save mostlyobvious/e0edc1d2ea2771033e92 to your computer and use it in GitHub Desktop.
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
[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