Skip to content

Commit 94709fd

Browse files
committed
(gh-35) Add a stop_service parameter to install task
This is for integration with openbolt for openvoxproject/openbolt@44. Bolt was providing a stop_service parameter to the puppetlabs-puppet_agent module here: https://github.com/OpenVoxProject/openbolt/blob/b9bff5a8dfe2f41218281bf8c5e6ad901bcae460/lib/bolt/plugin.rb#L133 This was for puppetlabs/bolt#1204, and while the current linux packages, at least, install with service stopped, it's probably still good practice to ensure it for the openbolt case. (This may have been more of an issue when some packages were still SysV?) Since our install task is more general, it could be used for openvox-server/openvoxdb, but there's no particular use case for this, and I haven't bothered with acceptance tests for them.
1 parent c248f2e commit 94709fd

File tree

5 files changed

+129
-1
lines changed

5 files changed

+129
-1
lines changed

.github/workflows/pr_testing.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,38 @@ jobs:
180180
PT_package: "openvox-server"
181181
PT_version: "8.8.0"
182182
run: ./openvox_bootstrap/tasks/install_linux.sh
183+
184+
test-install-and-stop:
185+
strategy:
186+
matrix:
187+
image:
188+
- rockylinux:9
189+
- fedora:41
190+
- debian:12
191+
- ubuntu:24.04
192+
# Need to pull in the repo GPG keys for sles
193+
# - registry.suse.com/suse/sle15:15.6
194+
needs: shellcheck
195+
runs-on: ubuntu-latest
196+
container: ${{ matrix.image }}
197+
steps:
198+
- uses: actions/checkout@v4
199+
with:
200+
path: openvox_bootstrap
201+
- id: prep
202+
uses: ./openvox_bootstrap/.github/actions/container_task_prep
203+
- name: Run openvox-agent install task manually
204+
env:
205+
PT_stop_service: "true"
206+
run: ./openvox_bootstrap/tasks/install_linux.sh
207+
- name: Verify openvox-agent is installed
208+
env:
209+
PT_version: '8'
210+
PT_test: 'gt'
211+
run: ./openvox_bootstrap/tasks/check_linux.sh
212+
- name: Verify service state
213+
run: |-
214+
set -e
215+
/opt/puppetlabs/bin/puppet resource service openvox-agent > service.state
216+
grep -E "ensure [ ]*=> [ ]*'stopped'" service.state
217+
grep -E "enable [ ]*=> [ ]*'false'" service.state

files/common.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,3 +510,43 @@ set_artifacts_package_url() {
510510
export package_url # quiets shellcheck SC2034
511511
assigned 'package_url'
512512
}
513+
514+
# Stop and disable the service for the given package.
515+
#
516+
# Only intended to work for openvox-agent, openvoxdb and
517+
# openvox-server.
518+
#
519+
# Will fail if openvox isn't installed.
520+
#
521+
# (voxpupuli/puppet-openvox_bootstrap#35)
522+
# Implemented for integration with openbolt.
523+
stop_and_disable_service() {
524+
local _package="$1"
525+
# Using the full path here because openvox is installed into opt,
526+
# and if we've just installed, the shell's PATH will not include it
527+
# yet.
528+
local _puppet="${2:-'/opt/puppetlabs/bin/puppet'}"
529+
530+
case "${_package}" in
531+
openvox-agent)
532+
local _service='puppet'
533+
;;
534+
openvoxdb)
535+
local _service='puppetdb'
536+
;;
537+
openvox-server)
538+
local _service='puppetserver'
539+
;;
540+
*)
541+
fail "Cannot stop service. Unknown service for package: '${_package}'"
542+
;;
543+
esac
544+
545+
info "Stopping and disabling service '${_service}' for package '${_package}'"
546+
547+
if [ -x "${_puppet}" ]; then
548+
exec_and_capture "${_puppet}" resource service "${_service}" ensure=stopped enable=false
549+
else
550+
fail "Puppet executable not found at '${_puppet}'. Cannot stop and disable service '${_service}'."
551+
fi
552+
}

spec/unit/bash/common_sh_spec.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,4 +577,48 @@
577577
end
578578
end
579579
end
580+
581+
context 'stop_and_disable_service' do
582+
it 'fails for an unknown package' do
583+
output, status = test('stop_and_disable_service unknown-package')
584+
585+
expect(status.success?).to be(false)
586+
expect(output.strip).to include("Unknown service for package: 'unknown-package'")
587+
end
588+
589+
it 'fails if puppet executable not found' do
590+
output, status = test('stop_and_disable_service openvox-agent /no/openvox')
591+
592+
expect(status.success?).to be(false)
593+
expect(output.strip).to include("Puppet executable not found at '/no/openvox'")
594+
end
595+
596+
context 'with puppet executable' do
597+
let(:mock_puppet) { "#{tmpdir}/puppet" }
598+
599+
before do
600+
# The little BashRspec lib isn't sophisticated enough
601+
# to deal with an absolute path, so using this instead of
602+
# allow_script.to receive_command(mock_puppet)...
603+
File.write(mock_puppet, <<~EOF)
604+
#!/bin/sh
605+
echo "Stopping ${3} service"
606+
EOF
607+
File.chmod(0o755, mock_puppet)
608+
end
609+
610+
[
611+
%w[openvox-agent puppet],
612+
%w[openvox-server puppetserver],
613+
%w[openvoxdb puppetdb],
614+
].each do |package, service|
615+
it "stops the #{service} service for #{package}" do
616+
output, status = test("stop_and_disable_service #{package} #{mock_puppet}")
617+
618+
expect(status.success?).to be(true)
619+
expect(output.strip).to include(service)
620+
end
621+
end
622+
end
623+
end
580624
end

tasks/install.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"description": "The yum source repository to retrieve rpm packages from.",
2525
"type": "Optional[String]",
2626
"default": "https://yum.voxpupuli.org"
27+
},
28+
"stop_service": {
29+
"description": "Whether to stop the given service after install. (Requires puppet on the system.)",
30+
"type": "Optional[Boolean]"
2731
}
2832
},
2933
"implementations": [

tasks/install_linux.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ version=${PT_version:-latest}
99
collection=${PT_collection:-openvox8}
1010
yum_source=${PT_yum_source:-https://yum.voxpupuli.org}
1111
apt_source=${PT_apt_source:-https://apt.voxpupuli.org}
12+
stop_service=${PT_stop_service:-'false'}
1213

1314
# shellcheck source=files/common.sh
1415
source "${PT__installdir}/openvox_bootstrap/files/common.sh"
@@ -75,5 +76,9 @@ download "${package_url}" "${local_release_package}"
7576
# The release package has the repository metadata needed to install
7677
# packages from the collection using the platform package manager.
7778
install_release_package "${local_release_package}"
78-
# Use the platform package manager to install openvox-agent
79+
# Use the platform package manager to install $package
7980
install_package "${package}" "${version}" "${os_family}" "${os_full_version}"
81+
# If a service stop is requested, stop the service now
82+
if [[ "${stop_service}" = 'true' ]]; then
83+
stop_and_disable_service "${package}"
84+
fi

0 commit comments

Comments
 (0)