Skip to content

Ensure prod-run.sh creates required log files and supports legacy log path - #48

Merged
gamblecodezcom merged 2 commits into
mainfrom
codex/main
Feb 21, 2026
Merged

Ensure prod-run.sh creates required log files and supports legacy log path#48
gamblecodezcom merged 2 commits into
mainfrom
codex/main

Conversation

@gamblecodezcom

@gamblecodezcom gamblecodezcom commented Feb 21, 2026

Copy link
Copy Markdown
Owner

User description

Motivation

  • Prevent startup/diagnostic failures on fresh clones where gitignored log files are missing by ensuring the runtime log paths exist.
  • Make runtime-generated operational configs consistent and portable by centralizing log path variables and supporting an existing legacy root runewager.log for backward compatibility.

Description

  • Added new log path variables (LEGACY_BOT_LOG, CRASH_LOG, SYSTEMD_STDOUT_LOG) and implemented ensure_log_paths() to create the logs directory and all expected log files before other checks.
  • Wired ensure_log_paths() into main() so log creation runs early in startup.
  • Updated systemd template and validation to use the consolidated $SYSTEMD_STDOUT_LOG variable for StandardOutput and to regenerate stale units that do not match the detected PROJECT_DIR/LOG_DIR.
  • Made ensure_logrotate_config() emit a $LOG_DIR-based template and replaced the logrotate file when it doesn't reference the detected LOG_DIR, and added diagnostics fallback in print_human_errors() to read the legacy log if the primary log is empty.

Testing

  • Ran a shell syntax check with bash -n prod-run.sh, which passed.
  • Performed a static review of the resulting prod-run.sh diff to confirm the new variables, ensure_log_paths() invocation, and updated systemd/logrotate templates were applied as intended.

Codex Task


CodeAnt-AI Description

Ensure prod-run creates required log files and supports legacy runewager.log

What Changed

  • prod-run now creates the logs directory and these files at startup: logs/runewager.log, logs/crash.log, logs/runewager-1.log, and the legacy project-root runewager.log if missing
  • Systemd unit generation now points StandardOutput to the consolidated logs/runewager-1.log path
  • Diagnostic output falls back to the legacy project-root runewager.log when the primary bot log is empty so human-readable errors show up

Impact

✅ Fewer startup failures on fresh clones
✅ Clearer diagnostics when logs are missing
✅ Backwards-compatible log location for older deployments

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

@codeant-ai

codeant-ai Bot commented Feb 21, 2026

Copy link
Copy Markdown

CodeAnt AI is reviewing your PR.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Feb 21, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@gamblecodezcom has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 2 minutes and 35 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

@gamblecodezcom
gamblecodezcom merged commit a98bafc into main Feb 21, 2026
1 check passed
@gamblecodezcom
gamblecodezcom deleted the codex/main branch February 21, 2026 01:01
@codeant-ai codeant-ai Bot added the size:S This PR changes 10-29 lines, ignoring generated files label Feb 21, 2026
@codeant-ai

codeant-ai Bot commented Feb 21, 2026

Copy link
Copy Markdown

Sequence Diagram

The PR makes prod-run.sh create required log files (including a legacy path) early, centralizes SYSTEMD_STDOUT_LOG/LOG_DIR for systemd and logrotate templates, and falls back to the legacy log when producing human-readable diagnostics. This diagram shows the main success path of those changes.

sequenceDiagram
    participant Operator
    participant prod-run.sh
    participant Filesystem
    participant ServiceManager
    participant Logrotate

    Operator->>prod-run.sh: start main()
    prod-run.sh->>Filesystem: ensure_log_paths (create logs dir, BOT_LOG, CRASH_LOG, SYSTEMD_STDOUT_LOG, ensure legacy BOT file)
    prod-run.sh->>ServiceManager: ensure_systemd_service (write/regenerate unit with StandardOutput=append:$SYSTEMD_STDOUT_LOG; daemon-reload)
    prod-run.sh->>Logrotate: ensure_logrotate_config (write/replace config referencing $LOG_DIR)
    prod-run.sh->>Filesystem: print_human_errors (tail BOT_LOG; if empty read LEGACY_BOT_LOG)
    prod-run.sh-->>Operator: report status / diagnostics
Loading

Generated by CodeAnt AI

@codeant-ai

codeant-ai Bot commented Feb 21, 2026

