Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebase pdxcat/xinetd against new upstream #15

Merged
merged 9 commits into from Jul 30, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .fixtures.yml
@@ -1,3 +1,5 @@
fixtures:
repositories:
"stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib"
symlinks:
"xinetd": "#{source_dir}"
1 change: 1 addition & 0 deletions Modulefile
Expand Up @@ -6,3 +6,4 @@ license 'Apache License 2.0'
summary 'Puppet Labs Xinetd Module'
description 'Puppet module to configure xinetd services'
project_page 'https://github.com/puppetlabs/puppetlabs-xinetd'
dependency 'puppetlabs/stdlib', '>= 2.2.1'
45 changes: 35 additions & 10 deletions manifests/init.pp
Expand Up @@ -9,19 +9,44 @@
# server_args => '--daemon --config /etc/rsync.conf',
# }
#
class xinetd {
class xinetd (
$confdir = $xinetd::params::confdir,
$conffile = $xinetd::params::conffile,
$package_name = $xinetd::params::package_name,
$service_name = $xinetd::params::service_name
) inherits xinetd::params {

package { 'xinetd': }
File {
owner => 'root',
group => '0',
notify => Service[$service_name],
require => Package[$package_name],
}

file { $confdir:
ensure => directory,
mode => '0755',
}

file { '/etc/xinetd.conf':
source => 'puppet:///modules/xinetd/xinetd.conf',
# Template uses:
# $confdir
file { $conffile:
ensure => file,
mode => '0644',
content => template('xinetd/xinetd.conf.erb'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this has a template() call I like to comment # Template uses: and list the variables so I don't have to open the template to see what is going on.

}

service { 'xinetd':
ensure => running,
enable => true,
restart => '/etc/init.d/xinetd reload',
require => [ Package['xinetd'],
File['/etc/xinetd.conf'] ],
package { $package_name:
ensure => installed,
before => Service[$service_name],
}

service { $service_name:
ensure => running,
enable => true,
hasrestart => false,
hasstatus => true,
require => File[$conffile],
}

}
34 changes: 34 additions & 0 deletions manifests/params.pp
@@ -0,0 +1,34 @@
class xinetd::params {

case $::osfamily {
'Debian': {
$confdir = '/etc/xinetd.d'
$conffile = '/etc/xinetd.conf'
$package_name = 'xinetd'
$service_name = 'xinetd'
}
'FreeBSD': {
$confdir = '/usr/local/etc/xinetd.d'
$conffile = '/usr/local/etc/xinetd.conf'
$package_name = 'security/xinetd'
$service_name = 'xinetd'
}
'Suse': {
$confdir = '/etc/xinetd.d'
$conffile = '/etc/xinetd.conf'
$package_name = 'xinetd'
$service_name = 'xinetd'
}
'RedHat': {
$confdir = '/etc/xinetd.d'
$conffile = '/etc/xinetd.conf'
$package_name = 'xinetd'
$service_name = 'xinetd'
}
default: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about if the fail() case was just the default case? fail("xinetd: module does not support osfamily ${osfamily}")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, the default case was the RedHat case I think, so we lost that. Could you put it back as RedHat above and remove the Solaris case?

fail("xinetd: module does not support osfamily ${::osfamily}")
}
}

}

91 changes: 65 additions & 26 deletions manifests/service.pp
Expand Up @@ -4,27 +4,32 @@
# all parameters match up with xinetd.conf(5) man page
#
# Parameters:
# $port - required - determines the service port
# $server - required - determines the executable for this service
# $ensure - optional - defaults to 'present'
# $cps - optional
# $flags - optional
# $per_source - optional
# $server_args - optional
# $log_on_failure - optional - may contain any combination of
# 'HOST', 'USERID', 'ATTEMPT'
# $disable - optional - defaults to 'no'
# $socket_type - optional - defaults to 'stream'
# $protocol - optional - defaults to 'tcp'
# $user - optional - defaults to 'root'
# $group - optional - defaults to 'root'
# $instances - optional - defaults to 'UNLIMITED'
# $wait - optional - based on $protocol
# will default to 'yes' for udp and 'no' for tcp
# $bind - optional - defaults to '0.0.0.0'
# $service_type - optional - type setting in xinetd
# may contain any combinarion of 'RPC', 'INTERNAL',
# 'TCPMUX/TCPMUXPLUS', 'UNLISTED'
# $cps - optional
# $flags - optional
# $per_source - optional
# $port - required - determines the service port
# $server - required - determines the program to execute for this service
# $server_args - optional
# $disable - optional - defaults to "no"
# $socket_type - optional - defaults to "stream"
# $protocol - optional - defaults to "tcp"
# $user - optional - defaults to "root"
# $group - optional - defaults to "root"
# $groups - optional - defaults to "yes"
# $instances - optional - defaults to "UNLIMITED"
# $only_from - optional
# $wait - optional - based on $protocol will default to "yes" for udp and "no" for tcp
# $xtype - optional - determines the "type" of service, see xinetd.conf(5)
# $no_access - optional
# $access_times - optional
# $log_type - optional
# $bind - optional
#
# Actions:
# setups up a xinetd service by creating a file in /etc/xinetd.d/
Expand All @@ -50,37 +55,71 @@
$port,
$server,
$ensure = present,
$log_on_failure = undef,
$service_type = undef,
$service_name = $title,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually the service_name parameter is used for the name of the service that the init manager starts which is xinetd in this case. But this is also special since the processes that xinetd runs are also called services.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any preference on what should be done?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think service_name is fine because the xinetd::service defined resource will never be managing an actual service resource.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Except that it does notify the xinetd service. I think $service_name will reference the parameter and $xinetd::service_name can reference the xinetd service.

$cps = undef,
$disable = 'no',
$flags = undef,
$group = 'root',
$groups = 'yes',
$instances = 'UNLIMITED',
$log_on_failure = undef,
$per_source = undef,
$protocol = 'tcp',
$server_args = undef,
$disable = 'no',
$socket_type = 'stream',
$protocol = 'tcp',
$user = 'root',
$group = 'root',
$instances = 'UNLIMITED',
$only_from = undef,
$wait = undef,
$bind = '0.0.0.0',
$service_type = undef
$xtype = undef,
$no_access = undef,
$access_times = undef,
$log_type = undef,
$bind = undef,
) {

include xinetd

if $wait {
$mywait = $wait
$_wait = $wait
} else {
$mywait = $protocol ? {
validate_re($protocol, '(tcp|udp)')
$_wait = $protocol ? {
tcp => 'no',
udp => 'yes'
}
}

file { "/etc/xinetd.d/${name}":
# Template uses:
# - $port
# - $disable
# - $socket_type
# - $protocol
# - $_wait
# - $user
# - $group
# - $groups
# - $server
# - $bind
# - $service_type
# - $server_args
# - $only_from
# - $per_source
# - $log_on_failure
# - $cps
# - $flags
# - $xtype
# - $no_access
# - $access_types
# - $log_type
file { "${xinetd::confdir}/${title}":
ensure => $ensure,
owner => 'root',
mode => '0644',
content => template('xinetd/service.erb'),
notify => Service['xinetd'],
require => Package['xinetd'],
notify => Service[$xinetd::service_name],
require => File[$xinetd::confdir],
}

}
7 changes: 6 additions & 1 deletion spec/classes/xinetd_init_spec.rb
@@ -1,9 +1,14 @@
require 'spec_helper'

describe 'xinetd' do

let :facts do
{ :osfamily => 'Debian' }
end

it {
should contain_package('xinetd')
should contain_file('/etc/xinetd.conf')
should contain_service('xinetd').with_restart('/etc/init.d/xinetd reload')
should contain_service('xinetd')
}
end
5 changes: 5 additions & 0 deletions spec/defines/xinetd_service_spec.rb
@@ -1,6 +1,11 @@
require 'spec_helper'

describe 'xinetd::service' do

let :facts do
{ :osfamily => 'Debian' }
end

let :default_params do
{
'port' => '80',
Expand Down
46 changes: 38 additions & 8 deletions templates/service.erb
@@ -1,21 +1,51 @@
# This file is being maintained by Puppet.
# DO NOT EDIT

service <%= @name %>
service <%= @service_name %>
{
port = <%= @port %>
disable = <%= @disable %>
socket_type = <%= @socket_type %>
protocol = <%= @protocol %>
wait = <%= @mywait %>
wait = <%= @_wait %>
user = <%= @user %>
group = <%= @group %>
groups = <%= @groups %>
server = <%= @server %>
<% if @bind -%>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no bind directive is set for xinetd, where does it listen? I ask because 0.0.0.0 was the previous value for this and was always present, and since this module is a stable release I just want to check that this isn't breaking behaviour.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The man page is very unhelpful in determining this.....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright I put it back to 0.0.0.0 for now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

man 5 xinetd.conf seems to imply that it listens on all interfaces by default... thoughts?

bind    Allows a service to be bound to a specific interface on the machine.  This means you can have a   
telnet server listening on a local, secured interface, and not on the external interface.  Or one port on one 
interface can do something,  while  the same port on a different interface can do something completely 
different.  Syntax: bind = (ip address of interface).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, my guess would be that no bind is the same as bind = 0.0.0.0

bind = <%= @bind %>
<% if @server_args %> server_args = <%= @server_args %><% end %>
<% if @per_source %> per_source = <%= @per_source %><% end %>
<% if @log_on_failure %> log_on_failure += <%= @log_on_failure %><% end %>
<% if @cps %> cps = <%= @cps %><% end %>
<% if @flags %> flags = <%= @flags %><% end %>
<% if @service_type %> type = <%= @service_type %><% end %>
<% end -%>
<% if @service_type -%>
type = <%= @service_type %>
<% end -%>
<% if @server_args -%>
server_args = <%= @server_args %>
<% end -%>
<% if @only_from -%>
only_from = <%= @only_from %>
<% end -%>
<% if @per_source -%>
per_source = <%= @per_source %>
<% end -%>
<% if @log_on_failure -%>
log_on_failure += <%= @log_on_failure %>
<% end -%>
<% if @cps -%>
cps = <%= @cps %>
<% end -%>
<% if @flags -%>
flags = <%= @flags %>
<% end -%>
<% if @xtype -%>
type = <%= @xtype %>
<% end -%>
<% if @no_access -%>
no_access = <%= @no_access %>
<% end -%>
<% if @access_times -%>
access_times = <%= @access_times %>
<% end -%>
<% if @log_type -%>
log_type = <%= @log_type %>
<% end -%>
}
3 changes: 1 addition & 2 deletions files/xinetd.conf → templates/xinetd.conf.erb
Expand Up @@ -48,5 +48,4 @@ defaults
# banner_success =
}

includedir /etc/xinetd.d

includedir <%= @confdir %>