Skip to content

Commit

Permalink
add new parameter $cron_host
Browse files Browse the repository at this point in the history
  • Loading branch information
fraenki committed Feb 11, 2025
1 parent 8b2895e commit 0d25dc2
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 34 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).

## [Unreleased]

### Added
* Add new parameter `$cron_host`

## [v1.11.0] - 2024-11-06

### Changed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ When using more than one server for the same Nextcloud instance, the following p
class { 'nextcloud':
update_enabled => true,
update_host => 'main-host-fqdn.example.com',
cron_host => 'main-host-fqdn.example.com',
...
}
```
Expand Down
28 changes: 19 additions & 9 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ Data type: `Hash`

A hash containing configuration options for Nextcloud.

##### `cron_host`

Data type: `Optional[String]`

Optional parameter to specify the FQDN of the host where all cronjobs
should run. Limiting these commands to a single host should prevent
race conditions.

Default value: ``undef``

##### `cronjobs`

Data type: `Hash`
Expand All @@ -95,14 +105,14 @@ Specifies a list of cron jobs that should be added when

##### `datadir`

Data type: `Stdlib::Compat::Absolute_path`
Data type: `Stdlib::Absolutepath`

Specifies the directory where Nextcloud will store user data.
It MUST reside outside of Nextcloud's installation directory.

##### `datastatefile`

Data type: `Stdlib::Compat::Absolute_path`
Data type: `Stdlib::Absolutepath`

A file that is required by the module to work properly. This value MUST NOT
be changed, because the path is hardcoded in several places.
Expand Down Expand Up @@ -164,7 +174,7 @@ Specifies the relative path to the binary of the HPB app.

##### `hpb_pidfile`

Data type: `Stdlib::Compat::Absolute_path`
Data type: `Stdlib::Absolutepath`

Specifies the PID file for the HPB service.

Expand All @@ -176,7 +186,7 @@ Specifies the port for the HPB service.

##### `hpb_service_config_file`

Data type: `Stdlib::Compat::Absolute_path`
Data type: `Stdlib::Absolutepath`

Specifies the full path to the HPB service config file.

Expand All @@ -188,7 +198,7 @@ Specifies the desired state of the HPB service.

##### `hpb_service_file`

Data type: `Stdlib::Compat::Absolute_path`
Data type: `Stdlib::Absolutepath`

Specifies the full path to the HPB service definition / startup script.

Expand All @@ -215,7 +225,7 @@ run manually and some features may not work as expected (not recommended).

##### `installroot`

Data type: `Stdlib::Compat::Absolute_path`
Data type: `Stdlib::Absolutepath`

Specifies the base directory where Nextcloud should be installed. A new
subdirectory for each version will be created.
Expand Down Expand Up @@ -299,7 +309,7 @@ should be executed.

##### `statefile`

Data type: `Stdlib::Compat::Absolute_path`
Data type: `Stdlib::Absolutepath`

A file that is required by the module to work properly. This value MUST NOT
be changed, because the path is hardcoded in several places.
Expand Down Expand Up @@ -406,7 +416,7 @@ Default value: `'system'`

##### `value`

Data type: `Variant[Boolean, Integer, String]`
Data type: `Variant[Boolean, Float, Integer, String]`

The configuration value that should be set.

Expand All @@ -418,7 +428,7 @@ The configuration key to find out whether it needs to be altered.

##### `verify_value`

Data type: `Variant[Boolean, Integer, String]`
Data type: `Variant[Boolean, Float, Integer, String]`

The configuration verify to find out whether it needs to be altered.

Expand Down
1 change: 1 addition & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ nextcloud::config:
- 'localhost'
- "%{facts.networking.fqdn}"
filelocking.enabled: true
nextcloud::cron_host: ~
nextcloud::cronjobs:
'Nextcloud background job':
command: "php -f %%{}s/cron.php >/dev/null 2>&1"
Expand Down
54 changes: 29 additions & 25 deletions manifests/cron.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,39 @@

# Only manage cron jobs if this feature is enabled.
if ($nextcloud::manage_cron) {
# Iterate over all cron jobs.
$nextcloud::cronjobs.each | $_cron, $_config| {
# Ignore invalid cron configurations.
if (($_config =~ Hash) and ('command' in $_config)) {
# Set environment variables.
if ('environment' in $_config) {
$_environment = $_config['environment'] + ["PATH=${nextcloud::path}"]
} else {
$_environment = ["PATH=${nextcloud::path}"]
}
# Add Nextcloud's installation directory to the command.
$_cmd = sprintf($_config['command'], $nextcloud::symlink)
# Check if this is the designated host for cron jobs.
if (($nextcloud::cron_host == undef or empty($nextcloud::cron_host))
or ($nextcloud::cron_host == $facts['networking']['fqdn'])) {
# Iterate over all cron jobs.
$nextcloud::cronjobs.each | $_cron, $_config| {
# Ignore invalid cron configurations.
if (($_config =~ Hash) and ('command' in $_config)) {
# Set environment variables.
if ('environment' in $_config) {
$_environment = $_config['environment'] + ["PATH=${nextcloud::path}"]
} else {
$_environment = ["PATH=${nextcloud::path}"]
}
# Add Nextcloud's installation directory to the command.
$_cmd = sprintf($_config['command'], $nextcloud::symlink)

# Ensure that the cron job does not run during updates.
$_real_cmd = "test ! -f ${nextcloud::update::update_lock} && ${_cmd}"
# Ensure that the cron job does not run during updates.
$_real_cmd = "test ! -f ${nextcloud::update::update_lock} && ${_cmd}"

# Finalize the config by adding Nextcloud's username.
$_real_config = $_config + {
command => $_real_cmd,
environment => $_environment,
user => $nextcloud::system_user,
}
# Finalize the config by adding Nextcloud's username.
$_real_config = $_config + {
command => $_real_cmd,
environment => $_environment,
user => $nextcloud::system_user,
}

# Finally add the cron job.
cron { $_cron:
* => $_real_config,
# Finally add the cron job.
cron { $_cron:
* => $_real_config,
}
} else {
fail("Invalid config for cron job \'${_cron}\'")
}
} else {
fail("Invalid config for cron job \'${_cron}\'")
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
# @param config
# A hash containing configuration options for Nextcloud.
#
# @param cron_host
# Optional parameter to specify the FQDN of the host where all cronjobs
# should run. Limiting these commands to a single host should prevent
# race conditions.
#
# @param cronjobs
# Specifies a list of cron jobs that should be added when
# `$manage_cron` is enabled.
Expand Down Expand Up @@ -220,6 +225,7 @@
String $system_user,
Variant[Boolean, Enum['none']] $update_enabled,
String $version,
Optional[String] $cron_host = undef,
Optional[String] $update_host = undef,
) {
# Merge configuration options.
Expand Down

0 comments on commit 0d25dc2

Please sign in to comment.