Permalink
Browse files

Check that the pidfile is not already present before overriding it

  • Loading branch information...
1 parent f99ea8c commit c582fb2c0db2c2ef9da1aab4b0a3a7a764faa819 @byroot byroot committed with raggi Mar 21, 2012
Showing with 12 additions and 0 deletions.
  1. +12 −0 lib/rack/server.rb
View
@@ -247,11 +247,14 @@ def start &blk
pp app
end
+ check_pid! if options[:pid]
+
# Touch the wrapped app, so that the config.ru is loaded before
# daemonization (i.e. before chdir, etc).
wrapped_app
daemonize_app if options[:daemonize]
+
write_pid if options[:pid]
trap(:INT) do
@@ -319,5 +322,14 @@ def write_pid
::File.open(options[:pid], 'w'){ |f| f.write("#{Process.pid}") }
at_exit { ::File.delete(options[:pid]) if ::File.exist?(options[:pid]) }
end
+
+ def check_pid!
+ return unless ::File.exist?(options[:pid])
+ pid = ::File.read(options[:pid])
+ STDERR.puts "There is already a pid file wrote a by process with pid #{pid}"
+ STDERR.puts "If this process is no longer running, you have to remove the pidfile #{options[:pid]}"
+ exit(1)
+ end
+
end
end

0 comments on commit c582fb2

Please sign in to comment.