diff --git a/CHANGELOG.md b/CHANGELOG.md index 506beb4..1a67b44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. ## [Unreleased][unreleased] +### Added +- Added upstart init for ubuntu platform. ## [0.5.1] - 2015-03-25 ### Changed diff --git a/README.md b/README.md index c09f9b6..9701650 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ a user-defined location. ### service The `service` recipe configures Prometheus to run under a process supervisor. Default supervisors are chosen based on distribution. Currently supported -supervisors are init, runit, systemd and bluepill. (Upstart coming soon) +supervisors are init, runit, systemd, upstart and bluepill. Resource/Provider ----------------- diff --git a/attributes/default.rb b/attributes/default.rb index 809cfd6..60f0e6d 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -18,7 +18,11 @@ # Init style. case node['platform_family'] when 'debian' - default['prometheus']['init_style'] = 'runit' + if node['platform'] == 'ubuntu' + default['prometheus']['init_style'] = 'upstart' + else + default['prometheus']['init_style'] = 'runit' + end when 'rhel', 'fedora' if node['platform_version'].to_i >= 7 default['prometheus']['init_style'] = 'systemd' diff --git a/recipes/service.rb b/recipes/service.rb index 63fb698..a8492d2 100644 --- a/recipes/service.rb +++ b/recipes/service.rb @@ -58,6 +58,17 @@ action [:enable, :start] end # rubocop:enable Style/HashSyntax +when 'upstart' + template '/etc/init/prometheus.conf' do + source 'upstart/prometheus.service.erb' + mode 0644 + notifies :restart, 'service[prometheus]', :delayed + end + + service 'prometheus' do + provider Chef::Provider::Service::Upstart + action [:enable, :start] + end else template '/etc/init.d/prometheus' do source 'prometheus.erb' diff --git a/spec/unit/recipes/default_spec.rb b/spec/unit/recipes/default_spec.rb index 1571e4f..31c5103 100644 --- a/spec/unit/recipes/default_spec.rb +++ b/spec/unit/recipes/default_spec.rb @@ -128,6 +128,18 @@ expect(chef_run).to render_file('/etc/systemd/system/prometheus.service') end end + + context 'upstart' do + let(:chef_run) do + ChefSpec::SoloRunner.new(file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['init_style'] = 'upstart' + end.converge(described_recipe) + end + + it 'renders an upstart job configuration file' do + expect(chef_run).to render_file('/etc/init/prometheus.conf') + end + end end # Test for binary.rb @@ -219,5 +231,17 @@ expect(chef_run).to render_file('/etc/systemd/system/prometheus.service') end end + context 'upstart' do + let(:chef_run) do + ChefSpec::SoloRunner.new(file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['init_style'] = 'upstart' + node.set['prometheus']['install_method'] = 'binary' + end.converge(described_recipe) + end + + it 'renders an upstart job configuration file' do + expect(chef_run).to render_file('/etc/init/prometheus.conf') + end + end end end diff --git a/templates/default/upstart/prometheus.service.erb b/templates/default/upstart/prometheus.service.erb new file mode 100644 index 0000000..820bf9e --- /dev/null +++ b/templates/default/upstart/prometheus.service.erb @@ -0,0 +1,14 @@ +description "Prometheus" +start on (local-filesystems and net-device-up IFACE!=lo) +stop on runlevel [016] + +respawn +env GOMAXPROCS=<%= node['cpu']['total'] %> +setuid <%= node['prometheus']['user'] %> +setgid <%= node['prometheus']['user'] %> + +script + exec >> "<%= node['prometheus']['log_dir'] %>/prometheus.log" + exec 2>&1 + exec <%= node['prometheus']['binary'] %> <%= generate_flags %> +end script