Smarter prod-run health summary and resilient systemd/logrotate handling - #49
Conversation
|
CodeAnt AI is reviewing your PR. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughThe prod-run.sh script introduces health monitoring functionality with new helper functions to check bot process status and log freshness. It adds dynamic user/group resolution for systemd and logrotate configurations, refactors process detection logic, and integrates error reporting into the main startup flow for improved visibility and service management. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
Note 🎁 Summarized by CodeRabbit FreeYour 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 |
Nitpicks 🔍
|
|
|
||
|
|
||
| get_bot_pid() { | ||
| pgrep -f "node .*index\.js" | head -n 1 || true |
There was a problem hiding this comment.
Suggestion: The bot PID detection uses a very generic pgrep -f "node .*index\.js" pattern, which can match any node index.js process on the host, so on systems running multiple Node apps it may incorrectly treat an unrelated process as this bot, causing health summaries and launch logic to report the bot as running and skip starting it when it is actually down. [logic error]
Severity Level: Major ⚠️
- ❌ Bot restart skipped when another node index.js is running.
- ⚠️ Health summary misreports status using wrong PID and logs.
- ⚠️ Operators may trust false positives from prod-run.sh checks.| pgrep -f "node .*index\.js" | head -n 1 || true | |
| # Restrict match to this project's index.js to avoid grabbing unrelated node processes | |
| pgrep -f "node .*${PROJECT_DIR}/index\.js" | head -n 1 || true |
Steps of Reproduction ✅
1. Deploy the app using the documented flow so that systemd or an operator runs
`/var/www/html/Runewager/prod-run.sh` as described in `README.md:102-171` and
`runewager.service:8-9`.
2. Start a different Node service on the same host with a generic entrypoint, e.g. `node
/opt/otherapp/index.js`, so that `pgrep -f "node .*index\.js"` matches this unrelated
process.
3. Stop the actual Runewager bot so there is no `node $PROJECT_DIR/index.js` process, then
invoke `./prod-run.sh` (or let systemd restart it), which calls `check_bot_status_twice()`
at `prod-run.sh:487-490`.
4. Observe that `get_bot_pid()` at `prod-run.sh:50-52` returns the PID of the other app,
causing `print_health_summary()` at `prod-run.sh:66-75` and `is_bot_running()` at
`prod-run.sh:483-485` to treat the bot as running, so `start_background_if_needed()` at
`prod-run.sh:493-513` skips launching the real bot even though it is down.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** prod-run.sh
**Line:** 51:51
**Comment:**
*Logic Error: The bot PID detection uses a very generic `pgrep -f "node .*index\.js"` pattern, which can match any `node index.js` process on the host, so on systems running multiple Node apps it may incorrectly treat an unrelated process as this bot, causing health summaries and launch logic to report the bot as running and skip starting it when it is actually down.
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 finished reviewing your PR. |
User description
Motivation
runewageruser or have legacy log locations by falling back to valid users/groups and legacy log files.Description
HEALTH_LOG_MAX_AGE_MINUTES,get_bot_pid(),log_age_seconds()andprint_health_summary()to report✅ Bot is running (pid: ...), log freshness, and a concrete restart suggestion when/startmay be unresponsive.is_bot_running/status prints withprint_health_summarycalls so health checks evaluate both process and log activity.ensure_log_paths()and using the legacyrunewager.logwhen the primary log is empty.ensure_logrotate_config()emit acreateline using a fallback owner/group whenrunewageruser is missing and includelogrotatedry-run stderr in warnings for clearer diagnostics.ensure_systemd_service()dynamically select a valid serviceUser/Groupwhenrunewageris absent and validate/replace stale directives (includingStandardOutput) with$PROJECT_DIR/$SYSTEMD_STDOUT_LOGvalues.print_human_errors()runs at the end to provide context after status checks.Testing
bash -n prod-run.sh, which passed.prod-run.shto verify added functions, reordered flow, and updated systemd/logrotate templates.Codex Task
CodeAnt-AI Description
Provide clearer bot health summary and make systemd/logrotate resilient to missing users and legacy logs
What Changed
Impact
✅ Clearer bot health messages with pid and log freshness✅ Fewer service failures on hosts without runewager user✅ More actionable logrotate diagnostics💡 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:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
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:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
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.