Skip to content

Commit

Permalink
run all app commands on the specified host when $update_host is set
Browse files Browse the repository at this point in the history
This is necessary to avoid situations where another host tries to
reinstall an app as part of the post-udpate procedure.
  • Loading branch information
fraenki committed Nov 5, 2022
1 parent 56472d9 commit 2982ca6
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 41 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [v1.8.2] - 2022-11-05

### Changed
* Run all app commands on the specified host when `$update_host` is set

## [v1.8.1] - 2022-11-05

### Changed
Expand Down
4 changes: 2 additions & 2 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ Data type: `Optional[String]`

Optional parameter to specify the FQDN of the host where all critical
operations should be performed. This includes operations such as the
initial installation and consecutive update installations. Limiting these
operations to a single host should prevent (rare) race conditions.
initial installation, update installations and all app commands.
Limiting these operations to a single host should prevent race conditions.

Default value: ``undef``

Expand Down
78 changes: 41 additions & 37 deletions manifests/app_command.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,49 @@
Enum['install','remove','enable','disable','install_disable','post_update'] $command,
String $app = $title,
) {
# Handle special app commands.
case $command {
# Install an app but keep it disabled.
'install_disable': {
$real_command = 'install --keep-disabled'
$pre_command = ''
# Check if this is the designated update/install host.
if (($nextcloud::update_host == undef or empty($nextcloud::update_host))
or ($nextcloud::update_host == $facts['networking']['fqdn'])) {
# Handle special app commands.
case $command {
# Install an app but keep it disabled.
'install_disable': {
$real_command = 'install --keep-disabled'
$pre_command = ''
}
# Ensure that an app is installed after updating Nextcloud.
'post_update': {
$real_command = 'install'
# First try to update the app. If this command returns a non-zero
# exit code, then try to install the app.
$pre_command = "php occ app:update ${app} ||"
}
default: {
$real_command = $command
$pre_command = ''
}
}
# Ensure that an app is installed after updating Nextcloud.
'post_update': {
$real_command = 'install'
# First try to update the app. If this command returns a non-zero
# exit code, then try to install the app.
$pre_command = "php occ app:update ${app} ||"
}
default: {
$real_command = $command
$pre_command = ''
}
}

# Commands and files required for app installation/removal.
$app_lock = "${nextcloud::datadir}/.puppet_app.lock"
$app_cmd = join([
"touch ${app_lock};",
$pre_command,
"php occ app:${real_command} ${app}",
'; _exit=$?', # record exit code
"; rm -f ${app_lock}", # always remove lock
'; test $_exit -lt 1 && true', # pass failures to puppet
], ' ')
# Commands and files required for app installation/removal.
$app_lock = "${nextcloud::datadir}/.puppet_app.lock"
$app_cmd = join([
"touch ${app_lock};",
$pre_command,
"php occ app:${real_command} ${app}",
'; _exit=$?', # record exit code
"; rm -f ${app_lock}", # always remove lock
'; test $_exit -lt 1 && true', # pass failures to puppet
], ' ')

# Run the app command.
# NOTE: The command will not run if an update of Nextcloud is running.
exec { "occ app:${command} ${app}":
command => $app_cmd,
path => $nextcloud::path,
cwd => $nextcloud::symlink,
onlyif => "test ! -f ${app_lock} -a ! -f ${nextcloud::update::update_lock}",
user => $nextcloud::system_user,
logoutput => $nextcloud::debug,
# Run the app command.
# NOTE: The command will not run if an update of Nextcloud is running.
exec { "occ app:${command} ${app}":
command => $app_cmd,
path => $nextcloud::path,
cwd => $nextcloud::symlink,
onlyif => "test ! -f ${app_lock} -a ! -f ${nextcloud::update::update_lock}",
user => $nextcloud::system_user,
logoutput => $nextcloud::debug,
}
}
}
4 changes: 2 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@
# @param update_host
# Optional parameter to specify the FQDN of the host where all critical
# operations should be performed. This includes operations such as the
# initial installation and consecutive update installations. Limiting these
# operations to a single host should prevent (rare) race conditions.
# initial installation, update installations and all app commands.
# Limiting these operations to a single host should prevent race conditions.
#
# @param version
# Specifies the version of Nextcloud that should be installed.
Expand Down

0 comments on commit 2982ca6

Please sign in to comment.