summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Williams <nathan@teamtreehouse.com>2016-05-06 14:37:46 -0700
committerNathan Williams <nathan@teamtreehouse.com>2016-05-06 15:14:17 -0700
commitd8b3f05774613c949c8ed33a48122a27b2cd053a (patch)
tree8ccd2b6eb8ddaacb86e56baf2fe4c463c2b783ce
parent3a982b8becf9b06a8e9ed772bb0e3912a5056254 (diff)
downloadchef-d8b3f05774613c949c8ed33a48122a27b2cd053a.tar.gz
add more unit actions
-rw-r--r--lib/chef/provider/systemd_unit.rb18
-rw-r--r--lib/chef/resource/systemd_unit.rb4
-rw-r--r--spec/unit/provider/systemd_unit_spec.rb63
3 files changed, 84 insertions, 1 deletions
diff --git a/lib/chef/provider/systemd_unit.rb b/lib/chef/provider/systemd_unit.rb
index db71a6c234..3e6c2d3171 100644
--- a/lib/chef/provider/systemd_unit.rb
+++ b/lib/chef/provider/systemd_unit.rb
@@ -133,6 +133,24 @@ class Chef
end
end
+ def action_try_restart
+ converge_by("try-restarting unit: #{new_resource.name}") do
+ systemctl_execute!("try-restart", new_resource.name)
+ end
+ end
+
+ def action_reload_or_restart
+ converge_by("reload-or-restarting unit: #{new_resource.name}") do
+ systemctl_execute!("reload-or-restart", new_resource.name)
+ end
+ end
+
+ def action_reload_or_try_restart
+ converge_by("reload-or-try-restarting unit: #{new_resource.name}") do
+ systemctl_execute!("reload-or-try-restart", new_resource.name)
+ end
+ end
+
def active?
systemctl_execute("is-active", new_resource.name).exitstatus == 0
end
diff --git a/lib/chef/resource/systemd_unit.rb b/lib/chef/resource/systemd_unit.rb
index 525e9ab35e..688f2e9dcd 100644
--- a/lib/chef/resource/systemd_unit.rb
+++ b/lib/chef/resource/systemd_unit.rb
@@ -29,7 +29,9 @@ class Chef
:enable, :disable,
:mask, :unmask,
:start, :stop,
- :restart, :reload
+ :restart, :reload,
+ :try_restart, :reload_or_restart,
+ :reload_or_try_restart
property :enabled, [TrueClass, FalseClass]
property :active, [TrueClass, FalseClass]
diff --git a/spec/unit/provider/systemd_unit_spec.rb b/spec/unit/provider/systemd_unit_spec.rb
index e71885f32d..a76f9e433a 100644
--- a/spec/unit/provider/systemd_unit_spec.rb
+++ b/spec/unit/provider/systemd_unit_spec.rb
@@ -629,6 +629,69 @@ describe Chef::Provider::SystemdUnit do
end
end
+ describe "try-restarts the unit" do
+ context "when a user is specified" do
+ it "try-restarts the unit" do
+ current_resource.user(user_name)
+ expect(provider).to receive(:shell_out_with_systems_locale!)
+ .with("#{systemctl_path} --user try-restart #{unit_name}", user_cmd_opts)
+ .and_return(shell_out_success)
+ provider.action_try_restart
+ end
+ end
+
+ context "when no user is specified" do
+ it "try-restarts the unit" do
+ expect(provider).to receive(:shell_out_with_systems_locale!)
+ .with("#{systemctl_path} --system try-restart #{unit_name}", {})
+ .and_return(shell_out_success)
+ provider.action_try_restart
+ end
+ end
+ end
+
+ describe "reload-or-restarts the unit" do
+ context "when a user is specified" do
+ it "reload-or-restarts the unit" do
+ current_resource.user(user_name)
+ expect(provider).to receive(:shell_out_with_systems_locale!)
+ .with("#{systemctl_path} --user reload-or-restart #{unit_name}", user_cmd_opts)
+ .and_return(shell_out_success)
+ provider.action_reload_or_restart
+ end
+ end
+
+ context "when no user is specified" do
+ it "reload-or-restarts the unit" do
+ expect(provider).to receive(:shell_out_with_systems_locale!)
+ .with("#{systemctl_path} --system reload-or-restart #{unit_name}", {})
+ .and_return(shell_out_success)
+ provider.action_reload_or_restart
+ end
+ end
+ end
+
+ describe "reload-or-try-restarts the unit" do
+ context "when a user is specified" do
+ it "reload-or-try-restarts the unit" do
+ current_resource.user(user_name)
+ expect(provider).to receive(:shell_out_with_systems_locale!)
+ .with("#{systemctl_path} --user reload-or-try-restart #{unit_name}", user_cmd_opts)
+ .and_return(shell_out_success)
+ provider.action_reload_or_try_restart
+ end
+ end
+
+ context "when no user is specified" do
+ it "reload-or-try-restarts the unit" do
+ expect(provider).to receive(:shell_out_with_systems_locale!)
+ .with("#{systemctl_path} --system reload-or-try-restart #{unit_name}", {})
+ .and_return(shell_out_success)
+ provider.action_reload_or_try_restart
+ end
+ end
+ end
+
describe "#active?" do
before(:each) do
provider.current_resource = current_resource