Skip to content

Commit 18ade0a

Browse files
authored
Merge pull request #438 from lucywyman/GH-1204-add-stop-service-option
(GH-1204) Add option to stop the puppet agent service after install
2 parents 20002d0 + 83f80a9 commit 18ade0a

File tree

6 files changed

+32
-2
lines changed

6 files changed

+32
-2
lines changed

task_spec/spec/acceptance/init_spec.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ def target_platform
4444
end
4545

4646
# Try to install an older version
47-
results = run_task('puppet_agent::install', 'target', { 'collection' => 'puppet5', 'version' => puppet_5_version })
47+
results = run_task('puppet_agent::install', 'target', { 'collection' => 'puppet5',
48+
'version' => puppet_5_version,
49+
'stop_service' => true })
4850
results.each do |res|
4951
expect(res).to include('status' => 'success')
5052
end
@@ -57,6 +59,14 @@ def target_platform
5759
expect(res['result']['source']).to be
5860
end
5961

62+
service = if target_platform =~ /win/
63+
run_command('c:/"program files"/"puppet labs"/puppet/bin/puppet resource service puppet', 'target')
64+
else
65+
run_command('/opt/puppetlabs/bin/puppet resource service puppet', 'target')
66+
end
67+
output = service[0]['result']['stdout']
68+
expect(output).to include("ensure => 'stopped'")
69+
6070
# Run with no argument upgrades
6171
results = run_task('puppet_agent::install', 'target', { 'collection' => 'puppet5' })
6272
results.each do |res|

tasks/install.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
"install_options": {
2929
"description": "optional install arguments to the windows installer (defaults to REINSTALLMODE=\"amus\")",
3030
"type": "Optional[String]"
31+
},
32+
"stop_service": {
33+
"description": "Whether to stop the puppet agent service after install",
34+
"type": "Optional[Boolean]"
3135
}
3236
},
3337
"implementations": [

tasks/install_powershell.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
"install_options": {
3030
"description": "optional install arguments to the windows installer (defaults to REINSTALLMODE=\"amus\")",
3131
"type": "Optional[String]"
32+
},
33+
"stop_service": {
34+
"description": "Whether to stop the puppet agent service after install",
35+
"type": "Optional[Boolean]"
3236
}
3337
}
3438
}

tasks/install_powershell.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ Param(
33
[String]$version,
44
[String]$collection = 'puppet',
55
[String]$windows_source = 'https://downloads.puppet.com',
6-
[String]$install_options = 'REINSTALLMODE="amus"'
6+
[String]$install_options = 'REINSTALLMODE="amus"',
7+
[Bool]$stop_service = $False
78
)
89
# If an error is encountered, the script will stop instead of the default of "Continue"
910
$ErrorActionPreference = "Stop"
@@ -65,6 +66,9 @@ function InstallPuppet {
6566
}
6667

6768
function Cleanup {
69+
if($stop_service -eq 'true') {
70+
C:\"Program Files"\"Puppet Labs"\Puppet\bin\puppet resource service puppet ensure=stopped enable=false
71+
}
6872
Write-Output "Deleting $msi_dest and $install_log"
6973
Remove-Item -Force $msi_dest
7074
Remove-Item -Force $install_log

tasks/install_shell.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
"install_options": {
3131
"description": "optional install arguments to the windows installer (defaults to REINSTALLMODE=\"amus\")",
3232
"type": "Optional[String]"
33+
},
34+
"stop_service": {
35+
"description": "Whether to stop the puppet agent service after install",
36+
"type": "Optional[Boolean]"
3337
}
3438
},
3539
"files": ["facts/tasks/bash.sh"]

tasks/install_shell.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,10 @@ do_download "$download_url" "$download_filename"
525525

526526
install_file $filetype "$download_filename"
527527

528+
if [[ $PT_stop_service = true ]]; then
529+
/opt/puppetlabs/bin/puppet resource service puppet ensure=stopped enable=false
530+
fi
531+
528532
#Cleanup
529533
if test "x$tmp_dir" != "x"; then
530534
rm -r "$tmp_dir"

0 commit comments

Comments
 (0)