🐚 Bash Toolkit · SysAdmin

RunCloud Bash Scripts

Bộ công cụ Bash production-grade cho sysadmin quản lý WordPress fleet trên RunCloud — migration, CVE scanning, security audit, permission fix, code freeze, my.cnf tuning, server metrics và self-update. Đã battle-tested trên 20+ server OpenLiteSpeed/Nginx, Ubuntu 20/22/24.

Battle-tested · 20+ servers Open Source Bash · Ubuntu 20/22/24

📋 Giới thiệu

RunCloud Bash Scripts là bộ công cụ dòng lệnh giúp tự động hóa toàn bộ công việc vận hành WordPress fleet trên RunCloud — những việc phải làm sau khi provisioning mà panel RunCloud không cover.

Vì sao cần toolkit này?

Panel RunCloud lo phần provisioning (tạo webapp, server, SSL). Nhưng công việc hằng ngày — migration giữa server, quét CVE, security audit, sửa permission, dọn disk, tune MySQL, code freeze sau launch — đều là thủ công. Toolkit này gói tất cả vào các script chạy một lệnh, đã được kiểm chứng trên hàng chục server production.

Tính năng chính

🚚

WP Migration

Migrate WordPress giữa các RunCloud server trong một lệnh — database, config, uploads, git submodules, staging URL.

🛡️

CVE Scanning

Quét plugin & theme WordPress theo CVE qua WPVulnerability.net API. Báo CVSS score và severity.

🔍

Security Audit

Phát hiện malware shells, file obfuscated, WP core integrity, cron hooks đáng ngờ, uploads audit.

🔒

Code Freeze

Khóa filesystem + admin capabilities sau launch. Ngăn cài plugin/theme, sửa file, quản lý user.

🧹

Disk Cleanup

Dọn LiteSpeed cache, swap files, journal logs, plugin caches. Hiển thị dung lượng trước/sau.

⚙️

my.cnf Tuning

Auto-tune MariaDB theo RAM/CPU server. Backup config, tự rollback nếu restart lỗi.

📊

Server Metrics

Thu thập CPU/RAM/disk/load + phát hiện WP updates. Gửi JSON qua webhook với HMAC-SHA256.

🔄

Self-Update

Một lệnh pull latest từ GitHub, tự chmod +x. Kết hợp cron để luôn cập nhật.

