Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PA-5786) Add ability to execute direct post installation scripts #825

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ This project adheres to [Semantic Versioning](https://semver.org).
This changelog adheres to [Keep a CHANGELOG](https://keepachangelog.com).

## [Unreleased]
### Added
- (PA-5786) Add `postinstall_required_actions` forcing scriptlets to run in the %post section for rpm

## [0.41.0] - 2023-10-26
### Added
Expand Down
4 changes: 4 additions & 0 deletions lib/vanagon/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ class Component
# activate_triggers is a one-dimentional Array of Strings, describing scripts that
# should be executed when a package identifies an activate trigger
attr_accessor :activate_triggers
# postinstall_required_actions is a two-dimensional Array, describing scripts that
# must be executed successfully after a given component is installed.
attr_accessor :postinstall_required_actions
# postinstall_actions is a two-dimensional Array, describing scripts that
# should be executed after a given component is installed.
attr_accessor :postinstall_actions
Expand Down Expand Up @@ -176,6 +179,7 @@ def initialize(name, settings, platform) # rubocop:disable Metrics/AbcSize
@install_triggers = []
@interest_triggers = []
@activate_triggers = []
@postinstall_required_actions = []
@postinstall_actions = []
@preremove_actions = []
@postremove_actions = []
Expand Down
10 changes: 10 additions & 0 deletions lib/vanagon/component/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,16 @@ def add_debian_activate_triggers(activate_name)
@component.activate_triggers << OpenStruct.new(:activate_name => activate_name)
end

# Add post installation action that must exit successfully before restarting the service
#
# @param pkg_state [Array] the state in which the scripts should execute. Can be
# one or multiple of 'install' and 'upgrade'.
# @param scripts [Array] the Bourne shell compatible scriptlet(s) to execute
def add_postinstall_required_action(pkg_state, scripts)
check_pkg_state_array(pkg_state)
@component.postinstall_required_actions << OpenStruct.new(:pkg_state => Array(pkg_state), :scripts => Array(scripts))
end

# Adds action to run during the postinstall phase of packaging
#
# @param pkg_state [Array] the state in which the scripts should execute. Can be
Expand Down
12 changes: 12 additions & 0 deletions lib/vanagon/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,18 @@ def get_postinstall_actions(pkg_state)
end
end

# Collects the postinstall packaging actions that must exit successfully for the project and it's components
# for the specified packaging state
#
# @param pkg_state [String] the package state we want to run the given scripts for.
# Can be one of 'install' or 'upgrade'
# @return [String] string of Bourne shell compatible scriptlets to execute during the postinstall
# phase of packaging during the state of the system defined by pkg_state (either install or upgrade)
def get_postinstall_required_actions(pkg_state)
scripts = components.flat_map(&:postinstall_required_actions).compact.select { |s| s.pkg_state.include? pkg_state }.map(&:scripts)
return ': no postinstall required scripts provided' if scripts.empty?
scripts.join("\n")
end
# Collects the preremove packaging actions for the project and it's components
# for the specified packaging state
#
Expand Down
9 changes: 9 additions & 0 deletions resources/rpm/project.spec.erb
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ fi


%post
# Run required postinstall scripts on install if defined
if [ -e %{_localstatedir}/lib/rpm-state/%{name}/install ] ; then
<%= get_postinstall_required_actions("install") %>
fi

# Run required postinstall scripts on upgrade if defined
if [ -e %{_localstatedir}/lib/rpm-state/%{name}/upgrade ] ; then
<%= get_postinstall_required_actions("upgrade") %>
fi
<%- if @platform.is_aix? || (@platform.is_el? && @platform.os_version.to_i == 4) -%>
## EL-4 and AIX RPM don't have %posttrans, so we'll put them here
# Run postinstall scripts on install if defined
Expand Down