From 6c7890be28de755aee0f22b8ff9413be39b4c6e7 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Sat, 27 Sep 2025 22:53:11 +0530 Subject: [PATCH] Chore: add timestamp in log directory --- scripts/rolling_update_uvicorn.sh | 25 ++++++++++++++++--------- scripts/start_services.sh | 15 ++++++++++++++- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/scripts/rolling_update_uvicorn.sh b/scripts/rolling_update_uvicorn.sh index c815f63..8a15c87 100755 --- a/scripts/rolling_update_uvicorn.sh +++ b/scripts/rolling_update_uvicorn.sh @@ -6,7 +6,8 @@ set -e # Exit on error ### CONFIGURATION ############################################################# ENV_FILE="api/.env" RUN_DIR="run" -LOG_DIR="logs" +BASE_LOG_DIR="/home/ubuntu/dograh/logs" # Base logs directory (same as start_services.sh) +LATEST_LINK="$BASE_LOG_DIR/latest" # Symlink to latest logs (same as start_services.sh) VENV_PATH="/home/ubuntu/dograh/venv" HEALTH_CHECK_ENDPOINT="/api/v1/health" # Adjust as needed MAX_WAIT_SECONDS=310 # Max wait for graceful shutdown (5 minutes + 10 seconds grace) @@ -143,15 +144,21 @@ start_new_uvicorn_workers() { # Activate virtual environment source ${VENV_PATH}/bin/activate - - # Use the log directory (where start_services.sh put logs) - local log_dir="$LOG_DIR" - - if [[ ! -d "$log_dir" ]]; then - log_error "No log directory found. Run start_services.sh first." + + # Use the latest log directory created by start_services.sh + local log_dir="" + + # First, check if the symlink exists and points to a valid directory + if [[ -L "$LATEST_LINK" ]] && [[ -d "$LATEST_LINK" ]]; then + # Follow the symlink to get the actual directory + log_dir="$BASE_LOG_DIR/$(readlink "$LATEST_LINK")" + log_info "Using existing log directory: $log_dir" + else + log_error "No log directory found. Run start_services.sh first to create logs directory." + log_error "Expected symlink at: $LATEST_LINK" return 1 fi - + # Create unique log filename using timestamp and script PID to avoid conflicts local script_pid=$$ # PID of this rolling_update script (for uniqueness) local timestamp=$(date '+%H%M%S') @@ -306,5 +313,5 @@ echo "✓ Rolling update completed successfully" echo " Old port: ${OLD_PORT:-none}" echo " New port: $NEW_PORT" echo " New PID: $NEW_PID" -echo " Logs: $LOG_DIR/" +echo " Logs: $BASE_LOG_DIR/$LATEST_LINK/" echo "──────────────────────────────────────────────────" \ No newline at end of file diff --git a/scripts/start_services.sh b/scripts/start_services.sh index 9d3305f..083c06b 100755 --- a/scripts/start_services.sh +++ b/scripts/start_services.sh @@ -6,7 +6,10 @@ set -e # Exit on error ### CONFIGURATION ############################################################# ENV_FILE="api/.env" RUN_DIR="run" # where we keep *.pid -LOG_DIR="logs" +BASE_LOG_DIR="/home/ubuntu/dograh/logs" # base logs directory +TIMESTAMP=$(date +"%Y%m%d_%H%M%S") +LOG_DIR="$BASE_LOG_DIR/$TIMESTAMP" # timestamped log directory +LATEST_LINK="$BASE_LOG_DIR/latest" # symlink to latest logs VENV_PATH="/home/ubuntu/dograh/venv" ARQ_WORKERS=${ARQ_WORKERS:-1} @@ -75,8 +78,18 @@ rm -f "$RUN_DIR/uvicorn.port" "$RUN_DIR/uvicorn_new.port" "$RUN_DIR/uvicorn_old. alembic -c api/alembic.ini upgrade head ### 5) Prepare logs ########################################################### +mkdir -p "$BASE_LOG_DIR" mkdir -p "$LOG_DIR" +# Remove old symlink if it exists and create new one +if [[ -L "$LATEST_LINK" ]]; then + rm "$LATEST_LINK" +fi +ln -s "$TIMESTAMP" "$LATEST_LINK" + +echo "Log directory: $LOG_DIR" +echo "Latest symlink: $LATEST_LINK -> $TIMESTAMP" + ### 7) Start services ######################################################### for name in "${!SERVICES[@]}"; do cmd=${SERVICES[$name]}