Skip to content

Commit

Permalink
Merge pull request #6 from alxwr/freebsd-support
Browse files Browse the repository at this point in the history
added support for FreeBSD
  • Loading branch information
tohuwabohu authored Jun 13, 2016
2 parents 87efb17 + 81288f7 commit 3191ba4
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 28 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
/spec/fixtures/manifests
/spec/fixtures/modules

*.swp
*.swo

# https://tickets.puppetlabs.com/browse/PUP-3444
vendor/**
.bundle/
4 changes: 2 additions & 2 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
file { $openntp::config_file:
ensure => $ensure_config,
content => template($real_template),
owner => 'root',
group => 'root',
owner => $openntp::rootuser,
group => $openntp::rootgroup,
mode => '0644',
}
}
15 changes: 13 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
$server = suffix(range('0', '3'), '.debian.pool.ntp.org')
$package_name = 'openntpd'
$service_name = 'openntpd'
$service_restart = '/usr/local/sbin/restart-openntpd'
$config_file = '/etc/openntpd/ntpd.conf'
$service_restart = $::osfamily ? {
'Debian' => '/usr/local/sbin/restart-openntpd',
default => undef
}
$config_file = $::osfamily ? {
'FreeBSD' => '/usr/local/etc/ntpd.conf',
default => '/etc/openntpd/ntpd.conf'
}
$rootuser = 'root'
$rootgroup = $::osfamily ? {
'FreeBSD' => 'wheel',
default => 'root'
}
}
32 changes: 17 additions & 15 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,25 @@
default => false,
}

if $openntp::service_restart == $openntp::params::service_restart {
# The restart script does not properly check if the service is actually stopped; hence, the start command can fail
# to start the service because it is still running. This script checks the status and issues the start command as
# soon as the service is actually stopped.
if $openntp::service_restart != undef {
if $openntp::service_restart == $openntp::params::service_restart {
# The restart script does not properly check if the service is actually stopped; hence, the start command can fail
# to start the service because it is still running. This script checks the status and issues the start command as
# soon as the service is actually stopped.

$file_ensure = $openntp::ensure ? {
absent => absent,
default => file,
}
$file_ensure = $openntp::ensure ? {
absent => absent,
default => file,
}

file { $openntp::params::service_restart:
ensure => $file_ensure,
content => template('openntp/restart.sh.erb'),
owner => 'root',
group => 'root',
mode => '0555',
before => Service[$openntp::service_name]
file { $openntp::params::service_restart:
ensure => $file_ensure,
content => template('openntp/restart.sh.erb'),
owner => $openntp::rootuser,
group => $openntp::rootgroup,
mode => '0555',
before => Service[$openntp::service_name]
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
"12.04",
"14.04"
]
},
{
"operatingsystem": "FreeBSD",
"operatingsystemrelease": [
"10"
]
}
],
"requirements": [
Expand Down
49 changes: 40 additions & 9 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,46 @@
describe 'by default' do
let(:params) { { } }

it { should contain_package('openntpd').with_ensure('installed') }
it { should contain_service('openntpd').with_ensure('running').with_enable(true) }
it { should contain_file(config_file) }
it { should contain_file(config_file).with_ensure('file') }
it { should contain_file(config_file).without_content(/listen on/) }
it { should contain_file(config_file).with_content(/server 0.debian.pool.ntp.org/) }
it { should contain_file(config_file).with_content(/server 1.debian.pool.ntp.org/) }
it { should contain_file(config_file).with_content(/server 2.debian.pool.ntp.org/) }
it { should contain_file(config_file).with_content(/server 3.debian.pool.ntp.org/) }
shared_examples 'a default setup' do
it { should contain_package('openntpd').with_ensure('installed') }
it { should contain_service('openntpd').with_ensure('running').with_enable(true) }
it { should contain_file(config_file) }
it { should contain_file(config_file).with_ensure('file') }
it { should contain_file(config_file).with_owner('root') }
it { should contain_file(config_file).without_content(/listen on/) }
it { should contain_file(config_file).with_content(/server 0.debian.pool.ntp.org/) }
it { should contain_file(config_file).with_content(/server 1.debian.pool.ntp.org/) }
it { should contain_file(config_file).with_content(/server 2.debian.pool.ntp.org/) }
it { should contain_file(config_file).with_content(/server 3.debian.pool.ntp.org/) }
end

it_behaves_like 'a default setup'
it { should_not contain_file('/usr/local/sbin/restart-openntpd') }

describe 'on Debian' do
let(:facts) { {
:concat_basedir => '/path/to/dir',
:osfamily => 'Debian'
} }

it_behaves_like 'a default setup'

it { should contain_file(config_file).with_group('root') }
it { should contain_file('/usr/local/sbin/restart-openntpd') }
end

describe 'on FreeBSD' do
let(:facts) { {
:concat_basedir => '/path/to/dir',
:osfamily => 'FreeBSD'
} }
let(:config_file) { '/usr/local/etc/ntpd.conf' }

it_behaves_like 'a default setup'

it { should contain_file(config_file).with_group('wheel') }
it { should_not contain_file('/usr/local/sbin/restart-openntpd') }
end
end

describe 'with custom version' do
Expand Down

0 comments on commit 3191ba4

Please sign in to comment.