70 lines
1.9 KiB
Bash
Executable File
70 lines
1.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# C-Relay Static Binary Deployment Script
|
|
# Deploys build/c_relay_static_x86_64 to server via sshlt
|
|
# Usage: ./deploy_static.sh [--debug-level=N] [-d=N]
|
|
|
|
set -e
|
|
|
|
# Configuration
|
|
LOCAL_BINARY="build/c_relay_static_x86_64"
|
|
REMOTE_BINARY_PATH="/usr/local/bin/c_relay/c_relay"
|
|
SERVICE_NAME="c-relay"
|
|
|
|
# Default debug level
|
|
DEBUG_LEVEL=0
|
|
|
|
# Parse command line arguments
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
--debug-level=*)
|
|
DEBUG_LEVEL="${1#*=}"
|
|
shift
|
|
;;
|
|
-d=*)
|
|
DEBUG_LEVEL="${1#*=}"
|
|
shift
|
|
;;
|
|
--debug-level)
|
|
DEBUG_LEVEL="$2"
|
|
shift 2
|
|
;;
|
|
-d)
|
|
DEBUG_LEVEL="$2"
|
|
shift 2
|
|
;;
|
|
*)
|
|
echo "Unknown option: $1"
|
|
echo "Usage: $0 [--debug-level=N] [-d=N]"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Validate debug level
|
|
if ! [[ "$DEBUG_LEVEL" =~ ^[0-5]$ ]]; then
|
|
echo "Error: Debug level must be 0-5, got: $DEBUG_LEVEL"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Deploying with debug level: $DEBUG_LEVEL"
|
|
|
|
# Create backup
|
|
ssh ubuntu@laantungir.com "sudo cp '$REMOTE_BINARY_PATH' '${REMOTE_BINARY_PATH}.backup.$(date +%Y%m%d_%H%M%S)'" 2>/dev/null || true
|
|
|
|
# Upload binary to temp location
|
|
scp "$LOCAL_BINARY" "ubuntu@laantungir.com:/tmp/c_relay.tmp"
|
|
|
|
# Install binary
|
|
ssh ubuntu@laantungir.com "sudo mv '/tmp/c_relay.tmp' '$REMOTE_BINARY_PATH'"
|
|
ssh ubuntu@laantungir.com "sudo chown c-relay:c-relay '$REMOTE_BINARY_PATH'"
|
|
ssh ubuntu@laantungir.com "sudo chmod +x '$REMOTE_BINARY_PATH'"
|
|
|
|
# Update systemd service environment variable
|
|
ssh ubuntu@laantungir.com "sudo sed -i 's/Environment=DEBUG_LEVEL=.*/Environment=DEBUG_LEVEL=$DEBUG_LEVEL/' /etc/systemd/system/c-relay.service"
|
|
|
|
# Reload systemd and restart service
|
|
ssh ubuntu@laantungir.com "sudo systemctl daemon-reload"
|
|
ssh ubuntu@laantungir.com "sudo systemctl restart '$SERVICE_NAME'"
|
|
|
|
echo "Deployment complete!" |