forked from GCWing/BitFun
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·128 lines (111 loc) · 3.13 KB
/
deploy.sh
File metadata and controls
executable file
·128 lines (111 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env bash
# BitFun Relay Server — one-click deploy script.
# Usage: bash deploy.sh [--skip-build] [--skip-health-check]
#
# Run this script on the target server itself after SSH login.
# It deploys to the current machine only; it does not SSH to a remote host.
#
# Prerequisites: Docker, Docker Compose
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SKIP_BUILD=false
SKIP_HEALTH_CHECK=false
usage() {
cat <<'EOF'
BitFun Relay Server deploy script
Usage:
bash deploy.sh [options]
Run location:
Execute this script on the target server itself after SSH login.
This script only deploys to the current machine.
Options:
--skip-build Skip docker compose build, only restart services
--skip-health-check Skip post-deploy health check
-h, --help Show this help message
EOF
}
check_command() {
local cmd="$1"
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "Error: '$cmd' is required but not installed."
exit 1
fi
}
check_docker_compose() {
if docker compose version >/dev/null 2>&1; then
return 0
fi
echo "Error: Docker Compose (docker compose) is required."
exit 1
}
for arg in "$@"; do
case "$arg" in
--skip-build) SKIP_BUILD=true ;;
--skip-health-check) SKIP_HEALTH_CHECK=true ;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown option: $arg"
usage
exit 1
;;
esac
done
echo "=== BitFun Relay Server Deploy ==="
echo "Target: current machine"
echo "Note: run this script on the target server after SSH login."
check_command docker
check_docker_compose
cd "$SCRIPT_DIR"
# Stop old containers if running
echo "[1/3] Stopping old containers (if running)..."
docker compose down 2>/dev/null || true
echo " Done."
# Build
if [ "$SKIP_BUILD" = true ]; then
echo "[2/3] Skipping Docker build (--skip-build)"
else
echo "[2/3] Building Docker images..."
docker compose build
fi
# Start
echo "[3/3] Starting services..."
docker compose up -d
if [ "$SKIP_HEALTH_CHECK" = false ]; then
echo "Waiting for services to start..."
sleep 5
echo "Checking relay health endpoint..."
if command -v curl >/dev/null 2>&1; then
MAX_RETRIES=6
RETRY=0
while [ $RETRY -lt $MAX_RETRIES ]; do
if curl -fsS --max-time 5 "http://127.0.0.1:9700/health" >/dev/null 2>&1; then
echo "Health check passed: http://127.0.0.1:9700/health"
break
fi
RETRY=$((RETRY + 1))
if [ $RETRY -lt $MAX_RETRIES ]; then
echo " Retry $RETRY/$MAX_RETRIES in 3s..."
sleep 3
else
echo "Warning: health check failed after $MAX_RETRIES attempts. Check logs:"
docker compose logs --tail=30 relay-server
fi
done
else
echo "Warning: 'curl' not found, skipped health check."
fi
fi
echo ""
echo "=== Deploy complete ==="
echo "Relay server running on port 9700"
echo "Caddy proxy on ports 80/443"
echo ""
echo "Custom Server URL examples for BitFun Desktop:"
echo " - Direct relay: http://<YOUR_SERVER_IP>:9700"
echo ""
echo "Check status: docker compose ps"
echo "View logs: docker compose logs -f relay-server"
echo "Stop: docker compose down"