From 4b960835e14821423659444dd3e4a94fbacef155 Mon Sep 17 00:00:00 2001 From: GambleCodez Affiliates Date: Fri, 20 Feb 2026 19:00:38 -0600 Subject: [PATCH] Ensure prod-run creates all required log paths/files --- prod-run.sh | 55 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/prod-run.sh b/prod-run.sh index 9cd7f24..8cac05f 100755 --- a/prod-run.sh +++ b/prod-run.sh @@ -7,6 +7,9 @@ INDEX_FILE="$PROJECT_DIR/index.js" ENV_FILE="$PROJECT_DIR/.env" LOG_DIR="$PROJECT_DIR/logs" BOT_LOG="$LOG_DIR/runewager.log" +LEGACY_BOT_LOG="$PROJECT_DIR/runewager.log" +CRASH_LOG="$LOG_DIR/crash.log" +SYSTEMD_STDOUT_LOG="$LOG_DIR/runewager-1.log" SERVICE_FILE="/etc/systemd/system/runewager.service" LOGROTATE_FILE="/etc/logrotate.d/runewager" CRON_LINE='0 3 * * * /usr/sbin/logrotate -f /etc/logrotate.d/runewager' @@ -31,6 +34,17 @@ ensure_file() { [ -f "$1" ] || : > "$1" } +ensure_log_paths() { + ensure_dir "$LOG_DIR" + ensure_file "$BOT_LOG" + ensure_file "$CRASH_LOG" + ensure_file "$SYSTEMD_STDOUT_LOG" + + if [ ! -f "$LEGACY_BOT_LOG" ]; then + : > "$LEGACY_BOT_LOG" + fi +} + fix_working_directory() { if [ "$(pwd)" != "$PROJECT_DIR" ]; then say "Switching working directory to $PROJECT_DIR" @@ -77,9 +91,14 @@ fix_git_remote_and_branch() { } fix_node_modules() { - if [ ! -d "$PROJECT_DIR/node_modules" ] || [ ! -f "$PROJECT_DIR/node_modules/.package-lock.json" ]; then - say "Installing dependencies with npm ci --omit=dev" - npm ci --omit=dev + if [ ! -d "$PROJECT_DIR/node_modules" ]; then + if [ -f "$PROJECT_DIR/package-lock.json" ]; then + say "Installing dependencies with npm ci --omit=dev" + npm ci --omit=dev + else + say "Installing dependencies with npm install --omit=dev (package-lock.json missing)" + npm install --omit=dev + fi fi } @@ -247,8 +266,8 @@ fix_require_and_import_hints() { ensure_logrotate_config() { local conf - conf=$(cat <<'CONF' -/var/www/html/Runewager/logs/runewager*.log /var/www/html/Runewager/logs/crash.log { + conf=$(cat < "$LOGROTATE_FILE" + fi + if [ -f "$LOGROTATE_FILE" ] && command -v logrotate >/dev/null 2>&1; then if ! logrotate -d "$LOGROTATE_FILE" >/dev/null 2>&1; then warn "logrotate dry-run failed for $LOGROTATE_FILE" @@ -296,7 +320,7 @@ ensure_cron_fallback() { ensure_systemd_service() { local conf - conf=$(cat <<'CONF' + conf=$(cat </dev/null || true)" + if [ -z "$blob" ] && [ -f "$LEGACY_BOT_LOG" ]; then + blob="$(tail -n 200 "$LEGACY_BOT_LOG" 2>/dev/null || true)" + fi say "Human-readable diagnosis" printf '%s\n' "$blob" | grep -qi 'Cannot find module' && say "Root cause: A Node module is missing or a require path is wrong. Run npm ci and verify relative import paths." @@ -433,10 +463,9 @@ main() { exit 1 fi - ensure_dir "$LOG_DIR" + ensure_log_paths ensure_dir "$PROJECT_DIR/data" ensure_dir "$PROJECT_DIR/data/backups" - ensure_file "$BOT_LOG" fix_merge_conflicts fix_lockfiles