1313# Options:
1414# --install-dir PATH Installation directory (default: /opt/perfsonar-tp)
1515# --with-certbot Install certbot service alongside testpoint
16+ # --auto-update Install perfsonar-auto-update.sh and a daily systemd
17+ # timer that pulls new images and restarts services only
18+ # when an image digest has changed (Podman-compatible;
19+ # does not rely on Docker-specific output strings)
1620# --help Show this help message
1721#
1822# Requirements:
2125# - perfSONAR testpoint scripts in installation directory
2226#
2327# Author: OSG perfSONAR deployment tools
24- # Version: 1.0 .0
28+ # Version: 1.1 .0
2529# Acknowledgements: Supported by IRIS-HEP and OSG-LHC
2630
2731set -e
2832
2933# Default values
3034INSTALL_DIR=" /opt/perfsonar-tp"
3135WITH_CERTBOT=false
36+ AUTO_UPDATE=false
3237
3338# Parse arguments
3439while [[ $# -gt 0 ]]; do
@@ -41,8 +46,12 @@ while [[ $# -gt 0 ]]; do
4146 WITH_CERTBOT=true
4247 shift
4348 ;;
49+ --auto-update)
50+ AUTO_UPDATE=true
51+ shift
52+ ;;
4453 --help)
45- head -n 20 " $0 " | grep " ^#" | sed ' s/^# \?//'
54+ head -n 25 " $0 " | grep " ^#" | sed ' s/^# \?//'
4655 exit 0
4756 ;;
4857 * )
8594echo " ==> Installing systemd units for perfSONAR testpoint"
8695echo " Installation directory: $INSTALL_DIR "
8796
88- # Create perfsonar-testpoint service
97+ # When --auto-update is the only goal (service already exists), skip rewriting
98+ # the testpoint/certbot service units to avoid disrupting a running deployment.
99+ SKIP_SERVICE_UNITS=false
100+ if [[ " $AUTO_UPDATE " == " true" && -f " $TESTPOINT_SERVICE " ]]; then
101+ echo " ==> Existing $TESTPOINT_SERVICE detected — skipping service unit rewrite (use without --auto-update to reinstall)"
102+ SKIP_SERVICE_UNITS=true
103+ fi
104+
105+ # Create perfsonar-testpoint service (skip if already present and only --auto-update was requested)
106+ if [[ " $SKIP_SERVICE_UNITS " == " false" ]]; then
89107cat > " $TESTPOINT_SERVICE " << EOF
90108[Unit]
91109Description=perfSONAR Testpoint Container
@@ -158,43 +176,133 @@ EOF
158176 echo " ==> ✓ Created $CERTBOT_SERVICE "
159177fi
160178
179+ fi # end SKIP_SERVICE_UNITS guard
180+
161181# Reload systemd
162182echo " ==> Reloading systemd daemon"
163183systemctl daemon-reload
164184
165- # Enable services
166- echo " ==> Enabling perfsonar-testpoint service"
167- systemctl enable perfsonar-testpoint.service
185+ # Enable services (only if service units were written)
186+ if [[ " $SKIP_SERVICE_UNITS " == " false" ]]; then
187+ echo " ==> Enabling perfsonar-testpoint service"
188+ systemctl enable perfsonar-testpoint.service
168189
169- if [[ " $WITH_CERTBOT " == " true" ]]; then
170- echo " ==> Enabling perfsonar-certbot service"
171- systemctl enable perfsonar-certbot.service
172- fi
190+ if [[ " $WITH_CERTBOT " == " true" ]]; then
191+ echo " ==> Enabling perfsonar-certbot service"
192+ systemctl enable perfsonar-certbot.service
193+ fi
173194
174- echo " "
175- echo " ==> ✓ Systemd units installed and enabled successfully"
176- echo " "
177- echo " Useful commands:"
178- echo " Start services: systemctl start perfsonar-testpoint.service"
179- if [[ " $WITH_CERTBOT " == " true" ]]; then
180- echo " systemctl start perfsonar-certbot.service"
195+ echo " "
196+ echo " ==> ✓ Systemd units installed and enabled successfully"
197+ echo " "
198+ echo " Useful commands:"
199+ echo " Start services: systemctl start perfsonar-testpoint.service"
200+ if [[ " $WITH_CERTBOT " == " true" ]]; then
201+ echo " systemctl start perfsonar-certbot.service"
202+ fi
203+ echo " Stop services: systemctl stop perfsonar-testpoint.service"
204+ if [[ " $WITH_CERTBOT " == " true" ]]; then
205+ echo " systemctl stop perfsonar-certbot.service"
206+ fi
207+ echo " Check status: systemctl status perfsonar-testpoint.service"
208+ if [[ " $WITH_CERTBOT " == " true" ]]; then
209+ echo " systemctl status perfsonar-certbot.service"
210+ fi
211+ echo " View logs: journalctl -u perfsonar-testpoint.service -f"
212+ if [[ " $WITH_CERTBOT " == " true" ]]; then
213+ echo " journalctl -u perfsonar-certbot.service -f"
214+ fi
215+ echo " Check containers: podman ps"
216+ echo " "
217+ echo " The services will automatically start containers on boot."
218+ echo " "
219+ echo " Note: These units use 'podman run --systemd=always' for proper systemd"
220+ echo " support inside the container. This is required for the testpoint"
221+ echo " image which runs systemd internally."
181222fi
182- echo " Stop services: systemctl stop perfsonar-testpoint.service"
183- if [[ " $WITH_CERTBOT " == " true" ]]; then
184- echo " systemctl stop perfsonar-certbot.service"
185- fi
186- echo " Check status: systemctl status perfsonar-testpoint.service"
187- if [[ " $WITH_CERTBOT " == " true" ]]; then
188- echo " systemctl status perfsonar-certbot.service"
189- fi
190- echo " View logs: journalctl -u perfsonar-testpoint.service -f"
191- if [[ " $WITH_CERTBOT " == " true" ]]; then
192- echo " journalctl -u perfsonar-certbot.service -f"
223+
224+ # ── Optional: auto-update timer ────────────────────────────────────────────────
225+ if [[ " $AUTO_UPDATE " == " true" ]]; then
226+ AUTO_UPDATE_SCRIPT=" $INSTALL_DIR /tools_scripts/perfSONAR-auto-update.sh"
227+ AUTO_UPDATE_BIN=" /usr/local/bin/perfsonar-auto-update.sh"
228+ AUTO_UPDATE_SVC=" /etc/systemd/system/perfsonar-auto-update.service"
229+ AUTO_UPDATE_TIMER=" /etc/systemd/system/perfsonar-auto-update.timer"
230+
231+ echo " "
232+ echo " ==> Installing auto-update timer"
233+
234+ # Use the versioned script from tools_scripts if present, else fall back to a
235+ # minimal inline version.
236+ if [[ -f " $AUTO_UPDATE_SCRIPT " ]]; then
237+ cp " $AUTO_UPDATE_SCRIPT " " $AUTO_UPDATE_BIN "
238+ else
239+ echo " WARNING: $AUTO_UPDATE_SCRIPT not found; writing minimal inline script."
240+ cat > " $AUTO_UPDATE_BIN " << 'AUTOUPDATE_EOF '
241+ #!/bin/bash
242+ # perfsonar-auto-update.sh (minimal inline fallback)
243+ # For the full versioned script, re-run bootstrap (install_tools_scripts.sh).
244+ set -euo pipefail
245+ LOGFILE="/var/log/perfsonar-auto-update.log"
246+ TESTPOINT_IMAGE="hub.opensciencegrid.org/osg-htc/perfsonar-testpoint:production"
247+ CERTBOT_IMAGE="docker.io/certbot/certbot:latest"
248+ log() { echo "$(date -Iseconds) $*" | tee -a "$LOGFILE"; }
249+ get_id() { podman image inspect "$1" --format '{{.Id}}' 2>/dev/null || echo none; }
250+ check_pull() {
251+ local img=$1 before after
252+ before=$(get_id "$img")
253+ podman pull "$img" >> "$LOGFILE" 2>&1 || { log "WARNING: pull failed for $img"; echo unchanged; return; }
254+ after=$(get_id "$img")
255+ [[ "$before" == "none" || "$before" != "$after" ]] && echo updated || echo unchanged
256+ }
257+ log '=== perfSONAR auto-update check ==='
258+ ANY=false
259+ [[ $(check_pull "$TESTPOINT_IMAGE") == updated ]] && ANY=true
260+ podman ps -a --format '{{.Names}}' 2>/dev/null | grep -q '^certbot$' && \
261+ [[ $(check_pull "$CERTBOT_IMAGE") == updated ]] && ANY=true
262+ $ANY && systemctl restart perfsonar-testpoint.service && log 'Restarted testpoint.service' || log 'No updates'
263+ log '=== done ==='
264+ AUTOUPDATE_EOF
265+ fi
266+ chmod 0755 " $AUTO_UPDATE_BIN "
267+ echo " ==> ✓ Installed $AUTO_UPDATE_BIN "
268+
269+ cat > " $AUTO_UPDATE_SVC " << 'EOF '
270+ [Unit]
271+ Description=perfSONAR Container Auto-Update
272+ After=network-online.target
273+
274+ [Service]
275+ Type=oneshot
276+ ExecStart=/usr/local/bin/perfsonar-auto-update.sh
277+ StandardOutput=journal
278+ StandardError=journal
279+
280+ [Install]
281+ WantedBy=multi-user.target
282+ EOF
283+ echo " ==> ✓ Created $AUTO_UPDATE_SVC "
284+
285+ cat > " $AUTO_UPDATE_TIMER " << 'EOF '
286+ [Unit]
287+ Description=perfSONAR Container Auto-Update Timer
288+
289+ [Timer]
290+ OnCalendar=*-*-* 03:00:00
291+ RandomizedDelaySec=1h
292+ Persistent=true
293+
294+ [Install]
295+ WantedBy=timers.target
296+ EOF
297+ echo " ==> ✓ Created $AUTO_UPDATE_TIMER "
298+
299+ systemctl daemon-reload
300+ systemctl enable --now perfsonar-auto-update.timer
301+ echo " ==> ✓ Enabled perfsonar-auto-update.timer (runs daily at 03:00 + up to 1h random delay)"
302+ echo " "
303+ echo " Useful auto-update commands:"
304+ echo " Check timer: systemctl list-timers perfsonar-auto-update.timer"
305+ echo " Run now (test): systemctl start perfsonar-auto-update.service"
306+ echo " View log: journalctl -u perfsonar-auto-update.service -f"
307+ echo " Update log file: tail -f /var/log/perfsonar-auto-update.log"
193308fi
194- echo " Check containers: podman ps"
195- echo " "
196- echo " The services will automatically start containers on boot."
197- echo " "
198- echo " Note: These units use 'podman run --systemd=always' for proper systemd"
199- echo " support inside the container. This is required for the testpoint"
200- echo " image which runs systemd internally."
0 commit comments