-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrato-node-linux.sh
More file actions
123 lines (105 loc) · 3.49 KB
/
strato-node-linux.sh
File metadata and controls
123 lines (105 loc) · 3.49 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
#!/bin/bash
# Strato Node Setup Script - One-command node installation
# Usage: curl -sSL https://raw.githubusercontent.com/AI-Decenter/Agent-Node/main/strato-node-linux.sh | bash -s -- [client_id] [client_password]
set -e
# Default configuration
DEFAULT_DOWNLOAD_URL="https://github.com/AI-Decenter/Agent-Node/releases/latest/download/agent-node-linux-x86_64"
# Parse arguments or use environment variables with defaults
CLIENT_ID="${1:-${CLIENT_ID}}"
CLIENT_PASSWORD="${2:-${CLIENT_PASSWORD}}"
DOWNLOAD_URL="${3:-${DOWNLOAD_URL:-$DEFAULT_DOWNLOAD_URL}}"
# Enhanced logging
log() {
echo -e "\033[32m[$(date '+%H:%M:%S')] $1\033[0m"
}
error() {
echo -e "\033[31m[ERROR] $1\033[0m" >&2
exit 1
}
# Validate required parameters
[[ -n "$CLIENT_ID" ]] || error "Client ID is required. Usage: bash script.sh [client_id] [client_password]"
[[ -n "$CLIENT_PASSWORD" ]] || error "Client password is required. Usage: bash script.sh [client_id] [client_password]"
PUBLIC_IP=$(curl -4 -s --max-time 5 icanhazip.com 2>/dev/null || echo "")
# Create client ID with IP if available, otherwise use original CLIENT_ID
if [[ -n "$PUBLIC_IP" ]]; then
CLIENT_WITH_IP="${CLIENT_ID}_${PUBLIC_IP}"
else
CLIENT_WITH_IP="$CLIENT_ID"
fi
log "Installing Strato Node (ID: $CLIENT_WITH_IP)"
# Create setup directory
SETUP_DIR="/opt/strato-node"
log "Creating setup directory: $SETUP_DIR"
sudo mkdir -p "$SETUP_DIR"
# Download node binary
log "Downloading strato-agent from: $DOWNLOAD_URL"
cd "$SETUP_DIR" || exit
if ! sudo curl -fsSL -o strato-agent "$DOWNLOAD_URL"; then
error "Failed to download strato-agent from: $DOWNLOAD_URL"
fi
sudo chmod +x strato-agent
# Create config file
log "Creating configuration file"
sudo tee config.toml > /dev/null <<EOF
host = "127.0.0.1"
port = 8379
storage_path = "strato_data"
engine = "rwlock"
sync_interval_seconds = 30
[replication]
enabled = true
mqtt_broker = "emqx.decenter.ai"
mqtt_port = 1883
topic_prefix = "strato_kv"
client_id = "$CLIENT_WITH_IP"
client_password = "$CLIENT_PASSWORD"
EOF
# Create systemd service
log "Creating systemd service"
sudo tee /etc/systemd/system/strato-node.service > /dev/null <<EOF
[Unit]
Description=Strato Node Service
After=network.target
Wants=network-online.target
[Service]
Type=simple
User=root
WorkingDirectory=$SETUP_DIR
ExecStart=$SETUP_DIR/strato-agent --config config.toml
ExecReload=/bin/kill -HUP \$MAINPID
Restart=always
RestartSec=5
StandardOutput=journal
StandardError=journal
SyslogIdentifier=strato-node
[Install]
WantedBy=multi-user.target
EOF
# Enable and start service
log "Enabling and starting Strato Node service"
sudo systemctl daemon-reload
sudo systemctl enable strato-node.service
sudo systemctl start strato-node.service
# Wait and check service status
sleep 2
if systemctl is-active --quiet strato-node.service; then
log "Strato Node service started successfully"
SERVICE_STATUS="running"
else
log "Warning: Service may have failed to start. Check: journalctl -u strato-node -f"
SERVICE_STATUS="failed"
fi
# Display installation summary
log "Installation completed!"
echo
echo "Strato Node Details:"
echo " Client ID: $CLIENT_ID"
echo " Setup Directory: $SETUP_DIR"
echo " Service Status: $SERVICE_STATUS"
echo
echo "Service Management Commands:"
echo " Check status: sudo systemctl status strato-node"
echo " View logs: sudo journalctl -u strato-node -f"
echo " Stop service: sudo systemctl stop strato-node"
echo " Start service: sudo systemctl start strato-node"
echo " Restart service: sudo systemctl restart strato-node"