<%-
	$depend_services = $depend_services_array.map |$s| { if $s =~ /\.[a-z]+$/ { $s }else { "${s}.service" } }
	$after = $sanitised_after_array.map |$s| { "${service_prefix}${s}.service" } +
		 $sanitised_depends_array.map |$s| { "${service_prefix}${s}.service"} +
		 $depend_services
	$wants = $sanitised_after_array.map |$a| { "${service_prefix}${a}.service" }
	$requires = $sanitised_depends_array.map |$d| { "${service_prefix}${d}.service" } +
		    $depend_services
-%>
# This file is managed by Puppet and local changes
# may be overwritten

[Unit]
Description=Daemon for <%= $title %>
After=<%= $after.unique.join(" ") %>
Wants=<%= $wants.unique.join(" ") %>
Requires=<%= $requires.unique.join(" ") %>
<%- if $have_systemd_v230 { -%>
StartLimitIntervalSec=20
StartLimitBurst=3
<% } -%>
<%- if $extra_systemd_parameters['Unit'] { -%>
	<%- $extra_systemd_parameters['Unit'].each |$key, $value| { %>
<%= $key %>=<%= $value %>
	<%- } -%>
<% } -%>

[Service]
Restart=<%= $systemd_restart %>
<%- unless $have_systemd_v230 { -%>
StartLimitInterval=20
StartLimitBurst=3
<% } -%>
TimeoutStartSec=0
RestartSec=5
Environment="HOME=/root"
<%- if $_syslog_identifier { -%>
SyslogIdentifier=<%= $_syslog_identifier %>
<% } -%>
<%- if $syslog_facility { -%>
SyslogFacility=<%= $syslog_facility %>
<% } -%>
ExecStart=/usr/local/bin/docker-run-<%= $sanitised_title %>-start.sh
ExecStop=-/usr/local/bin/docker-run-<%= $sanitised_title %>-stop.sh
<%- if $remain_after_exit { %>
RemainAfterExit=<%= $remain_after_exit %>
<% } -%>
<%- if $extra_systemd_parameters['Service'] { -%>
	<%- $extra_systemd_parameters['Service'].each |$key, $value| { -%>
<%= $key %>=<%= $value %>
	<%- } -%>
<% } -%>

[Install]
WantedBy=multi-user.target
<%- if $service_name { -%>
WantedBy=<%= $service_name %>.service
<% } -%>
<%- if $extra_systemd_parameters['Install'] { -%>
	<%- $extra_systemd_parameters['Install'].each |$key, $value| { -%>
<%= $key %>=<%= $value %>
	<%- } -%>
<% } -%>
