Skip to content

Commit

Permalink
Adding an override to daemon.pp which allows for a custom daemon bina…
Browse files Browse the repository at this point in the history
…ry name.
  • Loading branch information
dudemcbacon committed Dec 7, 2018
1 parent 4083f66 commit 9c31292
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 7 deletions.
4 changes: 4 additions & 0 deletions manifests/daemon.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
# [*bin_dir*]
# Directory where binaries are located
#
# [*bin_name*]
# The name of the binary to execute
#
# [*package_name*]
# The binary package name
#
Expand Down Expand Up @@ -64,6 +67,7 @@
String $os = $prometheus::os,
String $arch = $prometheus::real_arch,
Stdlib::Absolutepath $bin_dir = $prometheus::bin_dir,
String $bin_name = $name,
Optional[String] $package_name = undef,
String $package_ensure = 'installed',
Boolean $manage_user = true,
Expand Down
49 changes: 49 additions & 0 deletions spec/defines/daemon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@
%r{USER=smurf_user\n}
)
}

context 'with overidden bin_name' do
let(:params) do
parameters.merge(bin_name: 'notsmurf_exporter')
end

it {
is_expected.to contain_file('/etc/init.d/smurf_exporter').with_content(
%r{DAEMON=/usr/local/bin/notsmurf_exporter}
)
}
end
elsif ['centos-6-x86_64', 'redhat-6-x86_64'].include?(os)
# init_style = 'sysv'

Expand All @@ -107,6 +119,18 @@
%r{daemon --user=smurf_user \\\n --pidfile="\$PID_FILE" \\\n "\$DAEMON" '' >> "\$LOG_FILE" 2>&1 &}
)
}

context 'with overidden bin_name' do
let(:params) do
parameters.merge(bin_name: 'notsmurf_exporter')
end

it {
is_expected.to contain_file('/etc/init.d/smurf_exporter').with_content(
%r{DAEMON=/usr/local/bin/notsmurf_exporter}
)
}
end
elsif ['centos-7-x86_64', 'debian-8-x86_64', 'debian-9-x86_64', 'redhat-7-x86_64', 'ubuntu-16.04-x86_64', 'ubuntu-18.04-x86_64', 'archlinux-4-x86_64'].include?(os)
# init_style = 'systemd'

Expand All @@ -121,6 +145,19 @@
%r{ExecStart=/usr/local/bin/smurf_exporter\n\nExecReload=}
)
}

context 'with overidden bin_name' do
let(:params) do
parameters.merge(bin_name: 'notsmurf_exporter')
end

it {
is_expected.to contain_systemd__unit_file('smurf_exporter.service').with_content(
%r{ExecStart=/usr/local/bin/notsmurf_exporter}
)
}
end

elsif ['ubuntu-14.04-x86_64'].include?(os)
# init_style = 'upstart'

Expand All @@ -145,6 +182,18 @@
'mode' => '0755'
)
}

context 'with overidden bin_name' do
let(:params) do
parameters.merge(bin_name: 'notsmurf_exporter')
end

it {
is_expected.to contain_file('/etc/init/smurf_exporter.conf').with_content(
%r{env DAEMON=/usr/local/bin/notsmurf_exporter}
)
}
end
else
it {
is_expected.to raise_error(Puppet::Error, %r{I don't know how to create an init script for style})
Expand Down
2 changes: 1 addition & 1 deletion templates/daemon.debian.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
PATH=/usr/sbin:/usr/bin:/sbin:/bin:<%= @bin_dir %>
DESC="Prometheus <%= @name %>"
NAME=<%= @name %>
DAEMON=<%= @bin_dir %>/$NAME
DAEMON=<%= @bin_dir %>/<%= @bin_name %>
PIDFILE=/var/run/$NAME/$NAME.pid
<%- require 'shellwords' -%>
DAEMON_ARGS=<%= Shellwords.escape(@options) %>
Expand Down
2 changes: 1 addition & 1 deletion templates/daemon.env.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<% @env_vars.each do |key, value| -%>
<%= key %>="<%= value %>"
<% end -%>
<% end -%>
2 changes: 1 addition & 1 deletion templates/daemon.launchd.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</dict>
<key>ProgramArguments</key>
<array>
<string><%= @bin_dir %>/<%= @name %></string>
<string><%= @bin_dir %>/<%= @bin_name %></string>
<% require 'shellwords' %>
<% for extra_option in Shellwords.split(@options) %>
<string><%= extra_option %></string>
Expand Down
2 changes: 1 addition & 1 deletion templates/daemon.sles.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

rc_reset

<%= @name %>_BIN=<%= @bin_dir %>/<%= @name %>
<%= @name %>_BIN=<%= @bin_dir %>/<%= @bin_name %>
LOG_FILE=/var/log/<%= @name %>


Expand Down
2 changes: 1 addition & 1 deletion templates/daemon.systemd.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ User=<%= @user %>
Group=<%= @group %>
EnvironmentFile=<%= @env_file_path %>/<%= @name%>
<%- require 'shellwords' -%>
ExecStart=<%= @bin_dir %>/<%= @name %><% for option in Shellwords.split(@options) %> \
ExecStart=<%= @bin_dir %>/<%= @bin_name %><% for option in Shellwords.split(@options) %> \
<%= option -%>
<% end %>

Expand Down
2 changes: 1 addition & 1 deletion templates/daemon.sysv.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# Source function library.
. /etc/init.d/functions

DAEMON=<%= @bin_dir %>/<%= @name %>
DAEMON=<%= @bin_dir %>/<%= @bin_name %>
PID_FILE=/var/run/<%= @name %>/<%= @name %>.pid
LOG_FILE=/var/log/<%= @name %>

Expand Down
2 changes: 1 addition & 1 deletion templates/daemon.upstart.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description "Prometheus <%= @name %>"
start on runlevel [2345]
stop on runlevel [06]

env DAEMON=<%= @bin_dir %>/<%= @name %>
env DAEMON=<%= @bin_dir %>/<%= @bin_name %>
env USER=<%= @user %>
env GROUP=<%= @group %>
env DEFAULTS=/etc/default/<%= @name %>
Expand Down

0 comments on commit 9c31292

Please sign in to comment.