Added Shell Scripts

main
Anthony 2024-09-18 23:44:48 +08:00
parent 6a3c181656
commit 07b92a1b36
10 changed files with 219 additions and 0 deletions

View File

@ -0,0 +1,7 @@
TTL_PUB=$(wp --path=/var/www/webroot/ROOT litespeed-option get cache-ttl_pub)
TTL_PRIV=$(wp --path=/var/www/webroot/ROOT litespeed-option get cache-ttl_priv)
TTL_FRONTPAGE=$(wp --path=/var/www/webroot/ROOT litespeed-option get cache-ttl_frontpage)
TTL_FEED=$(wp --path=/var/www/webroot/ROOT litespeed-option get cache-ttl_feed)
TTL_REST=$(wp --path=/var/www/webroot/ROOT litespeed-option get cache-ttl_rest)
echo "TTL Values:\nPublic: $TTL_PUB\nPrivate: $TTL_PRIV\nFrontpage: $TTL_FRONTPAGE\nFeed: $TTL_FEED\nREST: $TTL_REST"

View File

@ -0,0 +1,25 @@
#!/bin/bash
# Check for correct number of arguments
if [ "$#" -ne 4 ]; then
echo "Usage: $0 TTL_PUB TTL_PRIV TTL_FRONTPAGE TTL_FEED"
exit 1
fi
# Assigning input parameters to variables
TTL_PUB=$1
TTL_PRIV=$2
TTL_FRONTPAGE=$3
TTL_FEED=$4
# CD into WordPress directory
cd /var/www/webroot/ROOT
# Run wp-cli
wp litespeed-option set cache-ttl_pub "$TTL_PUB"
wp litespeed-option set cache-ttl_priv "$TTL_PRIV"
wp litespeed-option set cache-ttl_frontpage "$TTL_FRONTPAGE"
wp litespeed-option set cache-ttl_feed "$TTL_FEED"
echo "Cache settings updated successfully."

View File

@ -0,0 +1,15 @@
#!/bin/bash
# Function to check if relay is installed
check_relay_installed() {
# Checking if the relay extension is present in the PHP modules
if php -m | grep -q relay; then
echo "Relay/Object Cache Pro is installed."
else
echo "Relay/Object Cache Pro is not installed."
fi
}
# Execute the check
check_relay_installed
exit 0

View File

@ -0,0 +1,7 @@
#!/bin/bash
if php -m | grep -q relay; then
echo "Relay is enabled"
else
echo "Relay is disabled"
fi

View File

@ -0,0 +1,18 @@
#!/bin/bash
# Disable Relay in PHP configuration
RELAY_INI_FILE=$(php-config --ini-dir)/60-relay.ini
if [ -f "$RELAY_INI_FILE" ]; then
# Ensure only uncommented 'extension = relay.so' lines are commented out
# Handle optional spaces around '='
sed -i '/^extension\s*=\s*relay.so/ s/^/;/' $RELAY_INI_FILE
echo "Relay disabled in PHP configuration."
else
echo "Relay configuration file not found."
exit 1
fi
# Restart LiteSpeed server
sudo service lsws restart
echo "LiteSpeed server restarted."

View File

@ -0,0 +1,17 @@
#!/bin/bash
# Enable Relay in PHP configuration
RELAY_INI_FILE=$(php-config --ini-dir)/60-relay.ini
if [ -f "$RELAY_INI_FILE" ]; then
# Handle optional spaces around '=' and ensure only commented 'extension = relay.so' lines are uncommented
sed -i 's/^;\s*extension\s*=\s*relay.so/extension=relay.so/' $RELAY_INI_FILE
echo "Relay enabled in PHP configuration."
else
echo "Relay configuration file not found."
exit 1
fi
# Restart LiteSpeed server
sudo service lsws restart
echo "LiteSpeed server restarted."

View File

@ -0,0 +1,23 @@
#!/bin/bash
# Directory where your WordPress is installed
WP_DIR="/var/www/webroot/ROOT"
# Path to the Unix socket file for Redis
REDIS_SOCKET="/var/run/redis/redis.sock"
echo "Flushing caches..."
# Change to the WordPress directory
cd "$WP_DIR"
# Flush Object Cache Pro Cache via WP CLI
echo "Flushing Object Cache Pro cache..."
wp redis flush --path="$WP_DIR"
# Flush Relay Cache via Redis
# Since Relay uses Redis, flushing Redis should also clear the Relay cache
echo "Flushing Relay and Redis cache..."
redis-cli -s "$REDIS_SOCKET" FLUSHALL
echo "All caches have been flushed successfully."

View File

@ -0,0 +1,68 @@
#!/bin/bash
set -e
# Commands that require root permissions
sudo su <<'ROOT_BLOCK'
yum install -y openssl11
yum install -y lsphp-pecl-msgpack
# Other root commands here...
ROOT_BLOCK
# Determine PHP version and directories
LSPHP=$(php-config --version | cut -c -3)
LSPHP="${LSPHP//./}"
RELAY_PHP=$(php-config --version | cut -c -3)
RELAY_INI_DIR=$(php-config --ini-dir)
RELAY_EXT_DIR=$(php-config --extension-dir)
RELAY_VERSION=$(curl -fs https://builds.r2.relay.so/meta/latest)
RELAY_ARCH=$(arch | sed -e 's/arm64/aarch64/;s/amd64\|x86_64/x86-64/')
# Install Relay (requires root)
sudo curl -L "https://builds.r2.relay.so/$RELAY_VERSION/relay-$RELAY_VERSION-php$RELAY_PHP-centos7-$RELAY_ARCH.tar.gz" | tar xz -C /tmp
sudo cp "/tmp/relay-$RELAY_VERSION-php$RELAY_PHP-centos7-$RELAY_ARCH/relay.ini" "$RELAY_INI_DIR/60-relay.ini"
sudo cp "/tmp/relay-$RELAY_VERSION-php$RELAY_PHP-centos7-$RELAY_ARCH/relay-pkg.so" "$RELAY_EXT_DIR/relay.so"
echo "extension = msgpack.so" | sudo tee "$RELAY_INI_DIR/50-msgpack.ini" > /dev/null
# Configure Relay (requires root)
sudo sed -i 's/^;\? \?relay.maxmemory =.*/relay.maxmemory = 128M/' $RELAY_INI_DIR/60-relay.ini
sudo sed -i 's/^;\? \?relay.eviction_policy =.*/relay.eviction_policy = lru/' $RELAY_INI_DIR/60-relay.ini
sudo sed -i 's/^;\? \?relay.environment =.*/relay.environment = production/' $RELAY_INI_DIR/60-relay.ini
sudo sed -i "s/^;\? \?relay.key =.*/relay.key = SJR3-5IHD-CKMYLH-YJRQSY2-8443KZZ-V2LAS6/" $RELAY_INI_DIR/60-relay.ini
sudo sed -i "s/00000000-0000-0000-0000-000000000000/$(cat /proc/sys/kernel/random/uuid)/" "$RELAY_EXT_DIR/relay.so"
# Install Object Cache Pro in WordPress (do not run as root)
cd /var/www/webroot/ROOT
wp plugin install 'https://objectcache.pro/plugin/object-cache-pro.zip?token=091801712a649241ca11668fdf19552c2d13dad4d9b1d28848c276cd5111' --force --activate
# Configure Object Cache Pro
ocp_config="[
'token' => '091801712a649241ca11668fdf19552c2d13dad4d9b1d28848c276cd5111',
'host' => '127.0.0.1',
'port' => 6379,
'client' => 'relay',
'database' => 0,
'prefix' => 'db0',
'shared' => false,
'compression' => 'zstd',
'serializer' => 'igbinary',
'prefetch' => false,
'split_alloptions' => false,
'timeout' => 0.5,
'read_timeout' => 0.5,
'retries' => 3,
'backoff' => 'smart',
'debug' => false,
'save_commands' => false,
]"
wp config set WP_REDIS_CONFIG "$ocp_config" --raw
wp config set WP_REDIS_DISABLED false --raw
wp redis enable --force
wp redis flush
# Restart LiteSpeed server (requires root)
sudo service lsws restart
echo "Relay and Object Cache Pro installation and configuration are complete."

View File

@ -0,0 +1,26 @@
#!/bin/bash
# Deactivate and uninstall Object Cache Pro from WordPress
cd /var/www/webroot/ROOT
wp plugin deactivate object-cache-pro
wp plugin uninstall object-cache-pro
# Optionally, if you want to re-enable LiteSpeed Cache settings
# wp litespeed-option set object 1 # Enables LiteSpeed Cache if it was disabled previously
# Path to the PHP extension directory and ini file for Relay
RELAY_INI_DIR=$(php-config --ini-dir)
RELAY_EXT_DIR=$(php-config --extension-dir)
RELAY_INI_FILE="$RELAY_INI_DIR/60-relay.ini"
RELAY_SO_FILE="$RELAY_EXT_DIR/relay.so"
# Remove the Relay configuration file and extension
sudo rm -f "$RELAY_INI_FILE"
sudo rm -f "$RELAY_SO_FILE"
# Restart the web server to apply changes
sudo service lsws restart
# Confirmation message
echo "Relay/Object Cache Pro and related configurations have been uninstalled."

View File

@ -0,0 +1,13 @@
#!/bin/bash
OP_INI='/usr/local/lsws/lsphp/etc/php.d/10-opcache.ini'
MEM_CONS=$1
INT_BUF=$2
MAX_FILES=$3
REVAL_FREQ=$4
# Use direct values instead of variable expansion in sed
sed -i -e "s/opcache.memory_consumption=.*/opcache.memory_consumption=$MEM_CONS/" $OP_INI
sed -i -e "s/opcache.interned_strings_buffer=.*/opcache.interned_strings_buffer=$INT_BUF/" $OP_INI
sed -i -e "s/opcache.max_accelerated_files=.*/opcache.max_accelerated_files=$MAX_FILES/" $OP_INI
sed -i -e "s/opcache.revalidate_freq=.*/opcache.revalidate_freq=$REVAL_FREQ/" $OP_INI