add sudo
This commit is contained in:
12
README.md
12
README.md
@@ -21,6 +21,18 @@ Or use the helper script, which creates/uses `.venv` automatically and runs `pip
|
|||||||
./start.sh stop
|
./start.sh stop
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The script activates `.venv` inside the script process. If you also want your current shell prompt to show the venv, run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
source .venv/bin/activate
|
||||||
|
```
|
||||||
|
|
||||||
|
For UDP `514`, the script starts only the listener command with `sudo`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
FGAI_SYSLOG_PORT=514 ./start.sh
|
||||||
|
```
|
||||||
|
|
||||||
Analyze local logs:
|
Analyze local logs:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
54
start.sh
54
start.sh
@@ -19,19 +19,39 @@ usage() {
|
|||||||
printf ' FGAI_LISTENER_LOG=%s\n' "$LISTENER_LOG"
|
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() {
|
install_deps() {
|
||||||
if [ ! -x "$VENV_DIR/bin/python" ]; then
|
if [ ! -x "$VENV_DIR/bin/python" ]; then
|
||||||
printf 'Creating venv: %s\n' "$VENV_DIR"
|
printf 'Creating venv: %s\n' "$VENV_DIR"
|
||||||
python3 -m venv "$VENV_DIR"
|
python3 -m venv "$VENV_DIR"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
activate_venv_for_script
|
||||||
printf 'Installing/updating fgAI dependencies...\n'
|
printf 'Installing/updating fgAI dependencies...\n'
|
||||||
"$VENV_DIR/bin/python" -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
"$VENV_DIR/bin/python" -m pip install -e "$ROOT_DIR"
|
python -m pip install -e "$ROOT_DIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
is_running() {
|
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() {
|
start_listener() {
|
||||||
@@ -44,11 +64,20 @@ start_listener() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
nohup "$VENV_DIR/bin/fgai" listen-syslog \
|
if needs_privileged_port; then
|
||||||
--host "$HOST" \
|
printf 'Port %s needs elevated privileges; starting listener with sudo.\n' "$PORT"
|
||||||
--port "$PORT" \
|
sudo nohup "$VENV_DIR/bin/fgai" listen-syslog \
|
||||||
--output "$LOG_FILE" \
|
--host "$HOST" \
|
||||||
--quiet > "$LISTENER_LOG" 2>&1 &
|
--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 '%s\n' "$!" > "$PID_FILE"
|
||||||
|
|
||||||
printf 'Started fgAI syslog listener, pid %s\n' "$(cat "$PID_FILE")"
|
printf 'Started fgAI syslog listener, pid %s\n' "$(cat "$PID_FILE")"
|
||||||
@@ -64,7 +93,9 @@ stop_listener() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
kill "$(cat "$PID_FILE")"
|
if ! kill "$(cat "$PID_FILE")" 2>/dev/null; then
|
||||||
|
sudo kill "$(cat "$PID_FILE")"
|
||||||
|
fi
|
||||||
rm -f "$PID_FILE"
|
rm -f "$PID_FILE"
|
||||||
printf 'Stopped fgAI syslog listener\n'
|
printf 'Stopped fgAI syslog listener\n'
|
||||||
}
|
}
|
||||||
@@ -74,6 +105,9 @@ status_listener() {
|
|||||||
printf 'fgAI syslog listener running, pid %s\n' "$(cat "$PID_FILE")"
|
printf 'fgAI syslog listener running, pid %s\n' "$(cat "$PID_FILE")"
|
||||||
printf 'Input: udp://%s:%s\n' "$HOST" "$PORT"
|
printf 'Input: udp://%s:%s\n' "$HOST" "$PORT"
|
||||||
printf 'Syslog file: %s\n' "$LOG_FILE"
|
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
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -103,7 +137,7 @@ case "$command" in
|
|||||||
;;
|
;;
|
||||||
analyze)
|
analyze)
|
||||||
install_deps
|
install_deps
|
||||||
"$VENV_DIR/bin/fgai" analyze-logs --logs "$LOG_FILE"
|
fgai analyze-logs --logs "$LOG_FILE"
|
||||||
;;
|
;;
|
||||||
install)
|
install)
|
||||||
install_deps
|
install_deps
|
||||||
|
|||||||
Reference in New Issue
Block a user