Service Management Scripts: - start_services.sh: Start Web, SSH, SMB servers - stop_services.sh: Stop all servers gracefully Features: - Port conflict detection - Graceful shutdown (SIGTERM + SIGKILL) - Log file management - Color-coded output Ports: - Web: 11438 - SSH: 2024 - SMB: 4445 Usage: ./scripts/start_services.sh ./scripts/stop_services.sh
127 lines
3.3 KiB
Bash
Executable File
127 lines
3.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# MarkBase Services Startup Script
|
|
# Starts all services: Web, SSH, SMB, WebDAV
|
|
|
|
set -e
|
|
|
|
PORT_WEB=11438
|
|
PORT_SSH=2024
|
|
PORT_SMB=4445
|
|
PORT_WEBDAV=11438
|
|
|
|
ROOT_DIR="/Users/accusys/momentry/var/sftpgo/data"
|
|
AUTH_DB="data/auth.sqlite"
|
|
LOG_DIR="/tmp/markbase_logs"
|
|
|
|
# Colors
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m'
|
|
|
|
mkdir -p "$LOG_DIR"
|
|
|
|
echo "================================================"
|
|
echo "MarkBase Services Startup"
|
|
echo "================================================"
|
|
echo ""
|
|
|
|
# Function to check if port is in use
|
|
check_port() {
|
|
local port=$1
|
|
if nc -z 127.0.0.1 $port 2>/dev/null; then
|
|
return 0 # Port is in use
|
|
else
|
|
return 1 # Port is free
|
|
fi
|
|
}
|
|
|
|
# Function to kill process on port
|
|
kill_port() {
|
|
local port=$1
|
|
local pid=$(lsof -t -i:$port 2>/dev/null)
|
|
if [ -n "$pid" ]; then
|
|
echo "${YELLOW}Killing process $pid on port $port${NC}"
|
|
kill $pid 2>/dev/null || true
|
|
sleep 2
|
|
fi
|
|
}
|
|
|
|
# Stop existing services
|
|
echo "=== Stopping existing services ==="
|
|
for port in $PORT_WEB $PORT_SSH $PORT_SMB; do
|
|
if check_port $port; then
|
|
kill_port $port
|
|
fi
|
|
done
|
|
echo "${GREEN}Existing services stopped${NC}"
|
|
echo ""
|
|
|
|
# Start Web Server (Port 11438)
|
|
echo "=== Starting Web Server (Port $PORT_WEB) ==="
|
|
if check_port $PORT_WEB; then
|
|
echo "${YELLOW}Port $PORT_WEB already in use${NC}"
|
|
else
|
|
cargo run --bin markbase-core -- web-start --port $PORT_WEB --root "$ROOT_DIR" > "$LOG_DIR/web.log" 2>&1 &
|
|
sleep 2
|
|
if check_port $PORT_WEB; then
|
|
echo "${GREEN}Web Server started${NC}"
|
|
echo " Log: $LOG_DIR/web.log"
|
|
else
|
|
echo "${RED}Web Server failed to start${NC}"
|
|
fi
|
|
fi
|
|
echo ""
|
|
|
|
# Start SSH Server (Port 2024)
|
|
echo "=== Starting SSH Server (Port $PORT_SSH) ==="
|
|
if check_port $PORT_SSH; then
|
|
echo "${YELLOW}Port $PORT_SSH already in use${NC}"
|
|
else
|
|
cargo run --bin markbase-core -- ssh-server-start --port $PORT_SSH --root "$ROOT_DIR" --auth-db "$AUTH_DB" > "$LOG_DIR/ssh.log" 2>&1 &
|
|
sleep 2
|
|
if check_port $PORT_SSH; then
|
|
echo "${GREEN}SSH Server started${NC}"
|
|
echo " Log: $LOG_DIR/ssh.log"
|
|
else
|
|
echo "${RED}SSH Server failed to start${NC}"
|
|
fi
|
|
fi
|
|
echo ""
|
|
|
|
# Start SMB Server (Port 4445)
|
|
echo "=== Starting SMB Server (Port $PORT_SMB) ==="
|
|
if check_port $PORT_SMB; then
|
|
echo "${YELLOW}Port $PORT_SMB already in use${NC}"
|
|
else
|
|
cargo run --bin markbase-core --features smb-server -- smb-start --port $PORT_SMB --share-name markbase --root "$ROOT_DIR" --user demo:demo123 > "$LOG_DIR/smb.log" 2>&1 &
|
|
sleep 3
|
|
if check_port $PORT_SMB; then
|
|
echo "${GREEN}SMB Server started${NC}"
|
|
echo " Log: $LOG_DIR/smb.log"
|
|
else
|
|
echo "${RED}SMB Server failed to start${NC}"
|
|
fi
|
|
fi
|
|
echo ""
|
|
|
|
# Summary
|
|
echo "================================================"
|
|
echo "MarkBase Services Summary"
|
|
echo "================================================"
|
|
echo ""
|
|
echo "Services:"
|
|
echo " Web Server: http://127.0.0.1:$PORT_WEB"
|
|
echo " SSH Server: ssh://127.0.0.1:$PORT_SSH"
|
|
echo " SMB Server: smb://127.0.0.1:$PORT_SMB"
|
|
echo " WebDAV: http://127.0.0.1:$PORT_WEBDAV/webdav/"
|
|
echo ""
|
|
echo "Logs: $LOG_DIR/"
|
|
echo " web.log"
|
|
echo " ssh.log"
|
|
echo " smb.log"
|
|
echo ""
|
|
echo "Users:"
|
|
echo " demo:demo123"
|
|
echo ""
|
|
echo "${GREEN}All services started${NC}" |