Skip to content

Commit

Permalink
Add sync-head 15-minutes timer script
Browse files Browse the repository at this point in the history
This new script update repodata contents from NS8 upstream repository.
Its copied contents are used to see modules in the Software Center page, as
opposed to the take-snapshot script, which manages the content for the
nightly update cronjob of subscription installations.
  • Loading branch information
DavidePrincipi committed Jul 15, 2024
1 parent 06a5832 commit 830ae03
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 5 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ Change one or more attributes with a command like this:
To publish the repository, a HTTP host name route must be configured from
the cluster-admin Settings page.

When the `configure-module` action is executed for the first time, service
and timer units are enabled and started.

Timers are:

- `take-snapshot.timer` is a weekly job that update Rocky Linux repository
mirror contents and makes a copy of repodata.json and other metadata
from NS8 repositories.

- `sync-head.timer` is a frequent job that 4 times per hour, from Monday to
Friday and during working hours, makes a copy of repodata.json and other
metadata from NS8 repositories.

Services are:

- `fpm.service`
- `nginx.service`

## Commands

### `take-snapshot`
Expand All @@ -68,6 +86,16 @@ As alternative start the equivalent Systemd service:

runagent -m porthos1 systemctl --user start snapshot

### `sync-head`

To synchronize the copy of NS8 repodata with its upstream manually run:

runagent -m porthos1 sync-head

As alternative start the equivalent Systemd service:

runagent -m porthos1 systemctl --user start sync-head

### Inspect the services status

Print the status of relevant Systemd units:
Expand Down
4 changes: 2 additions & 2 deletions imageroot/actions/configure-module/80restart_services
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ set -e
exec 1>&2

if [[ -z ${PORTHOS_FIRST_CONFIG} ]]; then
systemctl --user enable --now fpm.service nginx.service snapshot.timer
systemctl --user enable --now fpm.service nginx.service snapshot.timer sync-head.timer
echo 'PORTHOS_FIRST_CONFIG=1' >> environment
else
systemctl --user try-reload-or-restart fpm.service nginx.service snapshot.timer
systemctl --user try-reload-or-restart fpm.service nginx.service snapshot.timer sync-head.timer
fi
32 changes: 32 additions & 0 deletions imageroot/bin/sync-head
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

#
# Copyright (C) 2024 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#

set -e
shopt -s nullglob

# shellcheck disable=SC1091
source /etc/nethserver/core.env
new_head=tmp.$(date +head.%Y%m%dt%H%I%S%2N)
rsync_opts=(-aiSH --no-motd --no-super --no-perms --chmod=ugo=rwX --no-g --no-o --delete-after)
distfeed_url=https://github.com/NethServer/ns8-repomd/archive/refs/heads/repomd.tar.gz

cd /srv/porthos/webroot

trap 'rm -rf remove."${new_head}" "${new_head}"' EXIT

printf "Sync distfeed head from %s\n" "${distfeed_url}"
mkdir -vp "${new_head}/distfeed" head
curl --fail -L -O --output-dir "${new_head}" "${distfeed_url}"
tar -z -x --strip-components=1 -f "${new_head}/repomd.tar.gz" -C "${new_head}/distfeed"
rm -f "${new_head}/repomd.tar.gz"

# Substitute the head directory with new_head
mv head remove."${new_head}"
mv -v "${new_head}" head



15 changes: 12 additions & 3 deletions imageroot/script/snapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,30 @@ function main() {
echo "Not found\n";
}

$repo_view = isset($_SERVER['HTTP_X_REPO_VIEW']) ? $_SERVER['HTTP_X_REPO_VIEW'] : "latest";
$username = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : "";
$password = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : "";

sort($lsnapshots);

$snapshot = array_pop($lsnapshots);
if($username && $password) {
// Authenticated clients gain access to older tiers
if($repo_view == "managed" && $username && $password) {
// Access to managed updates for authenticated clients.
$snapshot = array_pop($lsnapshots);
while($snapshot != NULL) {
$tier_id = system_tier($username);
if (snapshot_age($snapshot) >= $tier_age[$tier_id]) {
break;
}
$snapshot = array_pop($lsnapshots);
}
} else if (substr($_SERVER['DOCUMENT_URI'], 0, 10) == "/distfeed/") {
// Access to latest metadata (distfeed) if client is not
// authenticated, or if the request comes from the user through
// the Software Center APIs.
$snapshot = 'head';
} else {
// Access to latest DNF mirror contents.
$snapshot = array_pop($lsnapshots);
}

header('Cache-Control: private');
Expand Down
12 changes: 12 additions & 0 deletions imageroot/systemd/user/sync-head.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Copyright (C) 2023 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#

[Unit]
Description=Scheduled Porthos sync-head procedure

[Service]
Type=oneshot
ExecStart=runagent sync-head
SyslogIdentifier=%N
13 changes: 13 additions & 0 deletions imageroot/systemd/user/sync-head.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#
# Copyright (C) 2023 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#

[Unit]
Description=Timer of Porthos sync-head procedure

[Timer]
OnCalendar=Mon..Fri *-*-* 07..17:00,15,45:00 UTC

[Install]
WantedBy=timers.target

0 comments on commit 830ae03

Please sign in to comment.