feat(service): implement PID-file based service management (DAW/furt#100)
- Replace unreliable pexp patterns with PID-file approach - Add graceful shutdown with timeout handling in rc.d script - Implement process validation after startup - Add SIGHUP config reload support for Unix services - Ensure PID-file cleanup on service exit - Update systemd service to use PIDFile parameter Platform improvements: - OpenBSD: rc_check/rc_stop functions now PID-file based - Linux: systemd Type=forking with proper PIDFile support - Cross-platform: /var/run/furt.pid standard location Resolves service status detection issues where rcctl check showed (failed) despite running service due to process name variations across platforms.
This commit is contained in:
parent
ddbb232de2
commit
25a709ebbe
3 changed files with 75 additions and 5 deletions
|
|
@ -19,8 +19,10 @@ LUA_COMMAND=""
|
|||
# Config check first
|
||||
if [ "$(uname)" = "OpenBSD" ] || [ "$(uname)" = "FreeBSD" ]; then
|
||||
CONFIG_FILE="/usr/local/etc/furt/furt.conf"
|
||||
PID_FILE="/var/run/furt.pid"
|
||||
else
|
||||
CONFIG_FILE="/etc/furt/furt.conf"
|
||||
PID_FILE="/var/run/furt.pid"
|
||||
fi
|
||||
|
||||
if [ ! -f "$CONFIG_FILE" ] && [ ! -f "$PROJECT_DIR/config/furt.conf" ]; then
|
||||
|
|
@ -87,12 +89,38 @@ 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
|
||||
# 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
|
||||
# Interactive mode - Foreground (no PID-File)
|
||||
echo -e "${GREEN}Interactive mode: Foreground${NC}"
|
||||
exec "$LUA_COMMAND" src/main.lua
|
||||
fi
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue