diff --git a/README.md b/README.md index 2e9ce4a..0e891f8 100644 --- a/README.md +++ b/README.md @@ -262,6 +262,8 @@ journalctl -u xmonitor-sender.service -f ls /home/ubuntu/xMonitor/logs ``` +When run manually, the script now auto-loads `/etc/xmonitor/xmonitor.env` if that file exists. + ### Behavior - Hotspot connect retry: every 5 seconds until the target SSID is connected diff --git a/scripts/start_monitor_sender.sh b/scripts/start_monitor_sender.sh index d3c23dd..f91e291 100644 --- a/scripts/start_monitor_sender.sh +++ b/scripts/start_monitor_sender.sh @@ -27,6 +27,12 @@ trap 'report_err "${LINENO}" "${BASH_COMMAND}"' ERR SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" DEFAULT_APP_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)" +ENV_FILE="${ENV_FILE:-/etc/xmonitor/xmonitor.env}" + +if [[ -f "${ENV_FILE}" ]]; then + # shellcheck disable=SC1090 + source "${ENV_FILE}" +fi RUN_USER="${RUN_USER:-$(id -un)}" APP_DIR="${APP_DIR:-${DEFAULT_APP_DIR}}" @@ -173,9 +179,14 @@ wait_for_server() { log "Starting xMonitor sender bootstrap" log "Using APP_DIR='${APP_DIR}'" log "Log file: ${LOG_FILE}" +if [[ -f "${ENV_FILE}" ]]; then + log "Loaded environment from '${ENV_FILE}'" +else + log "Environment file '${ENV_FILE}' not found; using current shell environment/defaults" +fi prune_old_logs -[[ -n "${HOTSPOT_SSID}" ]] || fail "HOTSPOT_SSID must be set in /etc/xmonitor/xmonitor.env" +[[ -n "${HOTSPOT_SSID}" ]] || fail "HOTSPOT_SSID must be set in '${ENV_FILE}' or exported before launching the script" [[ -d "${APP_DIR}" ]] || fail "APP_DIR does not exist: ${APP_DIR}" [[ -f "${APP_DIR}/monitor_sender.py" ]] || fail "monitor_sender.py not found in ${APP_DIR}" [[ -f "${ROS_SETUP}" ]] || fail "ROS setup file not found: ${ROS_SETUP}"