Skip to content

Commit

Permalink
Refactor xinetd and xinetd::service
Browse files Browse the repository at this point in the history
  - refactor xinetd class to be parameterized
  - rename $real_wait to $_wait to indicate it was munged
  - use validate_re function to verify tcp|udp
  - rename $xinetd_* to *
  - remove duplicate include xinetd
  - refactor template not to use scope.lookupvar
  - fix failing spec tests
  - add dependency on stdlib
  - add failure on unsupported osfamiles
  • Loading branch information
blkperl committed Jul 30, 2013
1 parent 74d681a commit 5c9dd81
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 51 deletions.
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'
26 changes: 16 additions & 10 deletions manifests/init.pp
Expand Up @@ -9,38 +9,44 @@
# server_args => '--daemon --config /etc/rsync.conf',
# }
#
class xinetd {
include xinetd::params
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 {

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

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

file { $xinetd::params::xinetd_conffile:
# Template uses:
# $confdir
file { $conffile:
ensure => file,
mode => '0644',
content => template('xinetd/xinetd.conf.erb'),
}

package { $xinetd::params::xinetd_package:
package { $package_name:
ensure => installed,
before => Service[$xinetd::params::xinetd_service],
before => Service[$service_name],
}

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

}
36 changes: 18 additions & 18 deletions manifests/params.pp
Expand Up @@ -2,31 +2,31 @@

case $::osfamily {
'Debian': {
$xinetd_confdir = '/etc/xinetd.d'
$xinetd_conffile = '/etc/xinetd.conf'
$xinetd_package = 'xinetd'
$xinetd_service = 'xinetd'
$confdir = '/etc/xinetd.d'
$conffile = '/etc/xinetd.conf'
$package_name = 'xinetd'
$service_name = 'xinetd'
}
'FreeBSD': {
$xinetd_confdir = '/usr/local/etc/xinetd.d'
$xinetd_conffile = '/usr/local/etc/xinetd.conf'
$xinetd_package = 'security/xinetd'
$xinetd_service = 'xinetd'
$confdir = '/usr/local/etc/xinetd.d'
$conffile = '/usr/local/etc/xinetd.conf'
$package_name = 'security/xinetd'
$service_name = 'xinetd'
}
'Suse': {
$xinetd_confdir = '/etc/xinetd.d'
$xinetd_conffile = '/etc/xinetd.conf'
$xinetd_package = 'xinetd'
$xinetd_service = 'xinetd'
$confdir = '/etc/xinetd.d'
$conffile = '/etc/xinetd.conf'
$package_name = 'xinetd'
$service_name = 'xinetd'
}
'Solaris': {
fail('xinetd: module does not support Solaris')
'RedHat': {
$confdir = '/etc/xinetd.d'
$conffile = '/etc/xinetd.conf'
$package_name = 'xinetd'
$service_name = 'xinetd'
}
default: {
$xinetd_confdir = '/etc/xinetd.d'
$xinetd_conffile = '/etc/xinetd.conf'
$xinetd_package = 'xinetd'
$xinetd_service = 'xinetd'
fail("xinetd: module does not support osfamily ${::osfamily}")
}
}
Expand Down
60 changes: 40 additions & 20 deletions manifests/service.pp
Expand Up @@ -40,15 +40,15 @@
#
# Sample Usage:
# # setup tftp service
# xinetd::service {"tftp":
# port => "69",
# server => "/usr/sbin/in.tftpd",
# server_args => "-s $base",
# socket_type => "dgram",
# protocol => "udp",
# cps => "100 2",
# flags => "IPv4",
# per_source => "11",
# xinetd::service { 'tftp':
# port => '69',
# server => '/usr/sbin/in.tftpd',
# server_args => '-s $base',
# socket_type => 'dgram',
# protocol => 'udp',
# cps => '100 2',
# flags => 'IPv4',
# per_source => '11',
# } # xinetd::service
#
define xinetd::service (
Expand Down Expand Up @@ -76,30 +76,50 @@
$no_access = undef,
$access_times = undef,
$log_type = undef,
$bind = undef
$bind = undef,
) {
include xinetd
include xinetd::params

include xinetd

if $wait {
$wait_real = $wait
$_wait = $wait
} else {
case $protocol {
'tcp': { $wait_real = 'no' }
'udp': { $wait_real = 'yes' }
default: { fail('wait not set, unable to determine sane default') }
validate_re($protocol, '(tcp|udp)')
$_wait = $protocol ? {
tcp => 'no',
udp => 'yes'
}
}

file { "${xinetd::params::xinetd_confdir}/${title}":
# 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::params::xinetd_service],
require => File[$xinetd::params::xinetd_confdir],
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
2 changes: 1 addition & 1 deletion templates/service.erb
Expand Up @@ -7,7 +7,7 @@ service <%= @service_name %>
disable = <%= @disable %>
socket_type = <%= @socket_type %>
protocol = <%= @protocol %>
wait = <%= @wait_real %>
wait = <%= @_wait %>
user = <%= @user %>
group = <%= @group %>
groups = <%= @groups %>
Expand Down
2 changes: 1 addition & 1 deletion templates/xinetd.conf.erb
Expand Up @@ -48,4 +48,4 @@ defaults
# banner_success =
}

includedir <%= scope.lookupvar('xinetd::params::xinetd_confdir') %>
includedir <%= @confdir %>

0 comments on commit 5c9dd81

Please sign in to comment.