SYSTEMD PATH FIX: Correct repository path for systemd sync in CI environments Issue Fixed: ❌ Repository systemd directory not found: /opt/aitbc/systemd ❌ CI workflows looking for wrong repository path ❌ Systemd sync failing in CI environments Root Cause: - CI workflows clone repository to workspace directories - Systemd sync script hardcoded to /opt/aitbc/systemd - Repository actually in /opt/aitbc/*-workspace/repo/systemd - Path mismatch causing sync failures Solution Applied: ✅ Dynamic path updates in all workflows ✅ sed commands to update REPO_SYSTEMD_DIR at runtime ✅ Correct paths for each workflow workspace ✅ Fallback manual sync with correct paths Fixed Workflows: 1. systemd-sync.yml: - Updated to use /opt/aitbc/systemd-sync-workspace/repo/systemd - Dynamic path update before running script 2. integration-tests.yml: - Updated to use /opt/aitbc/integration-tests-workspace/repo/systemd - Dynamic path update before running script 3. api-endpoint-tests.yml: - Updated to use /opt/aitbc/api-tests-workspace/repo/systemd - Dynamic path update before running script Changes Made: - Added sed commands to update REPO_SYSTEMD_DIR - Each workflow uses its own workspace path - Maintains original script functionality - Preserves fallback manual sync Impact: - Systemd sync now works in CI environments - Service-dependent workflows can start services - Integration and API tests can run properly - No more path-related failures This resolves the critical path issue that was preventing systemd sync and service-dependent workflows from working in the CI/CD environment.
184 lines
6.6 KiB
YAML
184 lines
6.6 KiB
YAML
name: systemd-sync
|
|
|
|
on:
|
|
push:
|
|
branches: [ main, develop ]
|
|
paths:
|
|
- 'systemd/**'
|
|
- '.gitea/workflows/systemd-sync.yml'
|
|
workflow_dispatch:
|
|
|
|
# Prevent parallel execution - run workflows serially
|
|
concurrency:
|
|
group: ci-workflows
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
sync-systemd:
|
|
runs-on: debian
|
|
|
|
steps:
|
|
- name: Setup workspace
|
|
run: |
|
|
echo "=== SYSTEMD SYNC SETUP ==="
|
|
echo "Current PWD: $(pwd)"
|
|
echo "Forcing absolute workspace path..."
|
|
|
|
# Clean and create isolated workspace
|
|
rm -rf /opt/aitbc/systemd-sync-workspace
|
|
mkdir -p /opt/aitbc/systemd-sync-workspace
|
|
cd /opt/aitbc/systemd-sync-workspace
|
|
|
|
# Ensure no git lock files exist
|
|
find . -name "*.lock" -delete 2>/dev/null || true
|
|
|
|
echo "Workspace PWD: $(pwd)"
|
|
echo "Cloning repository..."
|
|
git clone https://gitea.bubuit.net/oib/aitbc.git repo
|
|
|
|
cd repo
|
|
echo "Repo PWD: $(pwd)"
|
|
echo "Files in repo:"
|
|
ls -la
|
|
|
|
- name: Sync Systemd Files
|
|
run: |
|
|
echo "=== SYNCING SYSTEMD FILES ==="
|
|
cd /opt/aitbc/systemd-sync-workspace/repo
|
|
|
|
echo "Repository systemd files:"
|
|
ls -la systemd/ | head -10
|
|
echo
|
|
echo "Active systemd files:"
|
|
ls -la /etc/systemd/system/aitbc-* | head -5 || echo "No active files found"
|
|
echo
|
|
|
|
# Check if running as root (should be in CI)
|
|
if [[ $EUID -eq 0 ]]; then
|
|
echo "✅ Running as root - can sync systemd files"
|
|
|
|
# Run the linking script
|
|
if [[ -f "scripts/link-systemd.sh" ]]; then
|
|
echo "🔗 Running systemd linking script..."
|
|
# Update script with correct repository path
|
|
sed -i "s|REPO_SYSTEMD_DIR=\"/opt/aitbc/systemd\"|REPO_SYSTEMD_DIR=\"/opt/aitbc/systemd-sync-workspace/repo/systemd\"|g" scripts/link-systemd.sh
|
|
./scripts/link-systemd.sh
|
|
else
|
|
echo "❌ Link script not found, creating manual sync..."
|
|
|
|
# Manual sync as fallback
|
|
REPO_SYSTEMD_DIR="/opt/aitbc/systemd-sync-workspace/repo/systemd"
|
|
ACTIVE_SYSTEMD_DIR="/etc/systemd/system"
|
|
|
|
# Create backup
|
|
BACKUP_DIR="/opt/aitbc/systemd-backup-$(date +%Y%m%d-%H%M%S)"
|
|
mkdir -p "$BACKUP_DIR"
|
|
find "$ACTIVE_SYSTEMD_DIR" -name "aitbc-*" -type f -exec cp {} "$BACKUP_DIR/" \; 2>/dev/null || true
|
|
|
|
# Create symbolic links
|
|
for file in "$REPO_SYSTEMD_DIR"/aitbc-*; do
|
|
if [[ -f "$file" ]]; then
|
|
filename=$(basename "$file")
|
|
target="$ACTIVE_SYSTEMD_DIR/$filename"
|
|
source="$REPO_SYSTEMD_DIR/$filename"
|
|
|
|
echo "🔗 Linking: $filename"
|
|
ln -sf "$source" "$target"
|
|
|
|
# Handle .d directories
|
|
if [[ -d "${file}.d" ]]; then
|
|
target_dir="${target}.d"
|
|
source_dir="${file}.d"
|
|
rm -rf "$target_dir" 2>/dev/null || true
|
|
ln -sf "$source_dir" "$target_dir"
|
|
fi
|
|
fi
|
|
done
|
|
|
|
systemctl daemon-reload
|
|
echo "✅ Manual systemd sync completed"
|
|
fi
|
|
|
|
else
|
|
echo "⚠️ Not running as root - systemd sync requires root privileges"
|
|
echo " To sync manually: sudo ./scripts/link-systemd.sh"
|
|
fi
|
|
|
|
- name: Verify Sync
|
|
run: |
|
|
echo "=== VERIFYING SYSTEMD SYNC ==="
|
|
cd /opt/aitbc/systemd-sync-workspace/repo
|
|
|
|
if [[ $EUID -eq 0 ]]; then
|
|
echo "🔍 Verifying systemd links..."
|
|
|
|
# Check if links exist
|
|
echo "Checking symbolic links:"
|
|
for file in systemd/aitbc-*; do
|
|
if [[ -f "$file" ]]; then
|
|
filename=$(basename "$file")
|
|
target="/etc/systemd/system/$filename"
|
|
|
|
if [[ -L "$target" ]]; then
|
|
echo "✅ $filename -> $(readlink "$target")"
|
|
elif [[ -f "$target" ]]; then
|
|
echo "⚠️ $filename exists but is not a link (copied file)"
|
|
else
|
|
echo "❌ $filename not found in active systemd"
|
|
fi
|
|
fi
|
|
done
|
|
|
|
echo
|
|
echo "📊 Summary:"
|
|
echo " Repository files: $(find systemd -name 'aitbc-*' -type f | wc -l)"
|
|
echo " Active files: $(find /etc/systemd/system -name 'aitbc-*' -type f | wc -l)"
|
|
echo " Symbolic links: $(find /etc/systemd/system -name 'aitbc-*' -type l | wc -l)"
|
|
|
|
else
|
|
echo "⚠️ Cannot verify without root privileges"
|
|
fi
|
|
|
|
- name: Service Status Check
|
|
if: always()
|
|
run: |
|
|
echo "=== SERVICE STATUS CHECK ==="
|
|
|
|
if [[ $EUID -eq 0 ]]; then
|
|
echo "🔍 Checking AITBC service status..."
|
|
|
|
# Check if services are enabled
|
|
echo "Enabled services:"
|
|
systemctl list-unit-files 'aitbc-*' --state=enabled | head -5 || echo "No enabled services found"
|
|
|
|
echo
|
|
echo "Failed services:"
|
|
systemctl list-units 'aitbc-*' --state=failed | head -5 || echo "No failed services found"
|
|
|
|
echo
|
|
echo "Running services:"
|
|
systemctl list-units 'aitbc-*' --state=running | head -5 || echo "No running services found"
|
|
|
|
else
|
|
echo "⚠️ Cannot check service status without root privileges"
|
|
fi
|
|
|
|
- name: Instructions
|
|
run: |
|
|
echo "=== SYSTEMD SYNC INSTRUCTIONS ==="
|
|
echo
|
|
echo "🔧 Manual sync (if needed):"
|
|
echo " sudo ./scripts/link-systemd.sh"
|
|
echo
|
|
echo "🔄 Restart services:"
|
|
echo " sudo systemctl restart aitbc-blockchain-node"
|
|
echo " sudo systemctl restart aitbc-coordinator-api"
|
|
echo " sudo systemctl restart aitbc-*"
|
|
echo
|
|
echo "🔍 Check status:"
|
|
echo " sudo systemctl status aitbc-*"
|
|
echo
|
|
echo "🔍 Verify links:"
|
|
echo " ls -la /etc/systemd/system/aitbc-*"
|
|
echo " readlink /etc/systemd/system/aitbc-blockchain-node.service"
|