feat(install): add port conflict detection before starting services#15
feat(install): add port conflict detection before starting services#15logicalangel wants to merge 1 commit intoPasarGuard:mainfrom
Conversation
Check if UVICORN_PORT (default 8000) is already in use before starting Docker containers. If a conflict is detected, prompt the user for an alternative port and update .env accordingly (both UVICORN_PORT and ALLOWED_ORIGINS). This prevents the infinite restart loop that occurs when another service occupies the configured port, since PasarGuard uses network_mode: host. Closes PasarGuard#10
WalkthroughThe installation script now detects port conflicts before deployment. During setup, it checks if the configured Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pasarguard.sh (1)
3746-3785: Port conflict detection logic looks solid and addresses the issue requirements.The implementation correctly:
- Reads
UVICORN_PORTfrom.envwith a sensible default of 8000- Uses the existing
is_port_in_use()utility for detection- Validates port range and availability in a prompt loop
- Updates both
UVICORN_PORTandALLOWED_ORIGINSin the.envfileOne minor improvement per the static analysis hint:
🔧 Add `-r` flag to `read` command
The
readcommand on line 3760 should include the-rflag to prevent backslash interpretation. While users are unlikely to enter backslashes in port numbers, it's a shell scripting best practice.while true; do - read -p "Enter a different port for PasarGuard (1-65535) or 'q' to abort: " new_port + read -rp "Enter a different port for PasarGuard (1-65535) or 'q' to abort: " new_port if [[ "$new_port" == "q" || "$new_port" == "Q" ]]; then🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pasarguard.sh` around lines 3746 - 3785, The read invocation inside the port prompt loop should use the -r flag to prevent backslash interpretation; update the read command that assigns to new_port (inside the while true loop that validates ports) to use read -r so user input is read raw; no other logic changes needed—this affects the read that prompts "Enter a different port for PasarGuard..." in the block that checks is_port_in_use and later calls set_or_uncomment_env_var and up_pasarguard.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@pasarguard.sh`:
- Around line 3746-3785: The read invocation inside the port prompt loop should
use the -r flag to prevent backslash interpretation; update the read command
that assigns to new_port (inside the while true loop that validates ports) to
use read -r so user input is read raw; no other logic changes needed—this
affects the read that prompts "Enter a different port for PasarGuard..." in the
block that checks is_port_in_use and later calls set_or_uncomment_env_var and
up_pasarguard.
Summary
Adds automatic port conflict detection during installation to prevent the infinite Docker restart loop described in #10.
Problem
When another service already occupies port 8000 (the default
UVICORN_PORT),docker compose upstarts PasarGuard withnetwork_mode: host, which causes:This leads to an infinite restart loop since there is no pre-flight port check.
Solution
After the
.envfile is written and beforeup_pasarguard()starts the containers, the script now:UVICORN_PORTfrom.env(defaults to 8000)is_port_in_use()utilityUVICORN_PORTandALLOWED_ORIGINSin.envChanges
install_command(), placed betweeninstall_completionandup_pasarguardcalls.Testing
is_port_in_use()function (ss → netstat → lsof fallback chain)Closes #10
Summary by CodeRabbit