File: //init-scripts/enable_redis.sh
#!/usr/bin/env bash
if [ -z $REDIS_ENABLED ]; then
export REDIS_ENABLED='no'
fi
cd /var/www/html
while(true); do
if nc -z localhost 80; then
echo "Server Started .. proceeding"
break
else
echo "Server not yet started ... waiting ..."
sleep 5s
fi
done
if [ $REDIS_ENABLED == 'yes' ]; then
echo "Waiting until wordpress is available before trying to enable redis cache";
while ! nc -z localhost 80; do
echo "Waiting until wordpress is available before trying to enable redis cache";
sleep 1;
done;
echo "Checking if redis-cache plugin is installed and active."
if [ -f /var/www/html/wp-content/object-cache.php ]; then
echo "redis-cache plugin already enabled."
else
wp redis enable --allow-root;
if [ $? -ne 0 ]; then
echo "Error enabling Redis cache ... TERMINATING!"
exit 1
fi
echo "Redis Enabled successfully"
fi
else
echo "Disabling Redis"
if [ -f /var/www/html/wp-content/object-cache.php ]; then
wp redis disable --allow-root
if [ $? -ne 0 ]; then
echo "Error enabling Redis cache ... TERMINATING!"
exit 1
fi
else
echo "Redis is already disabled"
fi
fi