Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 53 lines (41 sloc) 1.41 KB
#!/usr/bin/env ruby
def getpid(pidfile)
f =
pid =
if pid == 0
raise "Error reading pid file: %s" % pidfile
return pid
pidfile = ARGV.first || "/var/run/"
pidfile2 = "%s.oldbin" % pidfile
if not pidfile && File.exist?(pidfile)
warn "Invalid pid file: %s\nIs nginx running?" % pidfile
puts "Starting new nginx binary"
Process.kill("USR2", getpid(pidfile))
puts "Sleeping 2 seconds"
puts "Gracefully stopping old workers"
Process.kill("WINCH", getpid(pidfile2))
puts ""
puts "Now we have the new and the old nginx masters, but only the new workers. If everything looks good we will shut down the old master, otherwise we can start the old workers again and stop the new master"
while true:
puts "Enter new to continue with new binary, old to roll back: "
plan = gets.downcase
break if ['new', 'old'].include?(plan)
puts "Invalid input: %s" % plan
if plan == 'new':
puts "Stopping old master"
Process.kill("QUIT", getpid(pidfile2))
puts "Starting old workers without config reload"
Process.kill("HUP", getpid(pidfile2))
puts "Gracefully shutting down new workers"
Process.kill("QUIT", getpid(pidfile))
puts "Sleeping 3 seconds"
puts("Stopping new master")
Process.kill("QUIT", getpid(pidfile))
puts "All done. Check that only one nginx master is running."