- Fix OpenBSD service file pexp pattern to match actual running process - Set pexp after sourcing rc.subr to prevent automatic override - Update deployment script process detection from broken furt-lua pattern - Add TTY-based daemon detection in start.sh for service vs development mode - Implement comprehensive deployment workflow with backup and health checks - Enable proper rcctl start/stop/check functionality on OpenBSD Root cause: OpenBSD rc.subr automatically generates pexp from daemon+flags, but actual process (/usr/local/bin/lua src/main.lua) differs from wrapper (start.sh). Solution: Override pexp after rc.subr with correct Lua pattern. Deployment script also had incorrect process detection pattern looking for 'furt-lua' string that doesn't exist in process name. Technical details: - Service file: pexp="/usr/local/bin/lua src/main.lua.*" after rc.subr - Process detection: pgrep -u _furt -f 'src/main.lua' - TTY detection: [ ! -t 0 ] for daemon vs interactive mode - Complete deployment workflow with stop/sync/start/health-check cycle Fixes #77 - OpenBSD rc.d service file problem resolved Related: Deployment automation now fully functional karl→walter
116 lines
4 KiB
Bash
Executable file
116 lines
4 KiB
Bash
Executable file
#!/bin/sh
|
|
# furt-lua/scripts/start.sh
|
|
# Start script for Furt Lua HTTP-Server
|
|
|
|
set -e
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Script directory (POSIX-compatible)
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
PROJECT_DIR="$(dirname "$SCRIPT_DIR")" # für src/, cd
|
|
REPO_ROOT="$(dirname "$(dirname "$SCRIPT_DIR")")" # für .env
|
|
|
|
echo -e "${GREEN}=== Furt Lua HTTP-Server Startup ===${NC}"
|
|
|
|
# Check required dependencies
|
|
echo -e "${YELLOW}Checking dependencies...${NC}"
|
|
|
|
# Load environment variables - Universal Config Detection
|
|
echo -e "${YELLOW}Loading environment variables...${NC}"
|
|
if [ -f "$REPO_ROOT/.env" ]; then
|
|
echo -e "${GREEN}[OK]${NC} Loading from $REPO_ROOT/.env"
|
|
export $(grep -v '^#' "$REPO_ROOT/.env" | grep -v '^$' | xargs)
|
|
elif [ -f "/usr/local/etc/furt/environment" ]; then
|
|
echo -e "${GREEN}[OK]${NC} Loading from /usr/local/etc/furt/environment"
|
|
export $(grep -v '^#' /usr/local/etc/furt/environment | grep -v '^$' | xargs)
|
|
elif [ -f "/etc/furt/environment" ]; then
|
|
echo -e "${GREEN}[OK]${NC} Loading from /etc/furt/environment"
|
|
export $(grep -v '^#' /etc/furt/environment | grep -v '^$' | xargs)
|
|
else
|
|
echo -e "${YELLOW}[WARN]${NC} No config file found in project root or system"
|
|
fi
|
|
|
|
# Setup Lua from config (after loading environment)
|
|
LUA_CMD="${LUA_COMMAND:-lua51}"
|
|
LUA_VER="${LUA_VERSION:-5.1}"
|
|
|
|
# Check if configured Lua is installed (POSIX-compatible)
|
|
if ! [ -x "$LUA_CMD" ]; then
|
|
echo -e "${RED}Error: $LUA_CMD is not installed${NC}"
|
|
echo "Install with: pkg_add lua51 (OpenBSD) or apt install lua5.1 (Ubuntu)"
|
|
exit 1
|
|
fi
|
|
|
|
# Check Lua version
|
|
LUA_VERSION_OUTPUT=$($LUA_CMD -v 2>&1 | head -n1)
|
|
echo -e "${YELLOW}Lua command:${NC} $LUA_CMD ($LUA_VERSION_OUTPUT)"
|
|
|
|
# Test lua-socket
|
|
$LUA_CMD -e "require('socket')" 2>/dev/null || {
|
|
echo -e "${RED}Error: lua-socket not found for $LUA_CMD${NC}"
|
|
echo "Install with: pkg_add lua51-socket (OpenBSD) or apt install lua-socket (Ubuntu)"
|
|
exit 1
|
|
}
|
|
echo -e "${GREEN}✓${NC} lua-socket found"
|
|
|
|
# Test lua-cjson (system or luarocks)
|
|
LUA_PATH="$HOME/.luarocks/share/lua/$LUA_VER/?.lua;;" \
|
|
LUA_CPATH="$HOME/.luarocks/lib/lua/$LUA_VER/?.so;;" \
|
|
$LUA_CMD -e "require('cjson')" 2>/dev/null || {
|
|
echo -e "${RED}Error: lua-cjson not found for $LUA_CMD${NC}"
|
|
echo "Install with: pkg_add lua51-cjson (OpenBSD) or luarocks install lua-cjson"
|
|
exit 1
|
|
}
|
|
echo -e "${GREEN}✓${NC} lua-cjson found"
|
|
|
|
# Test lua-ssl (optional for HTTPS)
|
|
LUA_PATH="$HOME/.luarocks/share/lua/$LUA_VER/?.lua;;" \
|
|
LUA_CPATH="$HOME/.luarocks/lib/lua/$LUA_VER/?.so;;" \
|
|
$LUA_CMD -e "require('ssl')" 2>/dev/null && {
|
|
echo -e "${GREEN}✓${NC} lua-ssl found (HTTPS ready)"
|
|
} || {
|
|
echo -e "${YELLOW}○${NC} lua-ssl not found (install with: luarocks install luaossl)"
|
|
}
|
|
|
|
# Check SMTP configuration (korrekte Variable-Namen)
|
|
if [ -n "$SMTP_USERNAME" ] && [ -n "$SMTP_PASSWORD" ]; then
|
|
echo -e "${GREEN}[OK]${NC} SMTP configured: $SMTP_USERNAME"
|
|
else
|
|
echo -e "${YELLOW}[WARN]${NC} SMTP credentials missing in .env"
|
|
echo "Add SMTP_USERNAME and SMTP_PASSWORD to .env"
|
|
fi
|
|
|
|
# Change to project directory
|
|
cd "$PROJECT_DIR"
|
|
|
|
# Add current directory and luarocks to Lua path for requires (dynamic version)
|
|
export LUA_PATH="$PROJECT_DIR/src/?.lua;$PROJECT_DIR/?.lua;$HOME/.luarocks/share/lua/$LUA_VER/?.lua;;"
|
|
export LUA_CPATH="$HOME/.luarocks/lib/lua/$LUA_VER/?.so;;"
|
|
|
|
echo -e "${GREEN}Starting Furt HTTP-Server...${NC}"
|
|
echo -e "${YELLOW}Project directory:${NC} $PROJECT_DIR"
|
|
echo -e "${YELLOW}Lua paths configured for $LUA_CMD (version $LUA_VER)${NC}"
|
|
echo ""
|
|
|
|
# Auto-detect service context
|
|
if [ ! -t 0 ] || [ ! -t 1 ]; then
|
|
# No TTY = Service mode (rcctl)
|
|
echo "Starting Furt in daemon mode..."
|
|
$LUA_CMD src/main.lua &
|
|
echo "Furt started (PID: $!)"
|
|
else
|
|
# Interactive mode (manual/development)
|
|
# echo "Furt HTTP-Server started on 127.0.0.1:8080"
|
|
# echo "Press Ctrl+C to stop"
|
|
$LUA_CMD src/main.lua
|
|
fi
|
|
|
|
|
|
# Start server
|
|
# $LUA_CMD src/main.lua
|
|
|