fix: WP-CLI path detection - prioritize /usr/local/bin/wp, fix sudo -u path loss across all scripts
parent
4c54fa106f
commit
20af8ad386
|
|
@ -314,15 +314,20 @@ step_wp_object_cache() {
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Guard: WP-CLI available
|
# Guard: WP-CLI available — resolve full path so sudo -u retains it
|
||||||
if ! command -v wp >/dev/null 2>&1; then
|
local wp_bin
|
||||||
warning "WP-CLI not found — skipping WP object cache config. Install WP-CLI first."
|
for _wp in "/usr/local/bin/wp" "/usr/bin/wp" "/home/litespeed/bin/wp"; do
|
||||||
|
if [ -x "$_wp" ]; then wp_bin="$_wp"; break; fi
|
||||||
|
done
|
||||||
|
[ -z "${wp_bin:-}" ] && wp_bin=$(command -v wp 2>/dev/null || echo "")
|
||||||
|
if [ -z "${wp_bin:-}" ]; then
|
||||||
|
warning "WP-CLI not found — skipping WP object cache config. Expected at /usr/local/bin/wp"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Guard: LiteSpeed Cache plugin active (run as litespeed to get correct WP context)
|
# Guard: LiteSpeed Cache plugin active (run as litespeed with full wp path)
|
||||||
local plugin_status
|
local plugin_status
|
||||||
plugin_status=$(sudo -u "$WEB_USER" -s wp plugin is-active litespeed-cache --path="$WP_ROOT" 2>/dev/null && echo "active" || echo "inactive")
|
plugin_status=$(sudo -u "$WEB_USER" "$wp_bin" plugin is-active litespeed-cache --path="$WP_ROOT" 2>/dev/null && echo "active" || echo "inactive")
|
||||||
if [[ "$plugin_status" != "active" ]]; then
|
if [[ "$plugin_status" != "active" ]]; then
|
||||||
warning "LiteSpeed Cache plugin is not active in WordPress — skipping object cache config."
|
warning "LiteSpeed Cache plugin is not active in WordPress — skipping object cache config."
|
||||||
warning "Activate it at: WordPress Admin > Plugins > LiteSpeed Cache"
|
warning "Activate it at: WordPress Admin > Plugins > LiteSpeed Cache"
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,17 @@
|
||||||
|
|
||||||
# Find WP-CLI location
|
# Find WP-CLI location
|
||||||
WP_CLI_PATH=""
|
WP_CLI_PATH=""
|
||||||
if [ -f "/home/litespeed/bin/wp" ]; then
|
for _wp_candidate in "/usr/local/bin/wp" "/usr/bin/wp" "/home/litespeed/bin/wp"; do
|
||||||
WP_CLI_PATH="/home/litespeed/bin/wp"
|
if [ -x "$_wp_candidate" ]; then
|
||||||
elif command -v wp >/dev/null 2>&1; then
|
WP_CLI_PATH="$_wp_candidate"
|
||||||
WP_CLI_PATH="wp"
|
break
|
||||||
else
|
fi
|
||||||
echo '{"error": "WP-CLI not found. Please ensure WP-CLI is installed and accessible."}'
|
done
|
||||||
|
if [ -z "$WP_CLI_PATH" ]; then
|
||||||
|
WP_CLI_PATH=$(command -v wp 2>/dev/null || echo "")
|
||||||
|
fi
|
||||||
|
if [ -z "$WP_CLI_PATH" ]; then
|
||||||
|
echo '{"error": "WP-CLI not found. Expected at /usr/local/bin/wp — run: which wp"}'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,19 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Check if WP-CLI is available
|
# Find WP-CLI binary
|
||||||
if [ ! -f "/home/litespeed/bin/wp" ]; then
|
WP_CLI_PATH=""
|
||||||
echo "WP-CLI not found"
|
for _wp in "/usr/local/bin/wp" "/usr/bin/wp" "/home/litespeed/bin/wp"; do
|
||||||
|
if [ -x "$_wp" ]; then WP_CLI_PATH="$_wp"; break; fi
|
||||||
|
done
|
||||||
|
[ -z "$WP_CLI_PATH" ] && WP_CLI_PATH=$(command -v wp 2>/dev/null || echo "")
|
||||||
|
if [ -z "$WP_CLI_PATH" ]; then
|
||||||
|
echo "WP-CLI not found. Expected at /usr/local/bin/wp"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Function to run WP-CLI commands
|
# Function to run WP-CLI commands
|
||||||
run_wp_command() {
|
run_wp_command() {
|
||||||
/home/litespeed/bin/wp --path=/var/www/webroot/ROOT "$@"
|
"$WP_CLI_PATH" --path=/var/www/webroot/ROOT "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check for correct number of arguments
|
# Check for correct number of arguments
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ function get_lsws_version() {
|
||||||
|
|
||||||
// Find WP-CLI binary
|
// Find WP-CLI binary
|
||||||
function find_wp_cli() {
|
function find_wp_cli() {
|
||||||
$candidates = ['/home/litespeed/bin/wp', '/usr/local/bin/wp', '/usr/bin/wp'];
|
$candidates = ['/usr/local/bin/wp', '/usr/bin/wp', '/home/litespeed/bin/wp'];
|
||||||
foreach ($candidates as $path) {
|
foreach ($candidates as $path) {
|
||||||
if (file_exists($path) && is_executable($path)) {
|
if (file_exists($path) && is_executable($path)) {
|
||||||
return $path;
|
return $path;
|
||||||
|
|
@ -118,7 +118,7 @@ function toggle_cache($enable = true) {
|
||||||
$wp_root = find_wp_root();
|
$wp_root = find_wp_root();
|
||||||
|
|
||||||
if (!$wp) {
|
if (!$wp) {
|
||||||
return ['ok' => false, 'error' => 'WP-CLI not found. Check /home/litespeed/bin/wp or /usr/local/bin/wp'];
|
return ['ok' => false, 'error' => 'WP-CLI not found. Expected at /usr/local/bin/wp — run: which wp'];
|
||||||
}
|
}
|
||||||
if (!$wp_root) {
|
if (!$wp_root) {
|
||||||
return ['ok' => false, 'error' => 'WordPress not found at /var/www/webroot/ROOT'];
|
return ['ok' => false, 'error' => 'WordPress not found at /var/www/webroot/ROOT'];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue