forked from anthropics/anthropic-quickstarts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement dynamic port allocation to avoid conflicts
Fixes anthropics#147 Implement dynamic port allocation to avoid conflicts with reserved ports. * **computer-use-demo/image/x11vnc_startup.sh** - Add functions to check port availability and find an available port. - Dynamically assign the VNC server port instead of hardcoding port 5900. - Update the `netstat` command to use the dynamically assigned port. * **computer-use-demo/image/novnc_startup.sh** - Add functions to check port availability and find an available port. - Dynamically assign the VNC server port instead of hardcoding port 5900. - Modify the `--vnc` option to use the dynamic port. * **computer-use-demo/image/port_check.sh** - Create a script to check port availability. - Use `lsof` to check if a port is in use. - Return an available port if the specified one is in use. * **computer-use-demo/.ports** - Maintain a list of reserved ports. - Include common ports used by macOS and other systems. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/anthropics/anthropic-quickstarts/issues/147?shareId=XXXX-XXXX-XXXX-XXXX).
- Loading branch information
1 parent
bbff506
commit 2c7fcb5
Showing
4 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Reserved Ports List | ||
# This file contains a list of ports that are reserved and should not be used by the application. | ||
|
||
# Common ports used by macOS and other systems | ||
5900 # VNC | ||
22 # SSH | ||
80 # HTTP | ||
443 # HTTPS | ||
3389 # RDP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
|
||
# Function to check if a port is in use | ||
check_port() { | ||
local port=$1 | ||
if lsof -i :$port >/dev/null 2>&1; then | ||
return 1 # Port is in use | ||
else | ||
return 0 # Port is available | ||
fi | ||
} | ||
|
||
# Function to find an available port starting from a given port | ||
find_available_port() { | ||
local start_port=$1 | ||
local port=$start_port | ||
while ! check_port $port; do | ||
((port++)) | ||
done | ||
echo $port | ||
} | ||
|
||
# Main script | ||
if [ $# -ne 1 ]; then | ||
echo "Usage: $0 <start_port>" | ||
exit 1 | ||
fi | ||
|
||
start_port=$1 | ||
available_port=$(find_available_port $start_port) | ||
echo $available_port |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters