Skip to content
This repository has been archived by the owner on Jan 16, 2019. It is now read-only.

Commit

Permalink
support upstart service supervisor on ubuntu
Browse files Browse the repository at this point in the history
  • Loading branch information
phlipper committed Nov 23, 2014
1 parent 7182529 commit 32bbb08
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
10 changes: 10 additions & 0 deletions 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
16 changes: 16 additions & 0 deletions recipes/default.rb
Expand Up @@ -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"
Expand All @@ -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
39 changes: 34 additions & 5 deletions 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) }
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -78,17 +109,15 @@
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",
mode: "0640"
)

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
Expand Down

0 comments on commit 32bbb08

Please sign in to comment.