Copy link
Copy Markdown

Nitpicks 🔍

🔒 No security issues identified
⚡ Recommended areas for review

  • Systemd stdout handling
    The systemd service template and subsequent validation use StandardOutput=append:$SYSTEMD_STDOUT_LOG. Confirm systemd on target systems supports the chosen directive form and the script's replacement logic will detect/invalidate stale units reliably. Also verify that writing/overwriting /etc/systemd/system/runewager.service will be safe on systems where the service is managed differently.

  • Logrotate pattern match
    The check that decides whether to replace the logrotate file uses grep -F with a glob pattern ("$LOG_DIR/runewager*.log"). Using -F treats the pattern as a fixed string, so the '*' will not behave as a glob and the check may incorrectly think the file doesn't reference the expected logs (causing unnecessary replacements) or miss existing valid entries. Consider using a regex-aware check or a more robust presence test for runewager log entries.

Comment thread prod-run.sh
ensure_dir "$LOG_DIR"
ensure_file "$BOT_LOG"
ensure_file "$CRASH_LOG"
ensure_file "$SYSTEMD_STDOUT_LOG"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Pre-creating the systemd stdout log file in ensure_log_paths() can cause permission errors when the script is run as a different user than the systemd service user: if prod-run.sh is ever run manually as root, it will create $SYSTEMD_STDOUT_LOG as a root-owned file, and later when systemd starts the service as the runewager user with StandardOutput=append:$SYSTEMD_STDOUT_LOG, systemd will fail to append to this file with "permission denied", preventing the service from starting correctly. Letting systemd create and own its own stdout log file avoids this mismatch. [logic error]

Severity Level: Critical 🚨
- ❌ Systemd runewager service fails to start on production VPS.
- ❌ Telegram bot offline; /health and /metrics endpoints unavailable.
- ⚠️ Manual prod-run.sh diagnostics can silently break systemd logging.
Suggested change
ensure_file "$SYSTEMD_STDOUT_LOG"
Steps of Reproduction ✅
1. Set up the production deployment under `/var/www/html/Runewager` following
`README.md:102-155`, which creates the `runewager` system user and the app directory and
installs the provided unit file `/var/www/html/Runewager/runewager.service`.

2. Inspect the unit file `/var/www/html/Runewager/runewager.service` (lines 8-12 and 18 in
that file): it runs `ExecStart=/var/www/html/Runewager/prod-run.sh` as `User=runewager`
and `Group=runewager`, with
`StandardOutput=append:/var/www/html/Runewager/logs/runewager-1.log`.

3. As `root` (or any user different from `runewager`), run the startup script manually in
the app directory: `cd /var/www/html/Runewager && ./prod-run.sh`. In
`prod-run.sh:454-466`, `main()` calls `ensure_log_paths`, which in turn calls `ensure_file
"$SYSTEMD_STDOUT_LOG"` at `prod-run.sh:41`, creating or truncating
`/var/www/html/Runewager/logs/runewager-1.log` owned by `root` (typically mode `0644
root:root`).

4. Restart the systemd service: `sudo systemctl restart runewager`. Systemd now starts
`prod-run.sh` as `User=runewager` (unit lines 8-12) and tries to append to
`/var/www/html/Runewager/logs/runewager-1.log` per
`StandardOutput=append:/var/www/html/Runewager/logs/runewager-1.log` (unit line 18), but
the file is owned by `root` and not writable by `runewager`, so systemd fails to open the
stdout log with a permission denied error and the `runewager` service fails to start.
Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** prod-run.sh
**Line:** 41:41
**Comment:**
	*Logic Error: Pre-creating the systemd stdout log file in `ensure_log_paths()` can cause permission errors when the script is run as a different user than the systemd service user: if `prod-run.sh` is ever run manually as root, it will create `$SYSTEMD_STDOUT_LOG` as a root-owned file, and later when systemd starts the service as the `runewager` user with `StandardOutput=append:$SYSTEMD_STDOUT_LOG`, systemd will fail to append to this file with "permission denied", preventing the service from starting correctly. Letting systemd create and own its own stdout log file avoids this mismatch.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
👍 | 👎

@codeant-ai

codeant-ai Bot commented Feb 21, 2026

Copy link
Copy Markdown

CodeAnt AI finished reviewing your PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex size:S This PR changes 10-29 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant