-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·477 lines (403 loc) · 14.4 KB
/
install.sh
File metadata and controls
executable file
·477 lines (403 loc) · 14.4 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
#!/bin/bash
# RustStrom - High-Performance Load Balancer Installer
# Supports: Linux (Ubuntu, Debian, CentOS, Fedora, Arch) and macOS
# Usage: curl -sSL https://raw.githubusercontent.com/ismoilovdevml/RustStrom/main/installer.sh | bash
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
REPO="ismoilovdevml/RustStrom"
INSTALL_DIR="/usr/local/bin"
CONFIG_DIR="/etc/rust-strom"
SERVICE_FILE="/etc/systemd/system/rust-strom.service"
BINARY_NAME="rust-strom"
LOG_DIR="/var/log/rust-strom"
DASHBOARD_DIR="/opt/ruststrom-dashboard"
# Print functions
print_info() {
echo -e "${BLUE}ℹ${NC} $1"
}
print_success() {
echo -e "${GREEN}✓${NC} $1"
}
print_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
print_error() {
echo -e "${RED}✗${NC} $1"
}
print_banner() {
echo -e "${BLUE}"
cat << "EOF"
╔═══════════════════════════════════════════════════════╗
║ ║
║ ██████╗ ██╗ ██╗███████╗████████╗ ║
║ ██╔══██╗██║ ██║██╔════╝╚══██╔══╝ ║
║ ██████╔╝██║ ██║███████╗ ██║ ║
║ ██╔══██╗██║ ██║╚════██║ ██║ ║
║ ██║ ██║╚██████╔╝███████║ ██║ ║
║ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝ ╚═╝ ║
║ ║
║ ███████╗████████╗██████╗ ██████╗ ███╗ ███╗ ║
║ ██╔════╝╚══██╔══╝██╔══██╗██╔═══██╗████╗ ████║ ║
║ ███████╗ ██║ ██████╔╝██║ ██║██╔████╔██║ ║
║ ╚════██║ ██║ ██╔══██╗██║ ██║██║╚██╔╝██║ ║
║ ███████║ ██║ ██║ ██║╚██████╔╝██║ ╚═╝ ██║ ║
║ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ║
║ ║
║ High-Performance Load Balancer ║
║ Proven Performance - Outperforms HAProxy ║
║ ║
╚═══════════════════════════════════════════════════════╝
EOF
echo -e "${NC}"
}
# Detect OS
detect_os() {
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS="linux"
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO=$ID
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS="macos"
DISTRO="macos"
else
print_error "Unsupported operating system: $OSTYPE"
exit 1
fi
print_info "Detected OS: $OS ($DISTRO)"
}
# Detect architecture
detect_arch() {
ARCH=$(uname -m)
case $ARCH in
x86_64)
ARCH="x86_64"
;;
aarch64|arm64)
ARCH="aarch64"
;;
*)
print_error "Unsupported architecture: $ARCH"
exit 1
;;
esac
print_info "Detected architecture: $ARCH"
}
# Check if running as root
check_root() {
if [ "$EUID" -ne 0 ]; then
print_warning "This script requires root privileges. Please run with sudo."
exit 1
fi
}
# Install dependencies
install_dependencies() {
print_info "Installing dependencies..."
case $DISTRO in
ubuntu|debian)
apt-get update -qq
apt-get install -y curl wget ca-certificates git build-essential > /dev/null 2>&1
;;
centos|fedora|rhel)
yum install -y curl wget ca-certificates git gcc gcc-c++ make > /dev/null 2>&1
;;
arch)
pacman -Sy --noconfirm curl wget ca-certificates git base-devel > /dev/null 2>&1
;;
macos)
# macOS typically has these already
if ! command -v brew &> /dev/null; then
print_info "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
brew install curl wget git > /dev/null 2>&1 || true
;;
esac
print_success "Dependencies installed"
}
# Download and install RustStrom
download_ruststrom() {
print_info "Downloading RustStrom..."
# Get latest release
LATEST_RELEASE=$(curl -s https://api.github.com/repos/$REPO/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$LATEST_RELEASE" ]; then
print_warning "Could not fetch latest release. Building from source..."
build_from_source
return
fi
print_info "Latest version: $LATEST_RELEASE"
# Determine binary name format
BINARY_ASSET="rust-strom-$OS-$ARCH"
# Download binary
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$LATEST_RELEASE/$BINARY_ASSET"
print_info "Downloading from: $DOWNLOAD_URL"
if curl -sL --fail "$DOWNLOAD_URL" -o "/tmp/$BINARY_NAME" 2>/dev/null; then
chmod +x "/tmp/$BINARY_NAME"
mv "/tmp/$BINARY_NAME" "$INSTALL_DIR/$BINARY_NAME"
print_success "RustStrom installed to $INSTALL_DIR/$BINARY_NAME"
else
print_warning "Pre-built binary not available. Building from source..."
build_from_source
fi
}
# Build from source
build_from_source() {
print_info "Building RustStrom from source..."
# Check if Rust is installed
if ! command -v cargo &> /dev/null; then
print_info "Installing Rust..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env" 2>/dev/null || true
export PATH="$HOME/.cargo/bin:$PATH"
fi
# Clone and build
TEMP_DIR=$(mktemp -d)
cd "$TEMP_DIR"
print_info "Cloning repository..."
git clone "https://github.com/$REPO.git" > /dev/null 2>&1
cd RustStrom
print_info "Building (this may take a few minutes)..."
cargo build --release > /dev/null 2>&1
# Install binary
cp "target/release/$BINARY_NAME" "$INSTALL_DIR/$BINARY_NAME"
chmod +x "$INSTALL_DIR/$BINARY_NAME"
# Cleanup
cd ~
rm -rf "$TEMP_DIR"
print_success "RustStrom built and installed successfully"
}
# Create configuration directory and files
setup_config() {
print_info "Setting up configuration..."
# Create directories
mkdir -p "$CONFIG_DIR"
mkdir -p "$LOG_DIR"
# Create default config if it doesn't exist
if [ ! -f "$CONFIG_DIR/config.toml" ]; then
cat > "$CONFIG_DIR/config.toml" << 'EOF'
# RustStrom Configuration File
# High-Performance Load Balancer
# HTTP and HTTPS binding addresses
http_address = "[::]:80"
https_address = "[::]:443"
# Health check interval (in seconds)
[health_interval]
check_every = 10
# Backend pool example
[[backend_pools]]
matcher = "Host('example.com')"
addresses = ["127.0.0.1:8080", "127.0.0.1:8081", "127.0.0.1:8082"]
schemes = ["HTTP", "HTTPS"]
# Load balancing strategy
# Options: RoundRobin, Random, IPHash, LeastConnection
strategy = { RoundRobin = {} }
# Health check configuration
[backend_pools.health_config]
slow_threshold = 300 # milliseconds
timeout = 500 # milliseconds
path = "/"
# Middlewares
[backend_pools.middlewares.Compression]
# Enable gzip/brotli compression
[backend_pools.middlewares.RateLimiter]
limit = 100 # requests
window_sec = 1 # per second
# TLS/SSL Certificates
# [certificates."example.com"]
# Local = { certificate_path = "cert.pem", private_key_path = "key.pem" }
# ACME (Let's Encrypt)
# [certificates."example.com"]
# ACME = { staging = false, email = "admin@example.com", persist_dir = "acme" }
EOF
print_success "Default configuration created at $CONFIG_DIR/config.toml"
else
print_warning "Configuration file already exists at $CONFIG_DIR/config.toml"
fi
}
# Create user and group
create_user() {
if [ "$OS" = "linux" ]; then
print_info "Creating rust-strom user and group..."
if ! getent group rust-strom > /dev/null 2>&1; then
groupadd --system rust-strom
fi
if ! id -u rust-strom > /dev/null 2>&1; then
useradd --system --no-create-home --gid rust-strom rust-strom
fi
# Set permissions
chown -R rust-strom:rust-strom "$CONFIG_DIR"
chown -R rust-strom:rust-strom "$LOG_DIR"
print_success "User and group created"
fi
}
# Setup systemd service (Linux only)
setup_systemd() {
if [ "$OS" = "linux" ]; then
print_info "Setting up systemd service..."
cat > "$SERVICE_FILE" << EOF
[Unit]
Description=RustStrom High-Performance Load Balancer
Documentation=https://github.com/$REPO
After=network.target
Wants=network-online.target
[Service]
Type=simple
User=rust-strom
Group=rust-strom
ExecStart=$INSTALL_DIR/$BINARY_NAME --config $CONFIG_DIR/config.toml
Restart=on-failure
RestartSec=5
StandardOutput=journal
StandardError=journal
SyslogIdentifier=rust-strom
# Security settings
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=$LOG_DIR $CONFIG_DIR
# Performance settings
LimitNOFILE=1048576
LimitNPROC=512
[Install]
WantedBy=multi-user.target
EOF
# Reload systemd
systemctl daemon-reload
print_success "Systemd service created"
print_info "To start RustStrom: sudo systemctl start rust-strom"
print_info "To enable on boot: sudo systemctl enable rust-strom"
fi
}
# Setup launchd service (macOS only)
setup_launchd() {
if [ "$OS" = "macos" ]; then
print_info "Setting up launchd service..."
PLIST_FILE="/Library/LaunchDaemons/com.ruststrom.plist"
cat > "$PLIST_FILE" << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.ruststrom</string>
<key>ProgramArguments</key>
<array>
<string>$INSTALL_DIR/$BINARY_NAME</string>
<string>--config</string>
<string>$CONFIG_DIR/config.toml</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>$LOG_DIR/rust-strom.log</string>
<key>StandardErrorPath</key>
<string>$LOG_DIR/rust-strom-error.log</string>
</dict>
</plist>
EOF
chmod 644 "$PLIST_FILE"
print_success "Launchd service created"
print_info "To start RustStrom: sudo launchctl load $PLIST_FILE"
fi
}
# Install Dashboard
install_dashboard() {
print_info "Installing Dashboard..."
# Check if Node.js is installed
if ! command -v node &> /dev/null; then
print_info "Installing Node.js..."
case $DISTRO in
ubuntu|debian)
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get install -y nodejs
;;
centos|fedora|rhel)
curl -fsSL https://rpm.nodesource.com/setup_20.x | bash -
yum install -y nodejs
;;
arch)
pacman -S --noconfirm nodejs npm
;;
macos)
brew install node
;;
esac
fi
# Clone dashboard
if [ ! -d "$DASHBOARD_DIR" ]; then
TEMP_DIR=$(mktemp -d)
cd "$TEMP_DIR"
git clone "https://github.com/$REPO.git" > /dev/null 2>&1
mv RustStrom/ruststrom-dashboard "$DASHBOARD_DIR"
rm -rf "$TEMP_DIR"
# Install dependencies
cd "$DASHBOARD_DIR"
npm install > /dev/null 2>&1
print_success "Dashboard installed to $DASHBOARD_DIR"
else
print_warning "Dashboard already installed at $DASHBOARD_DIR"
fi
}
# Print installation summary
print_summary() {
echo ""
echo -e "${GREEN}═══════════════════════════════════════════════════════${NC}"
print_success "RustStrom installed successfully!"
echo -e "${GREEN}═══════════════════════════════════════════════════════${NC}"
echo ""
print_info "Installation details:"
echo " • Binary: $INSTALL_DIR/$BINARY_NAME"
echo " • Config: $CONFIG_DIR/config.toml"
echo " • Logs: $LOG_DIR"
echo " • Dashboard: $DASHBOARD_DIR"
echo ""
print_info "Next steps:"
echo " 1. Edit configuration: sudo nano $CONFIG_DIR/config.toml"
if [ "$OS" = "linux" ]; then
echo " 2. Start service: sudo systemctl start rust-strom"
echo " 3. Enable on boot: sudo systemctl enable rust-strom"
echo " 4. Check status: sudo systemctl status rust-strom"
echo " 5. View logs: sudo journalctl -u rust-strom -f"
echo " 6. Start dashboard: cd $DASHBOARD_DIR && npm run dev"
elif [ "$OS" = "macos" ]; then
echo " 2. Start service: sudo launchctl load /Library/LaunchDaemons/com.ruststrom.plist"
echo " 3. Stop service: sudo launchctl unload /Library/LaunchDaemons/com.ruststrom.plist"
echo " 4. View logs: tail -f $LOG_DIR/rust-strom.log"
echo " 5. Start dashboard: cd $DASHBOARD_DIR && npm run dev"
fi
echo ""
print_info "Dashboard URL: http://localhost:3000"
print_info "Metrics URL: http://localhost:9090/metrics"
print_info "Documentation: https://github.com/$REPO"
echo ""
}
# Main installation flow
main() {
print_banner
check_root
detect_os
detect_arch
install_dependencies
download_ruststrom
setup_config
create_user
if [ "$OS" = "linux" ]; then
setup_systemd
elif [ "$OS" = "macos" ]; then
setup_launchd
fi
install_dashboard
print_summary
}
# Run main
main