New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add restart_command #9

Merged
merged 1 commit into from Sep 27, 2012
Jump to file or symbol
Failed to load files and symbols.
+49 −0
Diff settings

Always

Just for now

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
ProTip! Use n and p to navigate between commits in a pull request.