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

Implemented SystemD support #69

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,39 @@
$gunicorn_bin = 'gunicorn_django'
}

file {
[
'/etc/init.d/carbon-aggregator',
'/etc/init.d/carbon-cache',
'/etc/init.d/graphite-web'
]:
ensure => link,
target => '/lib/init/upstart-job',
}

file { '/etc/init/carbon-aggregator.conf':
if $::graphite::service_provider == 'upstart' {
file {
[
'/etc/init.d/carbon-aggregator',
'/etc/init.d/carbon-cache',
'/etc/init.d/graphite-web'
]:
ensure => link,
target => '/lib/init/upstart-job',
}

$base_service_path = '/etc/init'
$service_suffix = 'conf'
} elsif $::graphite::service_provider == 'systemd' {
$base_service_path = '/etc/systemd/system'
$service_suffix = 'service'
}

file { "${base_service_path}/carbon-aggregator.${service_suffix}":
ensure => present,
content => template('graphite/upstart/carbon-aggregator.conf'),
content => template("graphite/${::graphite::service_provider}/carbon-aggregator.${service_suffix}"),
mode => '0444',
}

file { '/etc/init/carbon-cache.conf':
file { "${base_service_path}/carbon-cache.${service_suffix}":
ensure => present,
content => template('graphite/upstart/carbon-cache.conf'),
content => template("graphite/${::graphite::service_provider}/carbon-cache.${service_suffix}"),
mode => '0444',
}

file { '/etc/init/graphite-web.conf':
file { "${base_service_path}/graphite-web.${service_suffix}":
ensure => present,
content => template('graphite/upstart/graphite-web.conf'),
content => template("graphite/${::graphite::service_provider}/graphite-web.${service_suffix}"),
mode => '0444',
}

Expand Down Expand Up @@ -138,8 +146,8 @@
refreshonly => true,
require => File["${root_dir}/storage"],
subscribe => [
File['/etc/init/graphite-web.conf'],
File['/etc/init/carbon-cache.conf'],
File["${base_service_path}/graphite-web.${service_suffix}"],
File["${base_service_path}/carbon-cache.${service_suffix}"],
File["${root_dir}/storage"],
File["${root_dir}/webapp/graphite"],
],
Expand Down
4 changes: 4 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
# [*memcache_hosts*]
# Optional: Array of memcached servers to use. Each should be ip:port
#
# [*service_provider*]
# Optional: String to use as a provider for the services (default: upstart)
#
class graphite(
$admin_password = $graphite::params::admin_password,
$bind_address = $graphite::params::bind_address,
Expand Down Expand Up @@ -124,6 +127,7 @@
$time_zone = $graphite::params::time_zone,
$django_secret_key = $graphite::params::django_secret_key,
$memcache_hosts = $graphite::params::memcache_hosts,
$service_provider = $graphite::params::service_provider,
) inherits graphite::params {
validate_string(
$admin_password,
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
$time_zone = 'UTC'
$django_secret_key = undef
$memcache_hosts = []
$service_provider = 'upstart'
}
6 changes: 3 additions & 3 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
ensure => $aggregator_ensure,
hasstatus => true,
hasrestart => false,
provider => upstart,
provider => $::graphite::service_provider,
}
-> service { 'carbon-cache':
ensure => running,
hasstatus => true,
hasrestart => false,
provider => upstart,
provider => $::graphite::service_provider,
}

service { 'graphite-web':
ensure => running,
hasstatus => true,
hasrestart => false,
provider => upstart,
provider => $::graphite::service_provider,
}
}
172 changes: 113 additions & 59 deletions spec/classes/graphite/graphite__config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,121 @@
describe 'graphite', :type => :class do
let(:facts) { {:osfamily => 'Debian'} }

it { should contain_file('/etc/init.d/carbon-aggregator').with_ensure('link').
with_target('/lib/init/upstart-job') }
it { should contain_file('/etc/init.d/carbon-cache').with_ensure('link').
with_target('/lib/init/upstart-job') }
it { should contain_file('/etc/init.d/graphite-web').with_ensure('link').
with_target('/lib/init/upstart-job') }

it do should contain_exec('set_graphite_ownership').with(
'before' => [ 'Service[graphite-web]', 'Service[carbon-cache]' ],
'refreshonly' => 'true'
)
end

context "root_dir" do
let(:params) {{ :root_dir => '/this/is/root' }}

describe "intial_data.json" do
it { should contain_file('/this/is/root/webapp/graphite/initial_data.json') }
end

describe "carbon-aggregator.conf" do
it { should contain_file('/etc/init/carbon-aggregator.conf').with_ensure('present').
with_content(/setuid www-data/).
with_content(/setgid www-data/).
with_content(/chdir '\/this\/is\/root'/).
with_content(/GRAPHITE_STORAGE_DIR='\/this\/is\/root\/storage'/).
with_content(/GRAPHITE_CONF_DIR='\/this\/is\/root\/conf'/).
with_content(/exec \/this\/is\/root\/bin\/carbon-aggregator.py/).
with_mode('0444') }
end

describe "carbon-cache.conf" do
it { should contain_file('/etc/init/carbon-cache.conf').with_ensure('present').
with_content(/setuid www-data/).
with_content(/setgid www-data/).
with_content(/chdir '\/this\/is\/root'/).
with_content(/GRAPHITE_STORAGE_DIR='\/this\/is\/root\/storage'/).
with_content(/GRAPHITE_CONF_DIR='\/this\/is\/root\/conf'/).
with_content(/exec \/this\/is\/root\/bin\/carbon-cache.py/).
with_mode('0444') }
end

describe "graphite-web.conf" do
it { should contain_file('/etc/init/graphite-web.conf').with_ensure('present').
with_content(/setuid www-data/).
with_content(/setgid www-data/).
with_content(/chdir '\/this\/is\/root\/webapp'/).
with_content(/PYTHONPATH='\/this\/is\/root\/lib:\/this\/is\/root\/webapp'/).
with_content(/GRAPHITE_STORAGE_DIR='\/this\/is\/root\/storage'/).
with_content(/GRAPHITE_CONF_DIR='\/this\/is\/root\/conf'/).
with_content(/-b127\.0\.0\.1:8000/).
with_mode('0444') }
context 'upstart_provider' do
it { should contain_file('/etc/init.d/carbon-aggregator').with_ensure('link').
with_target('/lib/init/upstart-job') }
it { should contain_file('/etc/init.d/carbon-cache').with_ensure('link').
with_target('/lib/init/upstart-job') }
it { should contain_file('/etc/init.d/graphite-web').with_ensure('link').
with_target('/lib/init/upstart-job') }

it do should contain_exec('set_graphite_ownership').with(
'before' => [ 'Service[graphite-web]', 'Service[carbon-cache]' ],
'refreshonly' => 'true'
)
end

context "root_dir" do
let(:params) {{ :root_dir => '/this/is/root' }}

describe "intial_data.json" do
it { should contain_file('/this/is/root/webapp/graphite/initial_data.json') }
end

describe "carbon-aggregator.conf" do
it { should contain_file('/etc/init/carbon-aggregator.conf').with_ensure('present').
with_content(/setuid www-data/).
with_content(/setgid www-data/).
with_content(/chdir '\/this\/is\/root'/).
with_content(/GRAPHITE_STORAGE_DIR='\/this\/is\/root\/storage'/).
with_content(/GRAPHITE_CONF_DIR='\/this\/is\/root\/conf'/).
with_content(/exec \/this\/is\/root\/bin\/carbon-aggregator.py/).
with_mode('0444') }
end

describe "carbon-cache.conf" do
it { should contain_file('/etc/init/carbon-cache.conf').with_ensure('present').
with_content(/setuid www-data/).
with_content(/setgid www-data/).
with_content(/chdir '\/this\/is\/root'/).
with_content(/GRAPHITE_STORAGE_DIR='\/this\/is\/root\/storage'/).
with_content(/GRAPHITE_CONF_DIR='\/this\/is\/root\/conf'/).
with_content(/exec \/this\/is\/root\/bin\/carbon-cache.py/).
with_mode('0444') }
end

describe "graphite-web.conf" do
it { should contain_file('/etc/init/graphite-web.conf').with_ensure('present').
with_content(/setuid www-data/).
with_content(/setgid www-data/).
with_content(/chdir '\/this\/is\/root\/webapp'/).
with_content(/PYTHONPATH='\/this\/is\/root\/lib:\/this\/is\/root\/webapp'/).
with_content(/GRAPHITE_STORAGE_DIR='\/this\/is\/root\/storage'/).
with_content(/GRAPHITE_CONF_DIR='\/this\/is\/root\/conf'/).
with_content(/-b127\.0\.0\.1:8000/).
with_mode('0444') }
end

describe "carbon.conf" do
it { should contain_file('/this/is/root/conf/carbon.conf').
with_content(/USER = www-data/).
with_content(/MAX_CACHE_SIZE = inf/).
with_content(/MAX_UPDATES_PER_SECOND = inf/).
with_content(/MAX_CREATES_PER_MINUTE = inf/).
with_content(/LOCAL_DATA_DIR = \/this\/is\/root\/storage\/whisper\//) }
end
end
end

describe "carbon.conf" do
it { should contain_file('/this/is/root/conf/carbon.conf').
with_content(/USER = www-data/).
with_content(/MAX_CACHE_SIZE = inf/).
with_content(/MAX_UPDATES_PER_SECOND = inf/).
with_content(/MAX_CREATES_PER_MINUTE = inf/).
with_content(/LOCAL_DATA_DIR = \/this\/is\/root\/storage\/whisper\//) }
context "systemd_provider" do
let(:params) {{ :service_provider => 'systemd' }}

it { should_not contain_file('/etc/init.d/carbon-aggregator').with_ensure('link').
with_target('/lib/init/upstart-job') }
it { should_not contain_file('/etc/init.d/carbon-cache').with_ensure('link').
with_target('/lib/init/upstart-job') }
it { should_not contain_file('/etc/init.d/graphite-web').with_ensure('link').
with_target('/lib/init/upstart-job') }

context "root_dir" do
let(:params) {{ :root_dir => '/this/is/root' }}

describe "carbon-aggregator.service" do
it { should contain_file('/etc/systemd/system/carbon-aggregator.service').
with_ensure('present').
with_content(/User=www-data/).
with_content(/Group=www-data/).
with_content(/WorkingDirectory=\/this\/is\/root/).
with_content(/Environment=GRAPHITE_STORAGE_DIR=\/this\/is\/root\/storage/).
with_content(/Environment=GRAPHITE_CONF_DIR=\/this\/is\/root\/conf/).
with_content(/ExecStart=\/this\/is\/root\/bin\/carbon-aggregator.py/).
with_mode('0444') }
end

describe "carbon-cache.service" do
it { should contain_file('/etc/systemd/system/carbon-cache.service').
with_ensure('present').
with_content(/User=www-data/).
with_content(/Group=www-data/).
with_content(/WorkingDirectory=\/this\/is\/root/).
with_content(/Environment=GRAPHITE_STORAGE_DIR=\/this\/is\/root\/storage/).
with_content(/Environment=GRAPHITE_CONF_DIR=\/this\/is\/root\/conf/).
with_content(/ExecStart=\/this\/is\/root\/bin\/carbon-cache.py/).
with_mode('0444') }
end

describe "graphite-web.service" do
it { should contain_file('/etc/systemd/system/graphite-web.service').
with_ensure('present').
with_content(/User=www-data/).
with_content(/Group=www-data/).
with_content(/WorkingDirectory=\/this\/is\/root/).
with_content(/Environment=PYTHONPATH=\/this\/is\/root\/lib:\/this\/is\/root\/webapp/).
with_content(/Environment=GRAPHITE_STORAGE_DIR=\/this\/is\/root\/storage/).
with_content(/Environment=GRAPHITE_CONF_DIR=\/this\/is\/root\/conf/).
with_content(/-b127\.0\.0\.1:8000/).
with_mode('0444') }
end
end
end

Expand Down
24 changes: 24 additions & 0 deletions templates/systemd/carbon-aggregator.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[Unit]
Description=Carbon aggregator service for Graphite
Wants=network-online.target
Wants=local-fs.target

[Install]
WantedBy=multi-user.target

[Service]
User=<%= @user %>
Group=<%= @group %>

Restart=on-failure

WorkingDirectory=<%= @root_dir %>

Environment=GRAPHITE_STORAGE_DIR=<%= @root_dir %>/storage
Environment=GRAPHITE_CONF_DIR=<%= @root_dir %>/conf

ExecStart=<%= @root_dir %>/bin/carbon-aggregator.py \
<% if @aggregation_rules_ensure == 'present' -%>
--rules='<%= @root_dir %>/conf/aggregation-rules.conf' \
<% end -%>
--debug start
22 changes: 22 additions & 0 deletions templates/systemd/carbon-cache.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[Unit]
Description=Carbon cache service for Graphite
Wants=network-online.target
Wants=local-fs.target

[Install]
WantedBy=multi-user.target

[Service]
User=<%= @user %>
Group=<%= @group %>

Restart=on-failure

WorkingDirectory=<%= @root_dir %>

Environment=GRAPHITE_STORAGE_DIR=<%= @root_dir %>/storage
Environment=GRAPHITE_CONF_DIR=<%= @root_dir %>/conf

ExecStart=<%= @root_dir %>/bin/carbon-cache.py --debug start

PIDFile=<%= @root_dir %>/storage/carbon-cache-a.pid
21 changes: 21 additions & 0 deletions templates/systemd/graphite-web.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[Unit]
Description=Graphite realtime graphing engine
Wants=network-online.target
Wants=local-fs.target

[Install]
WantedBy=multi-user.target

[Service]
User=<%= @user %>
Group=<%= @group %>

Restart=on-failure

WorkingDirectory=<%= @root_dir %>/webapp

Environment=GRAPHITE_STORAGE_DIR=<%= @root_dir %>/storage
Environment=GRAPHITE_CONF_DIR=<%= @root_dir %>/conf
Environment=PYTHONPATH=<%= @root_dir %>/lib:<%= @root_dir %>/webapp

ExecStart=<%= @gunicorn_bin %> -b<%= @bind_address -%>:<%= @port %> -w<%= @worker_processes -%> graphite/settings.py