How aron-666/titan-pcdn works
Step 1: Identify the project type and purpose
• This is a CLI-based service management tool (“Titan-PCDN 服務管理腳本”) that automates the deployment and operation of a PCDN agent using Docker and Docker Compose.
• Its goal is one-click deployment, configuration, logs management, and system tuning for a PCDN proxy service.
Step 2: Analyze the file structure
• Top-level scripts:
• pcdn.sh – main entrypoint for commands (start, stop, config, logs, etc.)
• _pcdn.sh – likely internal helper functions or shared logic
• Infrastructure config:
• docker-compose.yml – defines the containerized PCDN agent and any sidecar services
• Miscellaneous:
• .gitignore, LICENSE.md, README.md—documentation and version control files
Step 3: Examine the README for insights
• The script installs/uses Docker (with optional Chinese registry).
• Generates configuration in a conf/ directory:
• .env (HOOK_ENABLE, HOOK_REGION)
• .key (authorization token)
• Automates system tuning (sysctl, ulimit adjustments).
• Orchestrates containers (startup, shutdown, log streaming) via the CLI.
a. Main components
1. User & CLI layer
– User on Linux host invokes pcdn.sh with commands.
2. Automation script layer
– pcdn.sh and _pcdn.sh contain interactive menus, argument parsing, config-file generation, system tuning logic.
3. Host OS & System services
– Linux kernel, sysctl settings, ulimit adjustments.
4. Container orchestration
– Docker daemon (Engine + API)
– Docker Compose
5. Containers
– PCDN agent container (communicates with remote Titan network)
– (Optional) sidecar or helper container(s), e.g. logging aggregator
6. Configuration volume
– conf/ directory mounted into containers (.env, .key)
7. External services
– Titan-PCDN remote endpoints (protected by token)
– Docker registry (Docker Hub or China mirror)
b. Relationships & interactions
• User → CLI script: issues commands (start, config, logs, etc.)
• CLI script → OS: applies sysctl/ulimit; writes conf/.env and conf/.key
• CLI script → Docker Compose: invokes docker-compose up/down/logs
• Docker Compose → Docker daemon: orchestrates container lifecycle
• Containers → External Titan-PCDN servers: establish PCDN tunnels
• CLI script → Docker daemon: fetches logs or container status
c. Architectural patterns & design principles
• CLI facade pattern: single script wrapping multiple concerns (install, config, run, logs).
• Infrastructure-as-code: everything automated via shell script + docker-compose.
• Containerization: isolates PCDN agent in Docker, simplifies dependency management.
• Volume mounting for configuration: decouples runtime settings from code.
d. Key technologies & libraries
• Shell scripting (Bash)
• Docker & Docker Compose
• sysctl & ulimit for system tuning
• CLI argument parsing and interactive menus
• External registries (GitHub or Gitee mirrors)
Step 5: Tailored guidelines for this CLI/automation project
• Flow from user input to container deployment.
• Script’s dual responsibility: system prep (sysctl/ulimit) and orchestration (Docker Compose).
• Read/write path to conf/ volume for token and environment variables.
• Remote PCDN endpoints and how the agent container connects.
• Clear labels for: User, pcdn.sh, OS/system-tuning, Docker Daemon, Docker Compose, Containers, conf volume, External PCDN.
• From User → pcdn.sh
• pcdn.sh → OS (sysctl/ulimit)
• pcdn.sh → Docker Compose → Docker Daemon → Containers
• Containers ↔ External PCDN servers
• conf volume → Containers
• Grey for Host OS & system services
• Orange for orchestration (Docker/Compose)
• Green for running containers
• Red for external network endpoints
Step 7: Emphasize detail and completeness
• Break the script’s functionality into sub-components (install Docker, config generator, lifecycle commands).
• Sysctl/ulimit tuning as a separate labeled step.
• Optional Chinese-mirror flow: flag -i cn → alternative registry endpoint.