Master Command-Line Deployments with PSSH & PSCP: A Step-by-Step Guide
This tutorial walks you through using PSSH and PSCP for parallel command‑line deployments, establishing SSH trust, packaging and uploading files, handling branch selection, environment targeting, and safe rollback, all illustrated with real‑world examples and code snippets.
HULK already provides S3, Git, and SVN deployment systems; this article focuses on direct command‑line deployment of projects, covering both single‑file and full‑project releases.
1. Understand PSSH and PSCP
PSSH runs commands in parallel on target servers. Basic syntax: pssh -h "hosts.txt" -i "cmd" Key options:
-h: specify a file containing host list
-H: specify hosts as a space‑separated string
-p: set parallelism count
-i: show command output
-x "-o StrictHostKeyChecking=no": skip first‑login confirmation
Success example:
[1] 14:54:03 [SUCCESS] hulk001 [2] 14:54:03 [SUCCESS] hulk002
Failure example:
[1] 15:07:35 [FAILURE] hulk001 Exited with error code 1
Common error codes include 1, 127, 255.
2. Establish Trust Between Servers
Generate an SSH key pair with ssh-keygen (accept defaults). The generated id_rsa (private) and id_rsa.pub (public) are stored in ~/.ssh. Copy the public key to the target machine’s authorized_keys file for the deployment user, then test password‑less login.
3. Deploy Code
Run the deployment script:
~/project/pub(test) >> sh tools/deploy.sh src/application/controller/IndexController.phpThe script prompts for the branch (dev, master, test) and the target environment (test, beta, prod). After confirming the host list and file list, it packages the files, compares MD5 checksums, uploads to a baseline machine, backs up originals, and extracts the new version.
Example prompts and selections:
=== Choose branch === 1 dev 2 master 3 test
Enter branch [master]: test
=== Switch to [test] branch ===
=== Pull remote branch if needed ===
After confirming, the script uploads files in parallel using PSCP, then deploys them with PSSH. Successful upload and deployment messages are shown for each host.
Rollback can be performed with:
sh tools/deploy-revert.sh ~/deploy_bak/project_name/20170601093937.tgz hulk0014. Perfect Whole‑Project Deployment
For large projects, the same process scales: package, upload, and deploy across all servers, then verify. The article notes that operations like ls -sf are not atomic; instead, use ln && mv (which internally performs a rename) to ensure safe updates.
Rollback for all machines is executed with:
sh tools/deploy-revert.sh ~/deploy_bak/project_name/20170601095657.tgzOverall, the guide emphasizes a simple, fast, and reliable command‑line deployment workflow.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
360 Zhihui Cloud Developer
360 Zhihui Cloud is an enterprise open service platform that aims to "aggregate data value and empower an intelligent future," leveraging 360's extensive product and technology resources to deliver platform services to customers.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
