Skip to content
This repository was archived by the owner on May 12, 2026. It is now read-only.

Commit c9704c2

Browse files
authored
fix/sigterm-signal (#101)
* fix: handle SIGTERM for graceful shutdown and update release workflow to not include deploy step * chore: changeset
1 parent a14a998 commit c9704c2

3 files changed

Lines changed: 12 additions & 58 deletions

File tree

.changeset/free-streets-sing.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"khaxyrewrite": patch
3+
---
4+
5+
Add SIGTERM for graceful shutdown, for Docker. Remove deploy step from GH actions as it might not be 100% safe

.github/workflows/release.yml

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -35,61 +35,4 @@ jobs:
3535
commit: "chore: release versions"
3636
title: "chore: release versions"
3737
env:
38-
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
39-
deploy:
40-
name: Deploy to VPS
41-
runs-on: ubuntu-latest
42-
needs: [release]
43-
if: needs.release.outputs.published == 'true'
44-
steps:
45-
- name: Check if khaxyrewrite was published
46-
id: check
47-
run: |
48-
PACKAGES='${{ needs.release.outputs.publishedPackages }}'
49-
echo "Published packages: $PACKAGES"
50-
51-
if [ -z "$PACKAGES" ] || [ "$PACKAGES" = "false" ]; then
52-
echo "should_deploy=false" >> $GITHUB_OUTPUT
53-
echo "No packages were published"
54-
elif echo "$PACKAGES" | jq -e '.[] | select(.name == "khaxyrewrite")' > /dev/null 2>&1; then
55-
echo "should_deploy=true" >> $GITHUB_OUTPUT
56-
echo "khaxyrewrite was published, will deploy"
57-
else
58-
echo "should_deploy=false" >> $GITHUB_OUTPUT
59-
echo "khaxyrewrite was not in the published packages"
60-
fi
61-
- name: SSH and Deploy
62-
if: steps.check.outputs.should_deploy == 'true'
63-
uses: appleboy/ssh-action@v1.0.3
64-
with:
65-
host: ${{ secrets.VPS_IP }}
66-
username: ${{ secrets.VPS_USER }}
67-
key: ${{ secrets.VPS_SSH_KEY }}
68-
script: |
69-
set -e
70-
cd ~/Khaxy
71-
72-
# 1. Update local tags from GitHub
73-
git fetch --all --tags
74-
75-
# 2. Get the most recent tag created by Changesets
76-
LATEST_TAG=$(git tag -l "khaxyrewrite@*" --sort=-v:refname | head -n1)
77-
78-
if [ -z "$LATEST_TAG" ]; then
79-
echo "❌ No khaxyrewrite tag found!"
80-
exit 1
81-
fi
82-
83-
echo "🚀 Deploying release: $LATEST_TAG"
84-
git checkout --force $LATEST_TAG
85-
86-
# 3. Docker Zero-Downtime Update
87-
echo "🏗️ Building and deploying with Docker..."
88-
docker-compose build
89-
docker-compose up -d
90-
91-
# 4. Cleanup
92-
echo "🧹 Cleaning up old images..."
93-
docker image prune -f
94-
95-
echo "✅ Deployment Complete!"
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

apps/bot/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,9 @@ process.on("uncaughtException", (err) => {
9595
message: "Uncaught Exception",
9696
});
9797
});
98+
// Graceful shutdown
99+
process.on("SIGTERM", () => {
100+
console.log("SIGTERM received. Closing bot...");
101+
void client.destroy(); // Disconnect from Discord immediately
102+
process.exit(0); // Tell Docker we are done
103+
});

0 commit comments

Comments
 (0)