Chore: add timestamp in log directory

This commit is contained in:
Abhishek Kumar 2025-09-27 22:53:11 +05:30
parent 4629cc676a
commit 6c7890be28
2 changed files with 30 additions and 10 deletions

View file

@ -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 "──────────────────────────────────────────────────"

View file

@ -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]}