Skip to content

Commit

Permalink
Adds parameter for enabling the Tomcat service on boot
Browse files Browse the repository at this point in the history
  • Loading branch information
bmjen committed Mar 17, 2015
1 parent f22512c commit 02f39c0
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,10 @@ Specifies the path Java is installed under. Only applies if `$use_jsvc = 'true'`

Determines whether the Tomcat service is on or off. Valid values are 'running', 'stopped', 'true', and 'false'. (To determine whether the service is present/absent, see [tomcat::config::server::service](#tomcatconfigserverservice).)

#####`$service_enable`

Specifies whether to enable the Tomcat service at boot. Valid options are `true` or `false`. To use `$service_enable`, `use_init` must be set to `true`. If `$service_enable` is unset, `$use_init` is set to `true`, and `$service_ensure` is set to `running` or `true`, then `$service_enable` will be set to `true`.

#####`$use_init`

Specifies whether or not to use the package-provided init script for service management. A Boolean that defaults to 'false'. Note that the
Expand Down
25 changes: 25 additions & 0 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# - If using jsvc, optionally set java_home. Has no affect unless
# $use_jsvc = true.
# - $service_ensure is passed on to the service resource.
# - $service_enable specifies whether the tomcat service should be enabled on
# on boot. Valid options are 'true' or 'false'. Defaults to 'undef', will be
# programmatically set to 'true' if $use_init is true AND
# $service_ensure == 'running'
# - Whether or not to $use_init for service management. Boolean defaulting to
# false. If both $use_jsvc and $use_init are false,
# $CATALINA_BASE/bin/catalina.sh start and $CATALIN/A_BASE/bin/catalina.sh
Expand All @@ -25,6 +29,7 @@
$use_jsvc = false,
$java_home = undef,
$service_ensure = running,
$service_enable = undef,
$use_init = false,
$service_name = undef,
$start_command = undef,
Expand All @@ -42,6 +47,10 @@
fail('$service_name must be specified when $use_init is set to true')
}

if $service_enable != undef and ! $use_init {
fail('$use_init must be set to true when $service_enable is set')
}

if $use_init and ($catalina_home or $catalina_base) {
warning('$catalina_home and $catalina_base have no affect when $use_init = true')
}
Expand Down Expand Up @@ -123,8 +132,24 @@
$_provider = 'base'
}

if $use_init {
if $service_enable != undef {
validate_bool($service_enable)
$_service_enable = $service_enable
} else {
$_service_enable = $service_ensure ? {
'running' => true,
true => true,
default => undef,
}
}
} else {
$_service_enable = undef
}

service { $_service_name:
ensure => $service_ensure,
enable => $_service_enable,
hasstatus => $_hasstatus,
hasrestart => $_hasrestart,
start => $_start,
Expand Down
74 changes: 66 additions & 8 deletions spec/defines/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
end
let :facts do
{
:osfamily => 'Debian'
:osfamily => 'Debian',
}
end
let :title do
Expand All @@ -15,7 +15,7 @@
context 'using jsvc' do
let :params do
{
:use_jsvc => true
:use_jsvc => true,
}
end
it { is_expected.to contain_service('tomcat-default').with(
Expand All @@ -38,7 +38,7 @@
'hasrestart' => false,
'ensure' => 'running',
'start' => '/bin/true',
'stop' => '/bin/true',
'stop' => '/bin/true',
)
}
end
Expand Down Expand Up @@ -83,7 +83,7 @@
'hasrestart' => true,
'ensure' => 'running',
'start' => '/bin/true',
'stop' => '/bin/true',
'stop' => '/bin/true',
)
}
end
Expand Down Expand Up @@ -113,6 +113,51 @@
)
}
end

context "service_enable, set from user" do
let :params do
{
:use_init => true,
:service_name => 'tomcat',
:service_enable => true,
}
end
it { is_expected.to contain_service('tomcat').with(
'enable' => true,
)
}
end
context "service_enable, set true from defaults" do
let :params do
{
:use_init => true,
:service_name => 'tomcat',
:service_ensure => 'running',
}
end
it { is_expected.to contain_service('tomcat').with(
'hasstatus' => true,
'hasrestart' => true,
'ensure' => 'running',
'enable' => true,
)
}
end
context "service_enable, set undef from defaults" do
let :params do
{
:use_init => false,
:service_ensure => 'running',
}
end
it { is_expected.to contain_service('tomcat-default').with(
'hasstatus' => false,
'hasrestart' => false,
'ensure' => 'running',
'enable' => nil,
)
}
end
describe 'failing tests' do
context "bad use_jsvc" do
let :params do
Expand Down Expand Up @@ -154,8 +199,8 @@
context "init without servicename" do
let :params do
{
:use_jsvc => false,
:use_init => true,
:use_jsvc => false,
:use_init => true,
}
end
it do
Expand All @@ -164,6 +209,19 @@
}.to raise_error(Puppet::Error, /\$service_name must be specified/)
end
end
context "service_enable, error thrown if use_init is false" do
let :params do
{
:use_init => false,
:service_enable => true,
}
end
it do
expect {
is_expected.to compile
}.to raise_error(Puppet::Error, /\$use_init must be set to true when \$service_enable is set/)
end
end
context "java_home without use_jsvc warning" do
let :params do
{
Expand All @@ -176,8 +234,8 @@
context "java_home with start_command" do
let :params do
{
:java_home => 'foo',
:start_command => '/bin/true'
:java_home => 'foo',
:start_command => '/bin/true',
}
end

Expand Down

0 comments on commit 02f39c0

Please sign in to comment.