Skip to content

Instantly share code, notes, and snippets.

@kmayer
Last active April 5, 2016 23:13
Show Gist options
  • Save kmayer/7aa814b385ea60666502b01d9c44fbec to your computer and use it in GitHub Desktop.
Save kmayer/7aa814b385ea60666502b01d9c44fbec to your computer and use it in GitHub Desktop.
Puma plugin to stop via Redis on Heroku
# === Plugins ===
require './lib/puma/plugin/redis_stop_puma'
plugin 'redis_stop_puma'
require 'puma/plugin'
require 'redis'
Puma::Plugin.create do
def start(launcher)
hostname = ENV['DYNO']
return unless hostname
redis = Redis.new(url: ENV.fetch('REDIS_URL', nil))
return unless redis.ping == 'PONG'
in_background do
while true
sleep 2
if message = redis.get("puma::restart::#{hostname}")
redis.del("puma::restart::#{hostname}")
$stderr.puts message
launcher.stop
break
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment