Server management scripts for RunCloud-managed WordPress hosting fleet.
- 20 production servers across SG, VN, JP regions (see
~/.rc/config.yaml) - Multi-user: apps live under
/home/*/webapps/, not just/home/runcloud/ - SSH access: all servers via root, ports vary (22 or 2018, defined in config)
- Git-tracked: repo cloned at
/root/runcloud-bash-scripts/on every server - Dashboard integration: scripts registered as actions in
runcloud-go/internal/web/server.goappScriptsmap
- All scripts use
set -euo pipefail - Color helpers:
info(),success(),warn(),error() - Site resolution: accept
--site=NAME(searches/home/*/webapps/) or--path=PATH(full path) - Site owner detection:
stat -c '%U'(Linux) withstat -f '%Su'(BSD) fallback - wp-cli: search multiple paths (
/usr/local/bin/wp,/usr/bin/wp, RunCloud agent) - Run wp-cli as site owner:
sudo -u $SITE_OWNER $WP_CLI --path=$SITE_PATH
# Deploy to all servers (parallel):
sqlite3 ~/.rc/rc.db "SELECT hostname, ssh_port FROM servers;" | while IFS='|' read -r host port; do
(ssh -p "$port" -o ConnectTimeout=5 "root@$host" \
"cd /root/runcloud-bash-scripts && git checkout -- . 2>/dev/null; git pull --ff-only && chmod +x *.sh") &
done; waitIn runcloud-go/internal/web/server.go, use {name} and {path} placeholders (NOT %s):
"vuln-check": "bash /root/runcloud-bash-scripts/wp-vuln-check.sh --path={path} --include-core",- Syntax check:
bash -n script.sh - Test on a single server:
scp -P 2018 script.sh root@sg9.codetot.org:/root/test.sh && ssh -p 2018 root@sg9.codetot.org "bash /root/test.sh --site=vinhhoan" - Always test before merge+deploy
- Never hardcode
/home/runcloud/— use/home/*/webapps/glob or accept--path= fmt.Sprintfin Go eats%Ufromstat -c %U— use{name}/{path}placeholders onlygit checkout -- .beforegit pullon servers (filemode changes fromchmod +xblock pulls)- wp-cli may not be in PATH during cron — always search candidate paths