zioinfo-mail/scripts/setup/fix_webhook_server.py
DESKTOP-TKLFCPR\ython 5561d0d050 feat(cicd): fix webhook server, git URLs, push Jenkinsfiles to all 5 Gitea repos
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-01 19:55:19 +09:00

44 lines
1.9 KiB
Python

"""webhook 서버 포트 충돌 해결 + Jenkinsfile Gitea push"""
import paramiko, sys, subprocess, os
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('101.79.17.164', username='root', password='1q2w3e!Q', timeout=15)
def run(label, cmd, timeout=30):
print(f'\n[{label}]')
_, o, e = client.exec_command(cmd, timeout=timeout)
out = o.read().decode('utf-8', 'replace').strip()
print(out[:600] if out else '(empty)')
return out
# 1. 포트 9999 점유 프로세스 강제 종료
run('포트 9999 프로세스 확인', 'ss -tlnp | grep 9999')
run('포트 9999 kill', 'fuser -k 9999/tcp 2>/dev/null; sleep 1; ss -tlnp | grep 9999 || echo "포트 해제됨"')
# 2. systemd 서비스 재시작
run('서비스 재시작', 'systemctl restart zioinfo-deploy && sleep 3 && systemctl is-active zioinfo-deploy')
run('서비스 상태', 'systemctl status zioinfo-deploy --no-pager | head -10')
# 3. webhook 동작 확인
run('webhook 트리거 테스트', """
curl -sf -X POST http://localhost:9999 \
-H 'Content-Type: application/json' \
-H 'X-Gitea-Event: push' \
-d '{"repository":{"name":"guardia-itsm"}}' 2>/dev/null || echo "연결 실패"
""")
# 4. Gitea webhook 등록 상태 확인 (zioinfo-web 포함 5개)
REPOS = ["zioinfo-web", "guardia-itsm", "guardia-manager", "guardia-messenger", "guardia-docs"]
for repo in REPOS:
run(f'webhook {repo}', f"""
R=$(curl -sf 'http://127.0.0.1:9003/api/v1/repos/zio/{repo}/hooks' \
-u 'zio:Zio@Admin2026!' 2>/dev/null | \
python3 -c "import sys,json; d=json.load(sys.stdin); [print(h.get('id'), h.get('config',{{}}).get('url',''), 'active:', h.get('active')) for h in d]" 2>/dev/null)
[ -z "$R" ] && echo "webhook 없음" || echo "$R"
""")
client.close()
print('\n=== webhook 서버 수정 완료 ===')