Commit 5699cf7c authored by Your Name's avatar Your Name

Fix aisbf.sh to respect server.host from aisbf.json config

- Added find_config_file() to check config locations in correct order
- Added get_host() to read server.host from config (defaults to 127.0.0.1)
- Fixed get_port() to read from server.port instead of top-level port
- Updated start_server() and start_daemon() to use config-based host
- Updated CHANGELOG.md with the fix
parent e2243ed6
......@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [0.9.9] - 2026-04-04
### Fixed
- **aisbf.sh Host Configuration**: Fixed `aisbf.sh` always launching with `--host 127.0.0.1` regardless of `aisbf.json` configuration
- Added `find_config_file()` function that checks config locations in the correct order: `~/.aisbf/aisbf.json`, `/usr/share/aisbf/aisbf.json`, `~/.local/share/aisbf/aisbf.json`, then `$SHARE_DIR/config/aisbf.json`
- Added `get_host()` function that reads `server.host` from the found config file, defaulting to `127.0.0.1` if config cannot be resolved
- Fixed `get_port()` to correctly read from `server.port` (was reading top-level `port` which doesn't exist in the config structure)
- Updated `start_server()` and `start_daemon()` to use `HOST=$(get_host)` and pass `--host $HOST` to uvicorn
- Startup message now shows `Starting AISBF on $HOST:$PORT...` so users can see which address/port is being used
## [0.9.8] - 2026-04-04
### Added
......
......@@ -41,13 +41,75 @@ fi
# Create log directory if it doesn't exist
mkdir -p "$LOG_DIR"
# Function to find the aisbf.json config file
# Checks user config first, then installed locations, then source tree
find_config_file() {
# Check user config first (~/.aisbf/aisbf.json)
if [ -f "$HOME/.aisbf/aisbf.json" ]; then
echo "$HOME/.aisbf/aisbf.json"
return
fi
# Check installed locations
if [ -f "/usr/share/aisbf/aisbf.json" ]; then
echo "/usr/share/aisbf/aisbf.json"
return
fi
if [ -f "$HOME/.local/share/aisbf/aisbf.json" ]; then
echo "$HOME/.local/share/aisbf/aisbf.json"
return
fi
# Check source tree config
if [ -f "$SHARE_DIR/config/aisbf.json" ]; then
echo "$SHARE_DIR/config/aisbf.json"
return
fi
# Not found
echo ""
}
# Function to get host from config file
get_host() {
local DEFAULT_HOST="127.0.0.1"
local CONFIG_FILE=$(find_config_file)
# Check if config file was found
if [ -z "$CONFIG_FILE" ]; then
echo "$DEFAULT_HOST"
return
fi
# Try to read host from config using Python
local HOST=$(python3 -c "
import json
import sys
try:
with open('$CONFIG_FILE', 'r') as f:
config = json.load(f)
server = config.get('server', {})
print(server.get('host', '$DEFAULT_HOST'))
except:
print('$DEFAULT_HOST')
" 2>/dev/null)
# Validate host is not empty
if [ -n "$HOST" ]; then
echo "$HOST"
else
echo "$DEFAULT_HOST"
fi
}
# Function to get port from config file
get_port() {
local CONFIG_FILE="$SHARE_DIR/config/aisbf.json"
local DEFAULT_PORT=17765
local CONFIG_FILE=$(find_config_file)
# Check if config file exists
if [ ! -f "$CONFIG_FILE" ]; then
# Check if config file was found
if [ -z "$CONFIG_FILE" ]; then
echo "$DEFAULT_PORT"
return
fi
......@@ -59,7 +121,8 @@ import sys
try:
with open('$CONFIG_FILE', 'r') as f:
config = json.load(f)
print(config.get('port', $DEFAULT_PORT))
server = config.get('server', {})
print(server.get('port', $DEFAULT_PORT))
except:
print($DEFAULT_PORT)
" 2>/dev/null)
......@@ -140,7 +203,8 @@ start_server() {
# Ensure venv exists
ensure_venv
# Get port from config
# Get host and port from config
HOST=$(get_host)
PORT=$(get_port)
# Activate the virtual environment
......@@ -149,7 +213,7 @@ start_server() {
# Change to share directory where main.py is located
cd $SHARE_DIR
echo "Starting AISBF on port $PORT..."
echo "Starting AISBF on $HOST:$PORT..."
# Check if debug mode is enabled
if [ "$DEBUG" = "true" ]; then
......@@ -160,9 +224,9 @@ start_server() {
# Start the proxy server - runs in foreground
# Use exec to replace the shell process so signals are properly handled
if [ "$DEBUG" = "true" ]; then
exec uvicorn main:app --host 127.0.0.1 --port $PORT --log-level debug 2>&1 | tee -a "$LOG_DIR/aisbf_stdout.log"
exec uvicorn main:app --host $HOST --port $PORT --log-level debug 2>&1 | tee -a "$LOG_DIR/aisbf_stdout.log"
else
exec uvicorn main:app --host 127.0.0.1 --port $PORT 2>&1 | grep -v -E "(--- Logging error ---|BrokenPipeError|Call stack:|Message:|Arguments:)" | tee -a "$LOG_DIR/aisbf_stdout.log"
exec uvicorn main:app --host $HOST --port $PORT 2>&1 | grep -v -E "(--- Logging error ---|BrokenPipeError|Call stack:|Message:|Arguments:)" | tee -a "$LOG_DIR/aisbf_stdout.log"
fi
}
......@@ -183,10 +247,11 @@ start_daemon() {
# Ensure venv exists
ensure_venv
# Get port from config
# Get host and port from config
HOST=$(get_host)
PORT=$(get_port)
echo "Starting AISBF on port $PORT in background..."
echo "Starting AISBF on $HOST:$PORT in background..."
# Check if debug mode is enabled
if [ "$DEBUG" = "true" ]; then
......@@ -197,9 +262,9 @@ start_daemon() {
# Start in background with nohup and logging
# Filter out BrokenPipeError logging errors
if [ "$DEBUG" = "true" ]; then
nohup bash -c "source $VENV_DIR/bin/activate && cd $SHARE_DIR && uvicorn main:app --host 127.0.0.1 --port $PORT --log-level debug 2>&1" >> "$LOG_DIR/aisbf_stdout.log" 2>&1 &
nohup bash -c "source $VENV_DIR/bin/activate && cd $SHARE_DIR && uvicorn main:app --host $HOST --port $PORT --log-level debug 2>&1" >> "$LOG_DIR/aisbf_stdout.log" 2>&1 &
else
nohup bash -c "source $VENV_DIR/bin/activate && cd $SHARE_DIR && uvicorn main:app --host 127.0.0.1 --port $PORT 2>&1 | grep -v '--- Logging error ---' | grep -v 'BrokenPipeError' | grep -v 'Call stack:' | grep -v 'File .*python' | grep -v 'Message:' | grep -v 'Arguments:'" >> "$LOG_DIR/aisbf_stdout.log" 2>&1 &
nohup bash -c "source $VENV_DIR/bin/activate && cd $SHARE_DIR && uvicorn main:app --host $HOST --port $PORT 2>&1 | grep -v '--- Logging error ---' | grep -v 'BrokenPipeError' | grep -v 'Call stack:' | grep -v 'File .*python' | grep -v 'Message:' | grep -v 'Arguments:'" >> "$LOG_DIR/aisbf_stdout.log" 2>&1 &
fi
PID=$!
echo $PID > "$PIDFILE"
......
......@@ -12,7 +12,7 @@
"classify_privacy": false,
"classify_semantic": false,
"server": {
"host": "0.0.0.0",
"host": "127.0.0.1",
"port": 17765,
"protocol": "http",
"ssl_certfile": null,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment