diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-23 16:25:42 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-27 20:38:05 +0000 |
| commit | 0b9527ede03521a40f1174a5a6e40a943bf27e2d (patch) | |
| tree | 851d0b8a4dfb0d73f3964a473548cdb4c526a59c /docs/how-to | |
| parent | 2b21b807bdf6c0bab548ffceb5c41eee0902890c (diff) | |
Fix Phase 4 scripts to run flawlessly without manual intervention
Make scripts fully automatic with no manual intervention needed.
Changes:
- Add --no-pager to journalctl commands in validate-service.sh
- Add service existence validation with helpful error messages
- Capture and report journalctl stderr for better error visibility
- Improve error handling without failing on empty logs
The main issue was missing --no-pager in validate-service.sh which
could cause scripts to hang when run non-interactively (e.g., via SSH).
Tested locally - scripts run without hanging and produce correct output.
Diffstat (limited to 'docs/how-to')
3 files changed, 57 insertions, 6 deletions
diff --git a/docs/how-to/migration-scripts/30-extract-parse-failures.sh b/docs/how-to/migration-scripts/30-extract-parse-failures.sh index 410fcbc..d4f0ff2 100755 --- a/docs/how-to/migration-scripts/30-extract-parse-failures.sh +++ b/docs/how-to/migration-scripts/30-extract-parse-failures.sh | |||
| @@ -236,6 +236,19 @@ main() { | |||
| 236 | exit 1 | 236 | exit 1 |
| 237 | fi | 237 | fi |
| 238 | 238 | ||
| 239 | # Validate service exists (check if journalctl can find any logs for it) | ||
| 240 | # Note: We don't require the service to be running, just that it has logs | ||
| 241 | if ! journalctl --no-pager -u "$service" -n 1 &>/dev/null; then | ||
| 242 | log_warn "Could not query logs for service: $service" | ||
| 243 | log_warn "This may indicate the service doesn't exist or you lack permissions." | ||
| 244 | log_warn "" | ||
| 245 | log_warn "To list available ngit-grasp services:" | ||
| 246 | log_warn " systemctl list-units 'ngit-grasp*' --all" | ||
| 247 | log_warn " journalctl --list-boots # Check if you have journal access" | ||
| 248 | log_warn "" | ||
| 249 | # Continue anyway - the service might exist but have no logs yet | ||
| 250 | fi | ||
| 251 | |||
| 239 | # Build journalctl command | 252 | # Build journalctl command |
| 240 | local journal_cmd="journalctl -u $service --no-pager -o short-iso" | 253 | local journal_cmd="journalctl -u $service --no-pager -o short-iso" |
| 241 | 254 | ||
| @@ -280,8 +293,20 @@ main() { | |||
| 280 | log_info "Extracting log entries..." | 293 | log_info "Extracting log entries..." |
| 281 | 294 | ||
| 282 | # Get raw log lines containing [PARSE_FAIL] | 295 | # Get raw log lines containing [PARSE_FAIL] |
| 283 | local raw_lines | 296 | # Capture stderr separately to detect journalctl errors |
| 284 | raw_lines=$(eval "$journal_cmd" 2>/dev/null | grep '\[PARSE_FAIL\]' || true) | 297 | local raw_lines journal_stderr journal_exit |
| 298 | local temp_stderr | ||
| 299 | temp_stderr=$(mktemp) | ||
| 300 | |||
| 301 | raw_lines=$(eval "$journal_cmd" 2>"$temp_stderr" | grep '\[PARSE_FAIL\]' || true) | ||
| 302 | journal_exit=$? | ||
| 303 | journal_stderr=$(cat "$temp_stderr" 2>/dev/null || true) | ||
| 304 | rm -f "$temp_stderr" | ||
| 305 | |||
| 306 | # Report any journalctl errors (but don't fail - empty logs are valid) | ||
| 307 | if [[ -n "$journal_stderr" ]]; then | ||
| 308 | log_warn "journalctl reported: $journal_stderr" | ||
| 309 | fi | ||
| 285 | 310 | ||
| 286 | if [[ -z "$raw_lines" ]]; then | 311 | if [[ -z "$raw_lines" ]]; then |
| 287 | log_warn "No [PARSE_FAIL] entries found in logs." | 312 | log_warn "No [PARSE_FAIL] entries found in logs." |
diff --git a/docs/how-to/migration-scripts/31-extract-purgatory-expiry.sh b/docs/how-to/migration-scripts/31-extract-purgatory-expiry.sh index a20780e..a603a1e 100755 --- a/docs/how-to/migration-scripts/31-extract-purgatory-expiry.sh +++ b/docs/how-to/migration-scripts/31-extract-purgatory-expiry.sh | |||
| @@ -243,6 +243,19 @@ main() { | |||
| 243 | exit 1 | 243 | exit 1 |
| 244 | fi | 244 | fi |
| 245 | 245 | ||
| 246 | # Validate service exists (check if journalctl can find any logs for it) | ||
| 247 | # Note: We don't require the service to be running, just that it has logs | ||
| 248 | if ! journalctl --no-pager -u "$service" -n 1 &>/dev/null; then | ||
| 249 | log_warn "Could not query logs for service: $service" | ||
| 250 | log_warn "This may indicate the service doesn't exist or you lack permissions." | ||
| 251 | log_warn "" | ||
| 252 | log_warn "To list available ngit-grasp services:" | ||
| 253 | log_warn " systemctl list-units 'ngit-grasp*' --all" | ||
| 254 | log_warn " journalctl --list-boots # Check if you have journal access" | ||
| 255 | log_warn "" | ||
| 256 | # Continue anyway - the service might exist but have no logs yet | ||
| 257 | fi | ||
| 258 | |||
| 246 | # Build journalctl command | 259 | # Build journalctl command |
| 247 | local journal_cmd="journalctl -u $service --no-pager -o short-iso" | 260 | local journal_cmd="journalctl -u $service --no-pager -o short-iso" |
| 248 | 261 | ||
| @@ -287,8 +300,20 @@ main() { | |||
| 287 | log_info "Extracting log entries..." | 300 | log_info "Extracting log entries..." |
| 288 | 301 | ||
| 289 | # Get raw log lines containing [PURGATORY_EXPIRED] | 302 | # Get raw log lines containing [PURGATORY_EXPIRED] |
| 290 | local raw_lines | 303 | # Capture stderr separately to detect journalctl errors |
| 291 | raw_lines=$(eval "$journal_cmd" 2>/dev/null | grep '\[PURGATORY_EXPIRED\]' || true) | 304 | local raw_lines journal_stderr journal_exit |
| 305 | local temp_stderr | ||
| 306 | temp_stderr=$(mktemp) | ||
| 307 | |||
| 308 | raw_lines=$(eval "$journal_cmd" 2>"$temp_stderr" | grep '\[PURGATORY_EXPIRED\]' || true) | ||
| 309 | journal_exit=$? | ||
| 310 | journal_stderr=$(cat "$temp_stderr" 2>/dev/null || true) | ||
| 311 | rm -f "$temp_stderr" | ||
| 312 | |||
| 313 | # Report any journalctl errors (but don't fail - empty logs are valid) | ||
| 314 | if [[ -n "$journal_stderr" ]]; then | ||
| 315 | log_warn "journalctl reported: $journal_stderr" | ||
| 316 | fi | ||
| 292 | 317 | ||
| 293 | if [[ -z "$raw_lines" ]]; then | 318 | if [[ -z "$raw_lines" ]]; then |
| 294 | log_warn "No [PURGATORY_EXPIRED] entries found in logs." | 319 | log_warn "No [PURGATORY_EXPIRED] entries found in logs." |
diff --git a/docs/how-to/migration-scripts/validate-service.sh b/docs/how-to/migration-scripts/validate-service.sh index 2525a3f..6988af3 100755 --- a/docs/how-to/migration-scripts/validate-service.sh +++ b/docs/how-to/migration-scripts/validate-service.sh | |||
| @@ -108,9 +108,10 @@ validate_service_for_structured_logging() { | |||
| 108 | fi | 108 | fi |
| 109 | 109 | ||
| 110 | # Check for structured log entries | 110 | # Check for structured log entries |
| 111 | # IMPORTANT: Use --no-pager to prevent hanging when run non-interactively (e.g., via SSH) | ||
| 111 | local has_parse_fail has_purgatory | 112 | local has_parse_fail has_purgatory |
| 112 | has_parse_fail=$(journalctl -u "$service_name" --since "7 days ago" 2>/dev/null | grep -c '\[PARSE_FAIL\]' || echo "0") | 113 | has_parse_fail=$(journalctl --no-pager -u "$service_name" --since "7 days ago" 2>/dev/null | grep -c '\[PARSE_FAIL\]' || echo "0") |
| 113 | has_purgatory=$(journalctl -u "$service_name" --since "7 days ago" 2>/dev/null | grep -c '\[PURGATORY_EXPIRED\]' || echo "0") | 114 | has_purgatory=$(journalctl --no-pager -u "$service_name" --since "7 days ago" 2>/dev/null | grep -c '\[PURGATORY_EXPIRED\]' || echo "0") |
| 114 | 115 | ||
| 115 | # Strip any non-numeric characters (grep -c can have trailing whitespace) | 116 | # Strip any non-numeric characters (grep -c can have trailing whitespace) |
| 116 | has_parse_fail="${has_parse_fail//[^0-9]/}" | 117 | has_parse_fail="${has_parse_fail//[^0-9]/}" |