Skip to content

A platform for community discussion. Free, open, simple.

DEV: Extract unicorn server PID when ArgumentError raised (#36649)

Martin Brennan1dd8daef454f
diff --git a/bin/unicorn b/bin/unicorn
index 6b5c4edfb19..eaa04f761f5 100755
--- a/bin/unicorn
+++ b/bin/unicorn
@@ -60,7 +60,22 @@ if dev_mode
restart = true
while restart
restart = false
- pid = fork { load Gem.bin_path("unicorn", "unicorn") }
+ pid =
+ fork do
+ begin
+ load Gem.bin_path("unicorn", "unicorn")
+ rescue ArgumentError => err
+ if (err.message =~ /Already running on PID/)
+ puts "\n"
+ puts "Unicorn is already running!\n"
+ pid = err.message[/PID:(\d+)/, 1]&.to_i
+ puts "\n"
+ puts "kill -9 #{pid} to stop the existing unicorn master process, then try again."
+ else
+ raise err
+ end
+ end
+ end
done = false
Signal.trap("INT") do