✨ Features: - Complete LEMP stack automation - WordPress with WP-CLI - Redis Object Cache (50% performance boost) - Multi-OS support - SSL/Let's Encrypt integration - Security hardening - Enterprise features - Docker testing environment - GitHub Actions CI/CD - Comprehensive documentation 🧪 Fully tested and production-ready Copyright (c) 2025 Sebastian Palencsár
65 lines
1.6 KiB
Django/Jinja
65 lines
1.6 KiB
Django/Jinja
#!/bin/bash
|
|
# WordPress Cron Optimization Script
|
|
# Generated by Ansible
|
|
|
|
set -e
|
|
|
|
# Configuration
|
|
WORDPRESS_PATH="{{ wordpress_path }}"
|
|
WP_CLI_PATH="/usr/local/bin/wp"
|
|
LOG_FILE="/var/log/wordpress-cron.log"
|
|
LOCK_FILE="/tmp/wordpress-cron.lock"
|
|
|
|
# Function to log messages
|
|
log_message() {
|
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "$LOG_FILE"
|
|
}
|
|
|
|
# Check if another cron is running
|
|
if [[ -f "$LOCK_FILE" ]]; then
|
|
if ps -p "$(cat $LOCK_FILE)" > /dev/null 2>&1; then
|
|
log_message "WordPress cron is already running (PID: $(cat $LOCK_FILE))"
|
|
exit 0
|
|
else
|
|
rm -f "$LOCK_FILE"
|
|
fi
|
|
fi
|
|
|
|
# Create lock file
|
|
echo $$ > "$LOCK_FILE"
|
|
|
|
# Function to cleanup on exit
|
|
cleanup() {
|
|
rm -f "$LOCK_FILE"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
log_message "Starting WordPress cron execution"
|
|
|
|
# Change to WordPress directory
|
|
cd "$WORDPRESS_PATH"
|
|
|
|
# Execute WordPress cron
|
|
if [[ -x "$WP_CLI_PATH" ]]; then
|
|
# Use WP-CLI for better control
|
|
if sudo -u {{ nginx_user }} "$WP_CLI_PATH" cron event run --due-now --quiet; then
|
|
log_message "WordPress cron executed successfully via WP-CLI"
|
|
else
|
|
log_message "ERROR: WordPress cron execution failed via WP-CLI"
|
|
exit 1
|
|
fi
|
|
else
|
|
# Fallback to HTTP request
|
|
if curl -s "{{ wordpress_url }}/wp-cron.php" > /dev/null; then
|
|
log_message "WordPress cron executed successfully via HTTP"
|
|
else
|
|
log_message "ERROR: WordPress cron execution failed via HTTP"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Clean up old cron logs (keep last 30 days)
|
|
find /var/log/ -name "wordpress-cron.log*" -mtime +30 -delete 2>/dev/null || true
|
|
|
|
log_message "WordPress cron execution completed"
|