add sudo
This commit is contained in:
54
start.sh
54
start.sh
@@ -19,19 +19,39 @@ usage() {
|
||||
printf ' FGAI_LISTENER_LOG=%s\n' "$LISTENER_LOG"
|
||||
}
|
||||
|
||||
activate_venv_for_script() {
|
||||
# Activation here affects this script process. It cannot modify the parent shell prompt.
|
||||
# Use "source .venv/bin/activate" manually if you want your interactive prompt to show it.
|
||||
# shellcheck disable=SC1091
|
||||
source "$VENV_DIR/bin/activate"
|
||||
}
|
||||
|
||||
install_deps() {
|
||||
if [ ! -x "$VENV_DIR/bin/python" ]; then
|
||||
printf 'Creating venv: %s\n' "$VENV_DIR"
|
||||
python3 -m venv "$VENV_DIR"
|
||||
fi
|
||||
|
||||
activate_venv_for_script
|
||||
printf 'Installing/updating fgAI dependencies...\n'
|
||||
"$VENV_DIR/bin/python" -m pip install --upgrade pip
|
||||
"$VENV_DIR/bin/python" -m pip install -e "$ROOT_DIR"
|
||||
python -m pip install --upgrade pip
|
||||
python -m pip install -e "$ROOT_DIR"
|
||||
}
|
||||
|
||||
is_running() {
|
||||
[ -f "$PID_FILE" ] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null
|
||||
[ -f "$PID_FILE" ] && ps -p "$(cat "$PID_FILE")" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
needs_privileged_port() {
|
||||
[ "$PORT" -lt 1024 ] && [ "${EUID:-$(id -u)}" -ne 0 ]
|
||||
}
|
||||
|
||||
listener_command() {
|
||||
"$VENV_DIR/bin/fgai" listen-syslog \
|
||||
--host "$HOST" \
|
||||
--port "$PORT" \
|
||||
--output "$LOG_FILE" \
|
||||
--quiet
|
||||
}
|
||||
|
||||
start_listener() {
|
||||
@@ -44,11 +64,20 @@ start_listener() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
nohup "$VENV_DIR/bin/fgai" listen-syslog \
|
||||
--host "$HOST" \
|
||||
--port "$PORT" \
|
||||
--output "$LOG_FILE" \
|
||||
--quiet > "$LISTENER_LOG" 2>&1 &
|
||||
if needs_privileged_port; then
|
||||
printf 'Port %s needs elevated privileges; starting listener with sudo.\n' "$PORT"
|
||||
sudo nohup "$VENV_DIR/bin/fgai" listen-syslog \
|
||||
--host "$HOST" \
|
||||
--port "$PORT" \
|
||||
--output "$LOG_FILE" \
|
||||
--quiet > "$LISTENER_LOG" 2>&1 &
|
||||
else
|
||||
nohup "$VENV_DIR/bin/fgai" listen-syslog \
|
||||
--host "$HOST" \
|
||||
--port "$PORT" \
|
||||
--output "$LOG_FILE" \
|
||||
--quiet > "$LISTENER_LOG" 2>&1 &
|
||||
fi
|
||||
printf '%s\n' "$!" > "$PID_FILE"
|
||||
|
||||
printf 'Started fgAI syslog listener, pid %s\n' "$(cat "$PID_FILE")"
|
||||
@@ -64,7 +93,9 @@ stop_listener() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
kill "$(cat "$PID_FILE")"
|
||||
if ! kill "$(cat "$PID_FILE")" 2>/dev/null; then
|
||||
sudo kill "$(cat "$PID_FILE")"
|
||||
fi
|
||||
rm -f "$PID_FILE"
|
||||
printf 'Stopped fgAI syslog listener\n'
|
||||
}
|
||||
@@ -74,6 +105,9 @@ status_listener() {
|
||||
printf 'fgAI syslog listener running, pid %s\n' "$(cat "$PID_FILE")"
|
||||
printf 'Input: udp://%s:%s\n' "$HOST" "$PORT"
|
||||
printf 'Syslog file: %s\n' "$LOG_FILE"
|
||||
if command -v ss >/dev/null 2>&1; then
|
||||
ss -lunp 2>/dev/null | awk -v port=":$PORT" '$0 ~ port {print}'
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
@@ -103,7 +137,7 @@ case "$command" in
|
||||
;;
|
||||
analyze)
|
||||
install_deps
|
||||
"$VENV_DIR/bin/fgai" analyze-logs --logs "$LOG_FILE"
|
||||
fgai analyze-logs --logs "$LOG_FILE"
|
||||
;;
|
||||
install)
|
||||
install_deps
|
||||
|
||||
Reference in New Issue
Block a user