Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add --restart-services command line task #67

Merged
merged 2 commits into from

4 participants

@mattheath

Adds a command line task to restart all registered services by disabling and then re-enabling, rather useful when developing new manifests or config changes.

The disable/enable doesn't seem ideal, but I can't see any way that OS X has to generically restart a service using launchctl? Happy to improve if there is!

@wfarr
Owner

Add tests for this, please.

@wfarr
Owner

Bump.

@mattheath

Not sure on testing this, have tried mocking the enable/disable methods on the service but they're not getting called - any pointers?

@mattheath

@wfarr Finally got round to this, serious apologies for how long it took!

@wfarr
Owner

/cc @ymendel for code audit

@ymendel
Owner

Looks fine to me. It's pretty much exactly what I did for the enable and disable tests.

@fromonesrc fromonesrc merged commit c5b047d into boxen:master
@fromonesrc
Owner

:+1: from @wfarr and @ymendel. Merged --restart-services flag.

@mattheath mattheath deleted the mattheath:restart-services branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
9 lib/boxen/flags.rb
@@ -31,6 +31,7 @@ def initialize(*args)
@stealth = false
@disable_services = false
@enable_services = false
+ @restart_services = false
@list_services = false
@color = true
@@ -61,6 +62,10 @@ def initialize(*args)
@enable_services = true
end
+ o.on "--restart-services", "Restart Boxen services." do
+ @restart_services = true
+ end
+
o.on "--list-services", "List Boxen services." do
@list_services = true
end
@@ -160,6 +165,10 @@ def enable_services?
@enable_services
end
+ def restart_services?
+ @restart_services
+ end
+
def list_services?
@list_services
end
View
12 lib/boxen/runner.rb
@@ -93,6 +93,18 @@ def process_flags
exit
end
+ # --restart-services restarts all services
+
+ if flags.restart_services?
+ Boxen::Service.list.each do |service|
+ puts "Restarting #{service}..."
+ service.disable
+ service.enable
+ end
+
+ exit
+ end
+
end
def process_args
View
17 test/boxen_runner_test.rb
@@ -66,6 +66,23 @@ def test_enable_services
end
end
+ def test_restart_services
+ config = Boxen::Config.new
+ flags = Boxen::Flags.new('--restart-services')
+ runner = Boxen::Runner.new config, flags
+
+ services = Array.new(3) { mock('service') }
+ services.each do |service|
+ service.expects(:disable).once
+ service.expects(:enable).once
+ end
+ Boxen::Service.stubs(:list).returns(services)
+
+ assert_raises(SystemExit) do
+ runner.process
+ end
+ end
+
def test_list_services
config = Boxen::Config.new
flags = Boxen::Flags.new('--list-services')
Something went wrong with that request. Please try again.