updated the config script to auto-scan ports and update the necessary port functions
This commit is contained in:
parent
78015bee80
commit
93088f823a
187
config.sh
187
config.sh
@ -80,9 +80,147 @@ backup_env_file() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to get all used ports on the system
|
||||||
|
get_used_ports() {
|
||||||
|
local used_ports=()
|
||||||
|
|
||||||
|
# Try different methods to get used ports, in order of preference
|
||||||
|
if command -v ss >/dev/null 2>&1; then
|
||||||
|
# Use ss (preferred, modern replacement for netstat)
|
||||||
|
while IFS= read -r line; do
|
||||||
|
if [[ "$line" =~ :([0-9]+)[[:space:]] ]]; then
|
||||||
|
used_ports+=("${BASH_REMATCH[1]}")
|
||||||
|
fi
|
||||||
|
done < <(ss -tuln 2>/dev/null | grep -E ':[0-9]+[[:space:]]')
|
||||||
|
elif command -v netstat >/dev/null 2>&1; then
|
||||||
|
# Use netstat (fallback)
|
||||||
|
while IFS= read -r line; do
|
||||||
|
if [[ "$line" =~ :([0-9]+)[[:space:]] ]]; then
|
||||||
|
used_ports+=("${BASH_REMATCH[1]}")
|
||||||
|
fi
|
||||||
|
done < <(netstat -tuln 2>/dev/null | grep -E ':[0-9]+[[:space:]]')
|
||||||
|
elif command -v lsof >/dev/null 2>&1; then
|
||||||
|
# Use lsof (another fallback)
|
||||||
|
while IFS= read -r line; do
|
||||||
|
if [[ "$line" =~ :([0-9]+)[[:space:]] ]]; then
|
||||||
|
used_ports+=("${BASH_REMATCH[1]}")
|
||||||
|
fi
|
||||||
|
done < <(lsof -i -P -n 2>/dev/null | grep LISTEN | grep -E ':[0-9]+[[:space:]]')
|
||||||
|
else
|
||||||
|
echo "Warning: No port scanning tools available (ss, netstat, or lsof)"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove duplicates and sort
|
||||||
|
printf '%s\n' "${used_ports[@]}" | sort -nu
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to check if a specific port is available
|
||||||
|
is_port_available() {
|
||||||
|
local port=$1
|
||||||
|
local used_ports_list=$2
|
||||||
|
|
||||||
|
# Check if port is in the used ports list
|
||||||
|
if echo "$used_ports_list" | grep -q "^$port$"; then
|
||||||
|
return 1 # Port is in use
|
||||||
|
else
|
||||||
|
return 0 # Port is available
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to find next available port starting from a given port
|
||||||
|
find_next_available_port() {
|
||||||
|
local start_port=$1
|
||||||
|
local used_ports_list=$2
|
||||||
|
local max_attempts=${3:-100} # Maximum ports to check
|
||||||
|
|
||||||
|
for ((i=0; i<max_attempts; i++)); do
|
||||||
|
local test_port=$((start_port + i))
|
||||||
|
|
||||||
|
# Skip ports below 1024 (system ports) and above 65535
|
||||||
|
if [ "$test_port" -lt 1024 ] || [ "$test_port" -gt 65535 ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if is_port_available "$test_port" "$used_ports_list"; then
|
||||||
|
echo "$test_port"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Error: Could not find available port starting from $start_port" >&2
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to initialize available ports for services
|
||||||
|
initialize_available_ports() {
|
||||||
|
echo "Scanning system for used ports to avoid conflicts..."
|
||||||
|
|
||||||
|
# Get list of all used ports
|
||||||
|
local used_ports_list
|
||||||
|
used_ports_list=$(get_used_ports)
|
||||||
|
|
||||||
|
if [ $? -ne 0 ] || [ -z "$used_ports_list" ]; then
|
||||||
|
echo "Warning: Could not scan system ports. Using default ports."
|
||||||
|
echo "You may need to manually resolve conflicts later."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Found $(echo "$used_ports_list" | wc -l) ports currently in use"
|
||||||
|
|
||||||
|
# Define desired starting ports for each service
|
||||||
|
local -A service_ports=(
|
||||||
|
["CODE_SERVER_PORT"]=8888
|
||||||
|
["LISTMONK_PORT"]=9000
|
||||||
|
["LISTMONK_DB_PORT"]=5432
|
||||||
|
["MKDOCS_PORT"]=4000
|
||||||
|
["MKDOCS_SITE_SERVER_PORT"]=4001
|
||||||
|
["N8N_PORT"]=5678
|
||||||
|
["NOCODB_PORT"]=8090
|
||||||
|
["HOMEPAGE_PORT"]=3010
|
||||||
|
["GITEA_WEB_PORT"]=3030
|
||||||
|
["GITEA_SSH_PORT"]=2222
|
||||||
|
)
|
||||||
|
|
||||||
|
# Find available ports for each service
|
||||||
|
local -A available_ports
|
||||||
|
for service in "${!service_ports[@]}"; do
|
||||||
|
local preferred_port=${service_ports[$service]}
|
||||||
|
local available_port
|
||||||
|
|
||||||
|
if is_port_available "$preferred_port" "$used_ports_list"; then
|
||||||
|
available_port=$preferred_port
|
||||||
|
echo "✅ $service: Using preferred port $preferred_port"
|
||||||
|
else
|
||||||
|
available_port=$(find_next_available_port "$preferred_port" "$used_ports_list")
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "⚠️ $service: Port $preferred_port in use, using $available_port instead"
|
||||||
|
else
|
||||||
|
echo "❌ $service: Could not find available port, using $preferred_port (may conflict)"
|
||||||
|
available_port=$preferred_port
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
available_ports[$service]=$available_port
|
||||||
|
# Add the assigned port to used_ports_list to avoid double-assignment
|
||||||
|
used_ports_list=$(printf '%s\n%s' "$used_ports_list" "$available_port" | sort -nu)
|
||||||
|
done
|
||||||
|
|
||||||
|
# Export the available ports as global variables
|
||||||
|
for service in "${!available_ports[@]}"; do
|
||||||
|
export "$service=${available_ports[$service]}"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Port assignment completed successfully!"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
# Function to initialize the .env file with default values
|
# Function to initialize the .env file with default values
|
||||||
initialize_env_file() {
|
initialize_env_file() {
|
||||||
echo "Initializing new .env file with default values..."
|
echo "Initializing new .env file with available ports..."
|
||||||
|
|
||||||
|
# Initialize available ports before creating the .env file
|
||||||
|
initialize_available_ports
|
||||||
|
|
||||||
cat > "$ENV_FILE" << EOL
|
cat > "$ENV_FILE" << EOL
|
||||||
# Never share this file publicly. It contains sensitive information.
|
# Never share this file publicly. It contains sensitive information.
|
||||||
@ -94,17 +232,17 @@ USER_NAME=coder
|
|||||||
USER_ID=1000
|
USER_ID=1000
|
||||||
GROUP_ID=1000
|
GROUP_ID=1000
|
||||||
|
|
||||||
# Port Configuration
|
# Port Configuration (automatically assigned to avoid conflicts)
|
||||||
CODE_SERVER_PORT=8888
|
CODE_SERVER_PORT=${CODE_SERVER_PORT:-8888}
|
||||||
LISTMONK_PORT=9000
|
LISTMONK_PORT=${LISTMONK_PORT:-9000}
|
||||||
LISTMONK_DB_PORT=5432
|
LISTMONK_DB_PORT=${LISTMONK_DB_PORT:-5432}
|
||||||
MKDOCS_PORT=4000
|
MKDOCS_PORT=${MKDOCS_PORT:-4000}
|
||||||
MKDOCS_SITE_SERVER_PORT=4001
|
MKDOCS_SITE_SERVER_PORT=${MKDOCS_SITE_SERVER_PORT:-4001}
|
||||||
N8N_PORT=5678
|
N8N_PORT=${N8N_PORT:-5678}
|
||||||
NOCODB_PORT=8090
|
NOCODB_PORT=${NOCODB_PORT:-8090}
|
||||||
HOMEPAGE_PORT=3010
|
HOMEPAGE_PORT=${HOMEPAGE_PORT:-3010}
|
||||||
GITEA_WEB_PORT=3030
|
GITEA_WEB_PORT=${GITEA_WEB_PORT:-3030}
|
||||||
GITEA_SSH_PORT=2222
|
GITEA_SSH_PORT=${GITEA_SSH_PORT:-2222}
|
||||||
|
|
||||||
# Domain Configuration
|
# Domain Configuration
|
||||||
BASE_DOMAIN=https://changeme.org
|
BASE_DOMAIN=https://changeme.org
|
||||||
@ -141,7 +279,7 @@ N8N_ENCRYPTION_KEY=changeMe
|
|||||||
GENERIC_TIMEZONE=UTC
|
GENERIC_TIMEZONE=UTC
|
||||||
|
|
||||||
# Nocodb Configuration
|
# Nocodb Configuration
|
||||||
NOCODB_PORT=8090
|
NOCODB_PORT=${NOCODB_PORT:-8090}
|
||||||
NOCODB_JWT_SECRET=changeMe
|
NOCODB_JWT_SECRET=changeMe
|
||||||
NOCODB_DB_NAME=nocodb
|
NOCODB_DB_NAME=nocodb
|
||||||
NOCODB_DB_USER=noco
|
NOCODB_DB_USER=noco
|
||||||
@ -149,7 +287,22 @@ NOCODB_DB_PASSWORD=changeMe
|
|||||||
HOMEPAGE_VAR_BASE_URL=https://changeme.org
|
HOMEPAGE_VAR_BASE_URL=https://changeme.org
|
||||||
EOL
|
EOL
|
||||||
|
|
||||||
echo "New .env file created with default values."
|
echo "New .env file created with conflict-free port assignments."
|
||||||
|
|
||||||
|
# Show port assignments summary
|
||||||
|
echo ""
|
||||||
|
echo "=== Port Assignments Summary ==="
|
||||||
|
echo "Code Server: ${CODE_SERVER_PORT:-8888}"
|
||||||
|
echo "Listmonk: ${LISTMONK_PORT:-9000}"
|
||||||
|
echo "Listmonk DB: ${LISTMONK_DB_PORT:-5432}"
|
||||||
|
echo "MkDocs: ${MKDOCS_PORT:-4000}"
|
||||||
|
echo "MkDocs Site: ${MKDOCS_SITE_SERVER_PORT:-4001}"
|
||||||
|
echo "N8N: ${N8N_PORT:-5678}"
|
||||||
|
echo "NocoDB: ${NOCODB_PORT:-8090}"
|
||||||
|
echo "Homepage: ${HOMEPAGE_PORT:-3010}"
|
||||||
|
echo "Gitea Web: ${GITEA_WEB_PORT:-3030}"
|
||||||
|
echo "Gitea SSH: ${GITEA_SSH_PORT:-2222}"
|
||||||
|
echo "================================"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to update the site_url in mkdocs.yml
|
# Function to update the site_url in mkdocs.yml
|
||||||
@ -512,6 +665,12 @@ if [ ! -f "$ENV_FILE" ]; then
|
|||||||
else
|
else
|
||||||
echo "Found existing .env file. Will update values."
|
echo "Found existing .env file. Will update values."
|
||||||
backup_env_file
|
backup_env_file
|
||||||
|
|
||||||
|
# For existing .env files, also scan ports and suggest alternatives if conflicts exist
|
||||||
|
echo ""
|
||||||
|
echo "Checking existing port assignments for conflicts..."
|
||||||
|
load_env_vars
|
||||||
|
check_port_conflicts
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Load existing environment variables
|
# Load existing environment variables
|
||||||
|
|||||||
@ -2,32 +2,32 @@
|
|||||||
# Cloudflare Tunnel Configuration
|
# Cloudflare Tunnel Configuration
|
||||||
# Auto-generated by Changemaker Configuration Wizard
|
# Auto-generated by Changemaker Configuration Wizard
|
||||||
|
|
||||||
tunnel: 4948fed8-3fd4-4562-ace7-d3e9ebc590b0 # e.g. 1234567890abcdef
|
tunnel: ${CF_TUNNEL_ID} # e.g. 1234567890abcdef
|
||||||
credentials-file: /home/coder/.cloudflared/4948fed8-3fd4-4562-ace7-d3e9ebc590b0.json # e.g. /home/coder/.cloudflared/[insert tunnel number].json
|
credentials-file: /home/coder/.cloudflared/${CF_TUNNEL_ID}.json # e.g. /home/coder/.cloudflared/[insert tunnel number].json
|
||||||
ingress:
|
ingress:
|
||||||
|
|
||||||
- hostname: homepage.albertademocracytaskforce.org
|
- hostname: homepage.test.com
|
||||||
service: http://localhost:3010
|
service: http://localhost:3010
|
||||||
|
|
||||||
- hostname: code.albertademocracytaskforce.org
|
- hostname: code.test.com
|
||||||
service: http://localhost:8888
|
service: http://localhost:8888
|
||||||
|
|
||||||
- hostname: listmonk.albertademocracytaskforce.org
|
- hostname: listmonk.test.com
|
||||||
service: http://localhost:9000
|
service: http://localhost:9001
|
||||||
|
|
||||||
- hostname: docs.albertademocracytaskforce.org
|
- hostname: docs.test.com
|
||||||
service: http://localhost:4000
|
service: http://localhost:4000
|
||||||
|
|
||||||
- hostname: albertademocracytaskforce.org
|
- hostname: test.com
|
||||||
service: http://localhost:4001
|
service: http://localhost:4002
|
||||||
|
|
||||||
- hostname: n8n.albertademocracytaskforce.org
|
- hostname: n8n.test.com
|
||||||
service: http://localhost:5678
|
service: http://localhost:5678
|
||||||
|
|
||||||
- hostname: db.albertademocracytaskforce.org
|
- hostname: db.test.com
|
||||||
service: http://localhost:8090
|
service: http://localhost:8090
|
||||||
|
|
||||||
- hostname: git.albertademocracytaskforce.org
|
- hostname: git.test.com
|
||||||
service: http://localhost:3030
|
service: http://localhost:3030
|
||||||
|
|
||||||
# Catch-all rule (required)
|
# Catch-all rule (required)
|
||||||
|
|||||||
87
configs/homepage/services.yaml.backup_20250602_184336
Normal file
87
configs/homepage/services.yaml.backup_20250602_184336
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
---
|
||||||
|
# For public access, replace "http://localhost" with your subdomain URLs
|
||||||
|
|
||||||
|
- Essential Tools:
|
||||||
|
- Code Server:
|
||||||
|
href: "http://localhost:8888"
|
||||||
|
# href: "https://code.albertademocracytaskforce.org" # Uncomment for public access
|
||||||
|
description: VS Code in the browser
|
||||||
|
icon: mdi-code-braces
|
||||||
|
widget:
|
||||||
|
type: docker
|
||||||
|
container: code-server-changemaker
|
||||||
|
server: my-docker
|
||||||
|
- Listmonk:
|
||||||
|
href: "http://localhost:9000"
|
||||||
|
# href: "https://listmonk.albertademocracytaskforce.org" # Uncomment for public access
|
||||||
|
description: Newsletter & mailing list manager
|
||||||
|
icon: mdi-email-newsletter
|
||||||
|
widget:
|
||||||
|
type: docker
|
||||||
|
container: listmonk_app
|
||||||
|
server: my-docker
|
||||||
|
- NocoDB:
|
||||||
|
href: "http://localhost:8090"
|
||||||
|
# href: "https://db.albertademocracytaskforce.org" # Uncomment for public access
|
||||||
|
description: No-code database platform
|
||||||
|
icon: mdi-database
|
||||||
|
widget:
|
||||||
|
type: docker
|
||||||
|
container: changemakerlite-nocodb-1
|
||||||
|
server: my-docker
|
||||||
|
- Gitea:
|
||||||
|
href: "http://localhost:3030"
|
||||||
|
# href: "https://git.albertademocracytaskforce.org" # Uncomment for public access
|
||||||
|
description: Git repository hosting
|
||||||
|
icon: mdi-git
|
||||||
|
widget:
|
||||||
|
type: docker
|
||||||
|
container: gitea_changemaker
|
||||||
|
server: my-docker
|
||||||
|
|
||||||
|
- Content & Documentation:
|
||||||
|
- MkDocs (Live):
|
||||||
|
href: "http://localhost:4000"
|
||||||
|
# href: "https://docs.albertademocracytaskforce.org" # Uncomment for public access
|
||||||
|
description: Live documentation server with hot reload
|
||||||
|
icon: mdi-book-open-page-variant
|
||||||
|
widget:
|
||||||
|
type: docker
|
||||||
|
container: mkdocs-changemaker
|
||||||
|
server: my-docker
|
||||||
|
- Static Site:
|
||||||
|
href: "http://localhost:4001"
|
||||||
|
# href: "https://albertademocracytaskforce.org" # Uncomment for public access
|
||||||
|
description: Built documentation hosting
|
||||||
|
icon: mdi-web
|
||||||
|
widget:
|
||||||
|
type: docker
|
||||||
|
container: mkdocs-site-server-changemaker
|
||||||
|
server: my-docker
|
||||||
|
|
||||||
|
- Automation & Infrastructure:
|
||||||
|
- n8n:
|
||||||
|
href: "http://localhost:5678"
|
||||||
|
# href: "https://n8n.albertademocracytaskforce.org" # Uncomment for public access
|
||||||
|
description: Workflow automation platform
|
||||||
|
icon: mdi-workflow
|
||||||
|
widget:
|
||||||
|
type: docker
|
||||||
|
container: n8n-changemaker
|
||||||
|
server: my-docker
|
||||||
|
- PostgreSQL (Listmonk):
|
||||||
|
href: "#"
|
||||||
|
description: Database for Listmonk
|
||||||
|
icon: mdi-database-outline
|
||||||
|
widget:
|
||||||
|
type: docker
|
||||||
|
container: listmonk_db
|
||||||
|
server: my-docker
|
||||||
|
- PostgreSQL (NocoDB):
|
||||||
|
href: "#"
|
||||||
|
description: Database for NocoDB
|
||||||
|
icon: mdi-database-outline
|
||||||
|
widget:
|
||||||
|
type: docker
|
||||||
|
container: changemakerlite-root_db-1
|
||||||
|
server: my-docker
|
||||||
9
mkdocs/docs/overrides/main.html.backup_20250602_184336
Normal file
9
mkdocs/docs/overrides/main.html.backup_20250602_184336
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block extrahead %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block announce %}
|
||||||
|
<a href="https://homepage.albertademocracytaskforce.org" class="login-button">Login</a>
|
||||||
|
Changemaker Archive. <a href="https://docs.bnkops.com">Learn more</a>
|
||||||
|
{% endblock %}
|
||||||
Loading…
x
Reference in New Issue
Block a user