From 59ac912a4d6052574fca91159fb58c9179362a59 Mon Sep 17 00:00:00 2001 From: Dan Sajner Date: Mon, 11 Dec 2017 08:48:25 -0500 Subject: [PATCH 1/3] Add support for custom systemd file --- manifests/config.pp | 19 ++++++++++--------- manifests/params.pp | 6 +++--- .../statsd-init-rhel.erb | 0 .../statsd-systemd.erb | 7 ++++++- .../statsd-upstart.erb | 0 5 files changed, 19 insertions(+), 13 deletions(-) rename files/statsd-init-rhel => templates/statsd-init-rhel.erb (100%) rename files/statsd-systemd => templates/statsd-systemd.erb (54%) rename files/statsd-upstart => templates/statsd-upstart.erb (100%) diff --git a/manifests/config.pp b/manifests/config.pp index de76226..7371079 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -64,11 +64,12 @@ $repeaterProtocol = $statsd::repeaterProtocol, $config = $statsd::config, - $env_append = $statsd::env_append, - $nodejs_bin = $statsd::nodejs_bin, - $npm_bin = $statsd::npm_bin, - $statsjs = "${statsd::node_module_dir}/statsd/stats.js", - $logfile = $statsd::logfile, + $env_append = $statsd::env_append, + $nodejs_bin = $statsd::nodejs_bin, + $npm_bin = $statsd::npm_bin, + $statsjs = "${statsd::node_module_dir}/statsd/stats.js", + $logfile = $statsd::logfile, + $init_sysconfig = $statsd::init_sysconfig ) { file { '/etc/statsd': @@ -85,10 +86,10 @@ } file { $statsd::init_location: - source => $statsd::init_script, - mode => $statsd::init_mode, - owner => 'root', - group => 'root', + content => template($statsd::init_script), + mode => $statsd::init_mode, + owner => 'root', + group => 'root', } file { $statsd::init_sysconfig: diff --git a/manifests/params.pp b/manifests/params.pp index 630fd28..e92953f 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -96,7 +96,7 @@ $init_sysconfig = '/etc/sysconfig/statsd' $init_mode = '0755' $init_provider = 'redhat' - $init_script = 'puppet:///modules/statsd/statsd-init-rhel' + $init_script = 'statsd/statsd-init-rhel.erb' } 'Debian': { if $::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemmajrelease, '16') < 0 { @@ -104,13 +104,13 @@ $init_sysconfig = '/etc/default/statsd' $init_mode = '0644' $init_provider = 'upstart' - $init_script = 'puppet:///modules/statsd/statsd-upstart' + $init_script = 'statsd/statsd-upstart.erb' } else { $init_location = '/lib/systemd/system/statsd.service' $init_sysconfig = '/etc/default/statsd' $init_mode = '0644' $init_provider = 'systemd' - $init_script = 'puppet:///modules/statsd/statsd-systemd' + $init_script = 'statsd/statsd-systemd.erb' } } default: { diff --git a/files/statsd-init-rhel b/templates/statsd-init-rhel.erb similarity index 100% rename from files/statsd-init-rhel rename to templates/statsd-init-rhel.erb diff --git a/files/statsd-systemd b/templates/statsd-systemd.erb similarity index 54% rename from files/statsd-systemd rename to templates/statsd-systemd.erb index 5cef74d..d3e0b2c 100644 --- a/files/statsd-systemd +++ b/templates/statsd-systemd.erb @@ -5,7 +5,12 @@ Wants=network.target [Service] Type=simple -ExecStart=/usr/bin/nodejs /usr/local/lib/node_modules/statsd/stats.js /etc/statsd/localConfig.js +EnvironmentFile=<%= @init_sysconfig %> +<%- + env_string = "" + @env_append.each { |x| env_string << "#{x} -- " } +-%> +ExecStart=<%= env_string %><%= @nodejs_bin %> $STATSJS $STATSD_CONFIG Restart=on-failure RestartSec=10 diff --git a/files/statsd-upstart b/templates/statsd-upstart.erb similarity index 100% rename from files/statsd-upstart rename to templates/statsd-upstart.erb From 643587bdd936011d9115a57f357f8bf638ad5ae4 Mon Sep 17 00:00:00 2001 From: Dan Sajner Date: Mon, 11 Dec 2017 15:19:23 -0500 Subject: [PATCH 2/3] Add an exec to reload systemctl daemon --- manifests/config.pp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/manifests/config.pp b/manifests/config.pp index 7371079..5867642 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -69,6 +69,7 @@ $npm_bin = $statsd::npm_bin, $statsjs = "${statsd::node_module_dir}/statsd/stats.js", $logfile = $statsd::logfile, + $init_provider = $statsd::init_provider $init_sysconfig = $statsd::init_sysconfig ) { @@ -85,11 +86,23 @@ group => 'root', } + exec { 'statsd-systemctl-reload': + command => 'systemctl daemon-reload', + path => $::path, + refreshonly => true, + } + + $_notify = $init_provider ? { + /systemd/ => 'Exec[statsd-systemctl-reload]', + default => undef + } + file { $statsd::init_location: content => template($statsd::init_script), mode => $statsd::init_mode, owner => 'root', group => 'root', + notify => $_notify } file { $statsd::init_sysconfig: From 461d6fa8f363954455a58d06bb8282c1abebe28e Mon Sep 17 00:00:00 2001 From: Dan Sajner Date: Mon, 11 Dec 2017 15:25:11 -0500 Subject: [PATCH 3/3] Fix syntax error --- manifests/config.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/config.pp b/manifests/config.pp index 5867642..865df21 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -69,7 +69,7 @@ $npm_bin = $statsd::npm_bin, $statsjs = "${statsd::node_module_dir}/statsd/stats.js", $logfile = $statsd::logfile, - $init_provider = $statsd::init_provider + $init_provider = $statsd::init_provider, $init_sysconfig = $statsd::init_sysconfig ) {