Files
syscall_monitor/.gitea/workflows/cd.yml
MarceloZoeng b082012782
Some checks failed
CI / lint-and-build (push) Failing after 2s
CD / deploy (push) Failing after 31s
no message
2026-06-11 00:08:23 +08:00

90 lines
2.5 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: CD
on:
push:
tags:
- "v*"
workflow_dispatch:
env:
DEPLOY_DIR: /opt/syscall_monitor
HEALTH_URL: http://127.0.0.1:5000
jobs:
deploy:
runs-on: self-hosted
steps:
- name: Checkout
uses: https://gitea.com/actions/checkout@v4
- name: Show target host info
run: |
echo "deploying on: $(hostname)"
echo "user: $(id -un) ($(id -u))"
echo "ref: ${{ gitea.ref }}"
echo "deploy dir: $DEPLOY_DIR"
- name: Stop running instance (if any)
run: |
if [ -x "$DEPLOY_DIR/stop.sh" ]; then
sudo -n "$DEPLOY_DIR/stop.sh" || true
else
echo "no prior install at $DEPLOY_DIR, skipping stop"
fi
- name: Sync code to deploy dir
run: |
sudo -n /usr/bin/rsync -a --delete \
--exclude='.git' \
--exclude='.venv' \
--exclude='.venv-ci' \
--exclude='logs' \
--exclude='.pid' \
./ "$DEPLOY_DIR/"
sudo -n chmod +x "$DEPLOY_DIR/setup.sh" "$DEPLOY_DIR/run.sh" "$DEPLOY_DIR/stop.sh"
- name: Setup venv and dependencies
run: sudo -n "$DEPLOY_DIR/setup.sh"
- name: Start service
run: sudo -n "$DEPLOY_DIR/run.sh"
- name: Verify pid is alive
run: |
sleep 2
PID_FILE="$DEPLOY_DIR/.pid"
if [ ! -f "$PID_FILE" ]; then
echo "no .pid file at $PID_FILE" >&2
sudo -n tail -n 50 "$DEPLOY_DIR/logs/app.log" >&2 || true
exit 1
fi
PID=$(cat "$PID_FILE")
echo "pid=$PID"
if ! kill -0 "$PID" 2>/dev/null; then
kill -0 "$PID" 2>/dev/null
result=$?
echo "exit code = $result" # 0 表示活着非0表示死了
echo "pid $PID not alive" >&2
sudo -n tail -n 50 "$DEPLOY_DIR/logs/app.log" >&2 || true
exit 1
fi
echo "service running, pid=$PID"
- name: HTTP health check
run: |
for i in 1 2 3 4 5 6 7 8 9 10; do
if curl -fsS -o /dev/null "$HEALTH_URL"; then
echo "health check passed on attempt $i"
exit 0
fi
echo "attempt $i failed, retrying..."
sleep 2
done
echo "health check failed: $HEALTH_URL unreachable" >&2
sudo -n tail -n 80 "$DEPLOY_DIR/logs/app.log" >&2 || true
exit 1
- name: Tail startup log
if: always()
run: sudo -n tail -n 30 "$DEPLOY_DIR/logs/app.log" || true