furt/scripts/start.sh
michael 8b7806670c docs: simplify README and remove FreeBSD support
- Strip README to essentials with wiki references only
- Remove non-existent API docs and troubleshooting links
- Focus on quick start and actual integrations (merkwerk)
- Remove FreeBSD support from all installation scripts
- Clean up platform detection logic in scripts
- Maintain OpenBSD and Linux support only

Reduces maintenance burden and aligns with actual project scope.
2025-09-10 12:20:41 +02:00

126 lines
3.2 KiB
Bash
Executable file

#!/bin/sh
# scripts/start.sh
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
echo -e "${GREEN}=== Furt Lua HTTP-Server Startup ===${NC}"
# User can override this manually if needed:
LUA_COMMAND=""
# Config check first
if [ "$(uname)" = "OpenBSD" ]; then
CONFIG_FILE="/usr/local/etc/furt/furt.conf"
PID_FILE="/var/run/furt/furt.pid"
else
CONFIG_FILE="/etc/furt/furt.conf"
PID_FILE="/var/run/furt/furt.pid"
fi
if [ ! -f "$CONFIG_FILE" ] && [ ! -f "$PROJECT_DIR/config/furt.conf" ]; then
echo -e "${RED}Error: furt.conf not found${NC}"
echo "Create config first in $CONFIG_FILE or $PROJECT_DIR/config/furt.conf"
exit 1
fi
if [ -z "$LUA_COMMAND" ]; then
# Test standard distribution paths
for cmd in lua51 lua5.1; do
if command -v "$cmd" >/dev/null 2>&1; then
LUA_COMMAND="$cmd"
break
fi
done
fi
if [ -z "$LUA_COMMAND" ]; then
echo -e "${RED}Error: No Lua 5.1 found${NC}"
echo "Install options:"
echo " Arch: pacman -S lua51"
echo " OpenBSD: pkg_add lua51"
echo " Debian: apt install lua5.1"
echo ""
echo "Or set: LUA_COMMAND=/custom/path/lua51 at top of this script"
exit 1
fi
echo -e "${GREEN}Found Lua:${NC} $LUA_COMMAND"
# Dependency checks
# Socket check
$LUA_COMMAND -e "require('socket')" 2>/dev/null || {
echo -e "${RED}Error: lua-socket not found${NC}"
echo "Install options:"
echo " Arch: pacman -S lua51-socket"
echo " OpenBSD: pkg_add lua-socket"
echo " Debian: apt install lua-socket"
exit 1
}
# JSON library check
if ! ($LUA_COMMAND -e "require('cjson')" 2>/dev/null || $LUA_COMMAND -e "require('dkjson')" 2>/dev/null); then
echo -e "${RED}Error: No JSON library found${NC}"
echo "Install options:"
echo " Arch: pacman -S lua51-dkjson"
echo " OpenBSD: pkg_add lua-cjson"
echo " Debian: apt install lua-cjson"
exit 1
fi
# SSL/TLS library check
$LUA_COMMAND -e "require('ssl')" 2>/dev/null || {
echo -e "${RED}Error: SSL/TLS library not found${NC}"
echo "Install options:"
echo " Arch: pacman -S lua51-sec"
echo " OpenBSD: pkg_add luasec"
echo " Debian: apt install lua-sec"
exit 1
}
cd "$PROJECT_DIR"
echo -e "${GREEN}Starting Furt...${NC}"
# PID-File cleanup function
cleanup_pid() {
if [ -f "$PID_FILE" ]; then
rm -f "$PID_FILE"
fi
}
# Service vs Interactive Detection
if [ ! -t 0 ] || [ ! -t 1 ]; then
# Service mode - Background + PID-File
echo -e "${GREEN}Service mode: Background + PID-File${NC}"
# Start process in background
"$LUA_COMMAND" src/main.lua &
PID=$!
# Write PID-File
echo "$PID" > "$PID_FILE"
echo -e "${GREEN}Furt started (PID: $PID, PID-File: $PID_FILE)${NC}"
# Verify process is still running after short delay
sleep 1
if ! kill -0 "$PID" 2>/dev/null; then
echo -e "${RED}Error: Process died immediately${NC}"
cleanup_pid
exit 1
fi
echo -e "${GREEN}Service startup successful${NC}"
else
# Interactive mode - Foreground (no PID-File)
echo -e "${GREEN}Interactive mode: Foreground${NC}"
exec "$LUA_COMMAND" src/main.lua
fi