Skip to content

Commit

Permalink
Add upstart init support for ubuntu.
Browse files Browse the repository at this point in the history
Add upstart config file for ubuntu, set it as default. Standard init
script is still supported when explicitly selected.
  • Loading branch information
gbagnoli committed May 24, 2015
1 parent 305db97 commit 119e3af
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------------
Expand Down
6 changes: 5 additions & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
11 changes: 11 additions & 0 deletions recipes/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
24 changes: 24 additions & 0 deletions spec/unit/recipes/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
14 changes: 14 additions & 0 deletions templates/default/upstart/prometheus.service.erb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 119e3af

Please sign in to comment.