-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy
More file actions
executable file
·92 lines (74 loc) · 2.06 KB
/
deploy
File metadata and controls
executable file
·92 lines (74 loc) · 2.06 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
#!/bin/bash
if [ $# -ne 3 ]; then
echo "Usage: $0 <target> <ssh-user> <ssh-server>"
echo "<target>: 'web' or 'service'"
exit 1
fi
TARGET="$1"
USER="$2"
SERVER="$3"
TARGET_WEB_CLIENT="/var/www/sectalk.my.to/html/"
TARGET_SERVER="~/"
# Validate target parameter
if [[ "$TARGET" != "web" && "$TARGET" != "service" ]]; then
echo "✗ Invalid target '$TARGET'. Must be 'web' or 'service'"
exit 1
fi
# Test SSH connection
echo "Testing SSH connection to $USER@$SERVER ..."
if ! ssh -o ConnectTimeout=10 -o BatchMode=yes "$USER@$SERVER" "echo '✓ OK'"; then
echo "✗ Failed to connect to $USER@$SERVER"
exit 1
fi
if [ "$TARGET" == "web" ]; then
# Build Web client
echo "Building Web client ..."
if ! npm run build; then
echo "✗ npm run build failed"
exit 1
fi
echo "✓ OK"
# Deploy Web client
echo "Deploying Web client ..."
if ! scp dist/index.html "$USER@$SERVER:$TARGET_WEB_CLIENT"; then
echo "✗ Failed to deploy dist/index.html"
exit 1
fi
echo "✓ OK"
fi
if [ "$TARGET" == "service" ]; then
# Build service
echo "Building service ..."
if ! cargo build --release; then
echo "✗ cargo build --release failed"
exit 1
fi
echo "✓ OK"
# stop service
echo "Stopping service ..."
if ! ssh "$USER@$SERVER" "systemctl --user stop sectalkd"; then
echo "✗ Failed to stop sectalkd service"
exit 1
fi
echo "✓ OK"
# Deploy service
echo "Deploying service ..."
if ! scp target/release/sectalkd "$USER@$SERVER:$TARGET_SERVER"; then
echo "✗ Failed to deploy target/release/sectalkd"
exit 1
fi
echo "✓ OK"
# Start service
echo "Starting sectalkd service ..."
if ! ssh "$USER@$SERVER" "
systemctl --user daemon-reload &&
systemctl --user start sectalkd &&
systemctl --user is-active --quiet sectalkd
"; then
echo "✗ Failed to start sectalkd service"
exit 1
fi
echo "✓ OK"
fi
echo "Deployment complete: $TARGET"
exit 0