Permalink
Browse files

Allow for multiple heels running on different ports

Remove the assumption that a person would only run one instance of heel
at a time. Now each instance of heel running stores its pid in a file
that has the port number in the filename.

This allows for multiple heels to run simultanesouly on different ports.

Closes #9
  • Loading branch information...
copiousfreetime committed Jul 7, 2013
1 parent d501cc7 commit 64d7a2b8f719723a9c8f6e0aba0da0e056ced1c4
Showing with 18 additions and 10 deletions.
  1. +6 −10 lib/heel/server.rb
  2. +12 −0 spec/server_spec.rb
View
@@ -27,10 +27,6 @@ def home_directory # :nodoc:
(ENV["HOMEPATH"] && "#{ENV["HOMEDRIVE"]}#{ENV["HOMEPATH"]}") ||
"/"
end
-
- def kill_existing_proc
- Heel::Server.new.kill_existing_proc
- end
end
def initialize(argv = [])
@@ -71,11 +67,11 @@ def default_directory
end
def pid_file
- File.join(default_directory,"heel.pid")
+ File.join(default_directory,"heel.#{options.port}.pid")
end
def log_file
- File.join(default_directory,"heel.log")
+ File.join(default_directory,"heel.#{options.port}.log")
end
def win?
@@ -182,7 +178,7 @@ def kill_existing_proc
@stdout.puts "Unable to kill process with pid #{pid}. No permissions to kill process."
end
else
- @stdout.puts "No pid file exists, no process to kill"
+ @stdout.puts "No pid file exists for server running on port #{options.port}, no process to kill"
end
@stdout.puts "Done."
exit 0
@@ -200,10 +196,10 @@ def setup_heel_dir
# make sure that if we are daemonizing the process is not running
def ensure_not_running
- if options.daemonize and File.exist?(pid_file) then
+ if File.exist?(pid_file) then
@stdout.puts "ERROR: PID File #{pid_file} already exists. Heel may already be running."
@stdout.puts "ERROR: Check the Log file #{log_file}"
- @stdout.puts "ERROR: Heel will not start until the .pid file is cleared (`heel --kill' to clean it up)."
+ @stdout.puts "ERROR: Heel will not start until the .pid file is cleared (`heel --kill --port #{options.port}' to clean it up)."
exit 1
end
end
@@ -269,8 +265,8 @@ def server_options
# run the heel server with the current options.
def run
- error_version_help_kill
merge_options
+ error_version_help_kill
setup_heel_dir
ensure_not_running
View
@@ -118,4 +118,16 @@
@stdout.string.must_match( /Sending TERM to process -42/m )
end
end
+
+ it "records the port of the server process in the pid filename" do
+ server = Heel::Server.new( %w[ --port 4222 ] )
+ server.merge_options
+ File.basename( server.pid_file ).must_equal( "heel.4222.pid" )
+ end
+
+ it "records the port of the server process in the log filename" do
+ server = Heel::Server.new( %w[ --port 4222 ] )
+ server.merge_options
+ File.basename( server.log_file ).must_equal( "heel.4222.log" )
+ end
end

0 comments on commit 64d7a2b

Please sign in to comment.