From 32bbb0801a4968e9c553eab31ed07aeccd365854 Mon Sep 17 00:00:00 2001 From: Phil Cohen Date: Sat, 22 Nov 2014 17:16:33 -0800 Subject: [PATCH] support `upstart` service supervisor on ubuntu --- files/default/newrelic-sysmond.conf | 10 ++++++++ recipes/default.rb | 16 ++++++++++++ spec/default_spec.rb | 39 +++++++++++++++++++++++++---- 3 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 files/default/newrelic-sysmond.conf diff --git a/files/default/newrelic-sysmond.conf b/files/default/newrelic-sysmond.conf new file mode 100644 index 0000000..661d322 --- /dev/null +++ b/files/default/newrelic-sysmond.conf @@ -0,0 +1,10 @@ +description "Start New Relic Server Monitor" + +start on [2345] +stop on runlevel [!2345] + +respawn +console log +respawn limit 5 20 + +exec start-stop-daemon --start --chuid newrelic --group newrelic --exec /usr/sbin/nrsysmond -- -f -c /etc/newrelic/nrsysmond.cfg diff --git a/recipes/default.rb b/recipes/default.rb index 44d1496..89bddb2 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -48,6 +48,19 @@ not_if { node["new_relic"]["pidfile"].empty? } end +# replace init with upstart on ubuntu +if platform?("ubuntu") + file "/etc/init.d/newrelic-sysmond" do + action :delete + end + + cookbook_file "/etc/init/newrelic-sysmond.conf" do + owner "root" + group "root" + end +end + +# setup the main configuration file template "/etc/newrelic/nrsysmond.cfg" do source "nrsysmond.cfg.erb" owner "root" @@ -56,6 +69,9 @@ notifies :restart, "service[newrelic-sysmond]" end +# manage the service service "newrelic-sysmond" do + provider Chef::Provider::Service::Upstart if platform?("ubuntu") + supports status: true, restart: true action [:enable, :start] end diff --git a/spec/default_spec.rb b/spec/default_spec.rb index 10bf14f..f909dff 100644 --- a/spec/default_spec.rb +++ b/spec/default_spec.rb @@ -1,6 +1,18 @@ require "spec_helper" describe "newrelic-sysmond::default" do + let(:config_file) do + "/etc/newrelic/nrsysmond.cfg" + end + + let(:init_script) do + "/etc/init.d/newrelic-sysmond" + end + + let(:upstart_script) do + "/etc/init/newrelic-sysmond.conf" + end + # no license key == no action context "with no `license_key` attribute" do let(:chef_run) { ChefSpec::SoloRunner.new.converge(described_recipe) } @@ -19,7 +31,7 @@ end it "does not create the configuration file" do - expect(chef_run).to_not create_template("/etc/newrelic/nrsysmond.cfg") + expect(chef_run).to_not create_template(config_file) end end @@ -34,6 +46,17 @@ it "sets up an apt repository" do expect(chef_run).to add_apt_repository("newrelic") end + + it "removes the default initscript" do + expect(chef_run).to delete_file(init_script) + end + + it "provides an upstart initscript" do + expect(chef_run).to create_cookbook_file(upstart_script).with( + owner: "root", + group: "root" + ) + end end # rhel family setup @@ -47,6 +70,14 @@ it "sets up a yum repository" do expect(chef_run).to create_yum_repository("newrelic") end + + it "does not remove the default initscript" do + expect(chef_run).to_not delete_file(init_script) + end + + it "does not provide an upstart initscript" do + expect(chef_run).to_not create_cookbook_file(upstart_script) + end end # default recipe run @@ -78,7 +109,7 @@ end it "creates the configuration file" do - expect(chef_run).to create_template("/etc/newrelic/nrsysmond.cfg").with( + expect(chef_run).to create_template(config_file).with( source: "nrsysmond.cfg.erb", owner: "root", group: "newrelic", @@ -86,9 +117,7 @@ ) expect(chef_run).to( - render_file("/etc/newrelic/nrsysmond.cfg").with_content( - "license_key=abc123" - ) + render_file(config_file).with_content("license_key=abc123") ) end end