Gilles has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/399414 )

Change subject: Add ability to pass variables to systemd service template
......................................................................

Add ability to pass variables to systemd service template

Fixes issue with variable context seggregation and
the systemd service class.

Without this, the template cannot access variables
defined by classes calling systemd::service, which
seems to be a Puppet 4 breaking change.

Bug: T183374
Change-Id: I8a95385a314c78b74a5dd41b8548398b2f39a17a
---
A puppet/modules/statsd/templates/systemd/statsd.epp
D puppet/modules/statsd/templates/systemd/statsd.erb
M puppet/modules/systemd/manifests/service.pp
3 files changed, 39 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/vagrant 
refs/changes/14/399414/1

diff --git a/puppet/modules/statsd/templates/systemd/statsd.epp 
b/puppet/modules/statsd/templates/systemd/statsd.epp
new file mode 100644
index 0000000..59e7325
--- /dev/null
+++ b/puppet/modules/statsd/templates/systemd/statsd.epp
@@ -0,0 +1,16 @@
+[Unit]
+Description=statsd service
+Requires=mediawiki-ready.service
+After=mediawiki-ready.service
+
+[Service]
+Environment=NODE_PATH=<%= $dir %>/node_modules
+User=www-data
+Group=www-data
+SyslogIdentifier=statsd
+WorkingDirectory=<%= $dir %>
+ExecStart=/bin/sh -c '/usr/bin/nodejs stats.js <%= $dir %>/config.js > <%= 
$logdir %>/statsd.log'
+Restart=always
+
+[Install]
+WantedBy=multi-user.target
diff --git a/puppet/modules/statsd/templates/systemd/statsd.erb 
b/puppet/modules/statsd/templates/systemd/statsd.erb
deleted file mode 100644
index 5c58107..0000000
--- a/puppet/modules/statsd/templates/systemd/statsd.erb
+++ /dev/null
@@ -1,16 +0,0 @@
-[Unit]
-Description=statsd service
-Requires=mediawiki-ready.service
-After=mediawiki-ready.service
-
-[Service]
-Environment=NODE_PATH=<%= @dir %>/node_modules
-User=www-data
-Group=www-data
-SyslogIdentifier=statsd
-WorkingDirectory=<%= @dir %>
-ExecStart=/bin/sh -c '/usr/bin/nodejs stats.js <%= @dir %>/config.js > <%= 
@logdir %>/statsd.log'
-Restart=always
-
-[Install]
-WantedBy=multi-user.target
diff --git a/puppet/modules/systemd/manifests/service.pp 
b/puppet/modules/systemd/manifests/service.pp
index 3270f12..cda8297 100644
--- a/puppet/modules/systemd/manifests/service.pp
+++ b/puppet/modules/systemd/manifests/service.pp
@@ -29,16 +29,28 @@
 # [*service_params*]
 # A hash of parameters to applied to the Service resource. Default: {}
 #
+# [*template_variables*]
+# Variables to be exposed to the template. Default: {}
+#
+# [*epp_template*]
+# Whether or not the service template is EPP rather than ERB. Default: false
+#
 define systemd::service (
-    $ensure          = 'present',
-    $is_override     = false,
-    $refresh         = true,
-    $template_name   = $name,
-    $declare_service = true,
-    $service_params  = {},
+    $ensure             = 'present',
+    $is_override        = false,
+    $refresh            = true,
+    $template_name      = $name,
+    $declare_service    = true,
+    $service_params     = {},
+    $template_variables = {},
+    $epp_template       = false,
 ) {
     validate_ensure($ensure)
-    $unit_template = "${caller_module_name}/systemd/${template_name}.erb"
+    $unit_template = $epp_template ? {
+        true    => "${caller_module_name}/systemd/${template_name}.epp",
+        default => "${caller_module_name}/systemd/${template_name}.erb",
+    }
+
     $unit_path = $is_override ? {
         true    => 
"/etc/systemd/system/${name}.service.d/puppet-override.conf",
         default => "/lib/systemd/system/${name}.service",
@@ -59,7 +71,10 @@
         owner   => 'root',
         group   => 'root',
         mode    => '0444',
-        content => template($unit_template),
+        content => $epp_template ? {
+            true    => epp($unit_template, $template_variables),
+            default => template($unit_template),
+        },
     }
 
     exec { "systemd reload for ${name}":

-- 
To view, visit https://gerrit.wikimedia.org/r/399414
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8a95385a314c78b74a5dd41b8548398b2f39a17a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/vagrant
Gerrit-Branch: stretch-migration
Gerrit-Owner: Gilles <gdu...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to