Yêu cầu hệ thống

  • OpenLiteSpeed hoặc Nginx
  • Ubuntu 20, 22 hoặc 24
  • RunCloud server (multi-user layout /home/*/webapps/)
  • python3curl (cho CVE scanning)
  • SSH key auth giữa các server (cho migration)

Cài đặt

# Login as root và clone repo
cd /root
git clone https://github.com/codetot-web/runcloud-bash-scripts.git
cd runcloud-bash-scripts
chmod +x *.sh

💻 Scripts Reference

Danh sách đầy đủ các script và cách sử dụng. Tất cả chạy từ thư mục repo sau khi clone.

Migration

wp-migration.sh

Full WordPress migration giữa các RunCloud server — database, config, uploads, git submodules, staging URL trong một lệnh.

# Setup SSH keys (lần đầu)
./wp-migration.sh [email protected] --setup-ssh

# Migrate site (cùng tên app)
./wp-migration.sh [email protected] myapp

# Migrate với staging URL
./wp-migration.sh [email protected] myapp --staging-url=http://myapp.example.temp-site.link

# Custom SSH port
./wp-migration.sh [email protected]:2222 myapp

wp-local-to-production.sh

Sync một WordPress site local (Mac) lên RunCloud production webapp.

./wp-local-to-production.sh runcloud@YOUR_SERVER "/path/to/local/site/app/public" \
  --production-url=http://example.temp-site.link

# Dry-run để xem kế hoạch trước khi chạy
./wp-local-to-production.sh runcloud@YOUR_SERVER "/path/to/local/site/app/public" myapp \
  --dry-run --production-url=http://example.temp-site.link

laravel-migration.sh

Full Laravel migration giữa các RunCloud server — đọc .env, sync storage + build assets, chạy composer install và artisan optimize.

# Setup SSH (lần đầu)
./laravel-migration.sh runcloud@YOUR_SERVER --setup-ssh

# Migrate với staging URL override
./laravel-migration.sh runcloud@YOUR_SERVER myapp \
  --staging-url=http://myapp.staging.temp-site.link

# Skip composer (vendor đã rsync sẵn)
./laravel-migration.sh runcloud@YOUR_SERVER myapp --skip-composer

Permissions & Ownership

fix-permission.sh / fix-permission-site.sh

Fix file ownership và permissions cho RunCloud web applications.

./fix-permission.sh
./fix-permission-site.sh myapp

chown-site.sh

Recursively chown webapp tree về www-data:www-data trong khi giữ nguyên wp-content/uploads.

./chown-site.sh --site=meatdeli
./chown-site.sh --site=meatdeli --user=ubuntu

wp-ownership-audit.sh

Quét webapp phát hiện file owned-by-root, wrong-user, và ACL deny entries gây lỗi âm thầm.

# Quick check (top-level dirs)
./wp-ownership-audit.sh --dirs-only

# Full deep scan
./wp-ownership-audit.sh

# Auto-fix ownership
./wp-ownership-audit.sh --fix

Bảo trì & Tối ưu

cleanup-disk.sh

Dọn disk: LiteSpeed caches, swap files, journal logs, WordPress plugin caches. Hiển thị dung lượng trước/sau.

# Clean tất cả webapps + system
./cleanup-disk.sh

# Clean một webapp cụ thể
./cleanup-disk.sh --site=myapp

# Preview trước khi xóa
./cleanup-disk.sh --dry-run

tweak-mycnf.sh

Auto-tune MariaDB/MySQL theo RAM và CPU server, tối ưu cho WordPress workload.

# Auto-detect và apply
./tweak-mycnf.sh

# Preview changes
./tweak-mycnf.sh --dry-run

# Show current settings
./tweak-mycnf.sh --status

# Restore config trước đó
./tweak-mycnf.sh --restore
SettingFormula
innodb_buffer_pool_size~50% tổng RAM
innodb_buffer_pool_instances1 per GB buffer pool (max 8)
tmp_table_size64M (<4G), 96M (4-7G), 128M (8G+)
innodb_io_capacity2000 (giả định SSD)
max_connections300 (không phải default 4096)
wait_timeout300s (không phải default 28800s)

install-ioncube.sh

Cài ioncube loader cho tất cả PHP versions.

./install-ioncube.sh

change-ssh-port.sh

Đổi SSH port mặc định.

./change-ssh-port.sh

WordPress Health & Updates

wp-health-check.sh

WordPress health auditor — probe từng site qua FPM/LSPHP binary thật (bỏ qua Cloudflare), bắt lỗi DB connection, plugin/theme fatal.

# Probe tất cả sites (chỉ hiện failures)
./wp-health-check.sh

# Probe một site
./wp-health-check.sh --site=myapp

# JSON output
./wp-health-check.sh --format=json

wp-git-cleanup.sh

Quét untracked git files, phân loại, commit theo nhóm hoặc report. Tự thêm production artifacts vào .gitignore.

# Scan tất cả sites (report only)
./wp-git-cleanup.sh --action=scan

# Cleanup một site
./wp-git-cleanup.sh --site=myapp --action=cleanup

# Preview
./wp-git-cleanup.sh --site=myapp --action=cleanup --dry-run

wp-freeze.sh

Khóa filesystem + admin capabilities sau launch. Giữ post publishing và media upload hoạt động.

# Freeze một site
./wp-freeze.sh --site=myapp --action=freeze

# Unfreeze trước maintenance window
./wp-freeze.sh --site=myapp --action=unfreeze

# Check status
./wp-freeze.sh --site=myapp --action=status

wp-vuln-check.sh

Quét plugin/theme theo CVE qua WPVulnerability.net API. Báo vulnerability name, CVE ID, CVSS score, severity.

# Check một site
./wp-vuln-check.sh --site=myapp

# Bao gồm WP core version check
./wp-vuln-check.sh --site=myapp --include-core

# JSON output cho automation
./wp-vuln-check.sh --site=myapp --json

wp-security-audit-installer.sh / wp-security-audit.sh

Cài và chạy WordPress security audits — phát hiện malware shells, file obfuscated, WP core integrity, suspicious cron hooks, uploads audit.

./wp-security-audit-installer.sh
./wp-security-audit.sh

Metrics & Maintenance

server-metrics.sh

Thu thập CPU, RAM, disk, load, uptime + phát hiện WP updates. Gửi JSON qua webhook với HMAC-SHA256 signing.

# Print metrics ra stdout
./server-metrics.sh --print

# Send tới webhook
WEBHOOK_URL=https://example.com/api/webhooks/server-metrics ./server-metrics.sh

# Send với HMAC-SHA256 auth
WEBHOOK_URL=https://example.com/api/webhooks/server-metrics \
WEBHOOK_SECRET=your-secret \
./server-metrics.sh

self-update.sh

Auto-update repo từ GitHub. Skip nếu đã up-to-date. Tự chmod +x sau update.

./self-update.sh

🔧 DevOps & Automation

Tích hợp toolkit vào cron jobs, CI/CD và quy trình vận hành hằng ngày.

Cron Jobs (chạy as root)

Thêm qua RunCloud Dashboard → Cron Job, hoặc crontab trực tiếp:

# Daily — clean tất cả webapp caches + system
0 0 * * *   /root/runcloud-bash-scripts/cleanup-disk.sh

# Weekly Sunday — system cleanup only
0 0 * * 0   /root/runcloud-bash-scripts/cleanup-disk.sh --system-only

# Daily 3:30 AM — self-update
30 3 * * * /root/runcloud-bash-scripts/self-update.sh >> /var/log/runcloud-bash-scripts-update.log 2>&1

# Every 5 minutes — send metrics to webhook
*/5 * * * * WEBHOOK_URL=https://example.com/webhook WEBHOOK_SECRET=your-secret /root/runcloud-bash-scripts/server-metrics.sh >> /var/log/server-metrics.log 2>&1

# Hourly — save metrics locally
0 * * * * /root/runcloud-bash-scripts/server-metrics.sh --print >> /var/log/server-metrics.json

Maintenance Window Workflow

Quy trình chuẩn khi update WordPress trên site đã freeze:

# 1. Unfreeze trước khi update
./wp-freeze.sh --site=myapp --action=unfreeze

# 2. Chạy updates (plugins, core, themes)
wp plugin update --all --path=/home/runcloud/webapps/myapp
wp core update --path=/home/runcloud/webapps/myapp

# 3. Re-freeze sau khi update
./wp-freeze.sh --site=myapp --action=freeze

HMAC-SHA256 Webhook Verification

Khi WEBHOOK_SECRET được set, server-metrics.sh gửi hai headers:

  • X-Webhook-Signature — HMAC-SHA256 của {timestamp}.{payload}
  • X-Webhook-Timestamp — Unix timestamp của request

Verify phía nhận bằng timing-safe comparison:

# PHP
hash_equals($expected, $signature);

# Python
hmac.compare_digest(expected, signature)

Tích hợp với runcloud-go

Toolkit này kết hợp với runcloud-go — Go dashboard Docker-deployed — để wire các script vào per-app actions trên toàn fleet, quản lý tập trung qua một dashboard.

🔒 Bảo mật

Bộ công cụ bao gồm nhiều lớp bảo mật cho WordPress fleet — từ quét CVE đến khóa site sau launch.

Layers bảo mật

🛡️

CVE Scanning

Quét plugin/theme/core theo CVE qua WPVulnerability.net. Báo CVSS score và severity.

🔍

Malware Detection

Security audit phát hiện malware shells, file obfuscated, WP core integrity, suspicious cron hooks.

🔒

Code Freeze

Khóa filesystem + admin capabilities sau launch. Ngăn cài plugin/theme, sửa file, quản lý user.

👤

Ownership Audit

Phát hiện root-owned files, wrong-user files, ACL deny entries gây lỗi và lỗ hổng bảo mật.

Code Freeze — Admin Capabilities

ActionWorks?
Create / edit / publish posts✅ Yes
Upload media✅ Yes
Install hoặc update plugins/themes❌ No
Edit theme/plugin files trong admin❌ No
Create / edit / delete users❌ No
WordPress auto-updates❌ No

Security Audit Scope

Fast pattern detection bao gồm:

  • Malware shells và backdoor patterns
  • File obfuscated (base64, eval, exec)
  • WordPress core integrity check
  • Suspicious cron hooks
  • Uploads directory audit

Ghi chú

ClamAV/rootkit deep scan đã được gỡ (2026-08-05) vì gây CPU load cao trên production. Audit hiện dựa trên fast pattern checks + LiteSoup WAF + Apache hardening.

Webhook Authentication

Server metrics gửi qua webhook được bảo vệ bằng HMAC-SHA256 signing — đảm bảo payload không bị giả mạo giữa đường.

❓ Câu hỏi thường gặp

Các câu hỏi phổ biến về RunCloud Bash Scripts.

Toolkit có miễn phí không?

Có. Hoàn toàn mã nguồn mở trên GitHub. Bạn chỉ cần clone về server và chmod +x.

Yêu cầu hệ thống gì?

OpenLiteSpeed/Nginx, Ubuntu 20/22/24, chạy như root. CVE scanning cần python3curl.

Toolkit có hỗ trợ multi-user layout không?

Có. Hầu hết script hỗ trợ layout /home/*/webapps/ — quét và quản lý tất cả user trên server, không chỉ runcloud.

cleanup-disk.sh có xóa dữ liệu quan trọng không?

Không. Chỉ dọn cache, swap files, journal logs — tất cả đều tự regenerate. Luôn dùng --dry-run để preview trước khi chạy thật.

wp-freeze.sh có chặn admin đăng bài không?

Không. Freeze chỉ chặn cài/update plugin/theme, sửa file, và quản lý user. Việc tạo/sửa/đăng bài và upload media vẫn hoạt động bình thường.

Làm sao để migrate site giữa 2 server?

Dùng wp-migration.sh. Cần SSH key auth từ source tới destination, database và user đã tồn tại trên destination (tạo qua RunCloud panel), và chạy như user runcloud trên source.

Toolkit có kết hợp với công cụ khác không?

Có. Kết hợp với runcloud-go — Go dashboard Docker-deployed — để wire các script vào per-app actions trên toàn fleet.