Permalink
Browse files

Merge pull request #9 from livingsocial/restart_command

Add a restart command
  • Loading branch information...
FooBarWidget committed Sep 27, 2012
2 parents ffdd2f2 + 25a9cfb commit 20135f553656dc87de6143ea11713581b05bdfed
Showing with 49 additions and 0 deletions.
  1. +19 −0 lib/daemon_controller.rb
  2. +30 −0 spec/daemon_controller_spec.rb
View
@@ -120,6 +120,13 @@ class DaemonizationTimeout < TimeoutError
#
# The default value is +nil+.
#
# [:restart_command]
# A command to restart the daemon with, e.g. "/etc/rc.d/nginx restart". If
# no restart command is given (i.e. +nil+), then DaemonController will
# restart the daemon by calling #stop and #start.
#
# The default value is +nil+.
#
# [:before_start]
# This may be a Proc. It will be called just before running the start command.
# The before_start proc is not subject to the start timeout.
@@ -180,6 +187,7 @@ def initialize(options)
@start_command = options[:start_command]
@stop_command = options[:stop_command]
@ping_command = options[:ping_command]
@restart_command = options[:restart_command]
@ping_interval = options[:ping_interval] || 0.1
@pid_file = options[:pid_file]
@log_file = options[:log_file]
@@ -286,6 +294,17 @@ def stop
end
end
# Restarts the daemon. Uses the restart_command if provided, otherwise
# calls #stop and #start.
def restart
if @restart_command
run_command(@restart_command)
else
stop
start
end
end
# Returns the daemon's PID, as reported by its PID file. Returns the PID
# as an integer, or nil there is no valid PID in the PID file.
#
@@ -291,6 +291,36 @@
end
end
describe DaemonController, "#restart" do
include TestHelper
before :each do
new_controller
end
it "raises no exception if the daemon is not running" do
@controller.restart
end
describe 'with no restart command' do
it "restart the daemon using stop and start" do
@controller.should_receive(:stop)
@controller.should_receive(:start)
@controller.restart
end
end
describe 'with a restart_command' do
it 'restarts the daemon using the restart_command' do
stop_cmd = "echo 'hello world'"
new_controller :restart_command => stop_cmd
@controller.should_receive(:run_command).with(stop_cmd)
@controller.restart
end
end
end
describe DaemonController, "#connect" do
include TestHelper

0 comments on commit 20135f5

Please sign in to comment.