Skip to content

Commit

Permalink
Merge pull request #56 from aws-samples/hotpatch-redis-errors
Browse files Browse the repository at this point in the history
Fix Redis and Memcached driver installation errors
  • Loading branch information
vrioux authored Jan 30, 2024
2 parents dad4d0f + c57880a commit 77206ae
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
12 changes: 6 additions & 6 deletions templates/03-pipelinehelper.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ Resources:
#This bucket is being used for storing Code artifacts for deployment.
CodeArtifactS3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Join ['-', [!Sub 'moodle-code', !Select [4, !Split ['-', !Select [2, !Split ['/', !Ref AWS::StackId]]]]]]
DeletionPolicy: RetainExceptOnCreate

InstanceProfile:
Type: AWS::IAM::InstanceProfile
Expand Down Expand Up @@ -486,7 +485,7 @@ Resources:
export EnvIsMoodleSetupCompleted=`echo $EnvIsMoodleSetupCompleted | sed -e 's/^"//' -e 's/"$//'`

export EnvElastiCacheClusterEndpointAddress=$(aws ssm get-parameters --region $region --names /Moodle/${ProjectName}/Cache/session/ElastiCacheClusterEndpoint --query Parameters[0].Value)
export EnvElastiCacheClusterEndpointAddress=`echo $EnvElastiCacheClusterEndpointAddress | sed -e 's/^"//' -e 's/"$//'`
export EnvElastiCacheClusterEndpointAddress=`echo $EnvElastiCacheClusterEndpointAddress | sed -e 's/^"//' -e 's/"$//' | cut -f1 -d":"`

export EnvElastiCacheEngine=$(aws ssm get-parameters --region $region --names /Moodle/${ProjectName}/Cache/session/Engine --query Parameters[0].Value)
export EnvElastiCacheEngine=`echo $EnvElastiCacheEngine | sed -e 's/^"//' -e 's/"$//'`
Expand All @@ -495,11 +494,12 @@ Resources:
if [ "$EnvIsMoodleSetupCompleted" != "No" ] && [ "$EnvElastiCacheClusterEndpointAddress" != "null" -a "$EnvElastiCacheClusterEndpointAddress" != "" ]; then
sed -i "s/\$SessionEndpoint = .*/\$SessionEndpoint = '"$EnvElastiCacheClusterEndpointAddress"';/" /var/www/moodle/html/config.php

if [ "$EnvElastiCacheEngine" == "Redis"]; then
if [ "$EnvElastiCacheEngine" == "Redis" ]; then
sed -i "s/\$SessionsCacheType = .*/\$SessionsCacheType = '"$EnvElastiCacheEngine"';/" /var/www/moodle/html/config.php
else
#else
# Below commented out because we don't use the ElastiCache client anymore
#update Moodle source to use DYNAMIC_CLIENT_MODE so Moodle can detect changes to the elasticache cluster membership
sed -i '/\$this->options\[Memcached::OPT_BUFFER_WRITES\] = \$bufferwrites;/a \ \ \ \ \ \ \ \ $this->options[Memcached::OPT_CLIENT_MODE] = Memcached::DYNAMIC_CLIENT_MODE;' /var/www/moodle/html/cache/stores/memcached/lib.php
#sed -i '/\$this->options\[Memcached::OPT_BUFFER_WRITES\] = \$bufferwrites;/a \ \ \ \ \ \ \ \ $this->options[Memcached::OPT_CLIENT_MODE] = Memcached::DYNAMIC_CLIENT_MODE;' /var/www/moodle/html/cache/stores/memcached/lib.php
fi
else
sed -i "s/\$SessionEndpoint = .*/\$SessionEndpoint = '';/" /var/www/moodle/html/config.php
Expand Down
43 changes: 31 additions & 12 deletions templates/04-web.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,22 @@ Resources:
pecl install -f libsodium
echo "extension=sodium.so;" > /etc/php.d/50-sodium.ini
# Install Redis client as well as related extensions - see here https://github.com/amazonlinux/amazon-linux-2023/issues/328
pear update-channels
pecl update-channels
/usr/bin/yes 'no' | pecl install igbinary
echo 'extension=igbinary.so' > /etc/php.d/30-igbinary.ini
/usr/bin/yes 'no' | pecl install msgpack
echo 'extension=msgpack.so' > /etc/php.d/30-msgpack.ini
dnf install -q -y libzstd-devel
/usr/bin/yes 'no' | pecl install zstd
echo 'extension=zstd.so' > /etc/php.d/40-zstd.ini
/usr/bin/yes 'no' | pecl install --configureoptions 'enable-lzf-better-compression="no"' lzf
echo 'extension=lzf.so' > /etc/php.d/40-lzf.ini
dnf install -q -y redis6-devel lz4-devel
/usr/bin/yes 'no' | pecl install --configureoptions 'enable-redis-igbinary="yes" enable-redis-lzf="yes" enable-redis-zstd="yes" enable-redis-msgpack="yes" enable-redis-lz4="yes" with-liblz4="yes"' redis
echo 'extension=redis.so' > /etc/php.d/41-redis.ini
# Adjust base php.ini
sed -i 's/memory_limit =.*/memory_limit = 4096M/' /etc/php.ini
sed -i 's/;max_input_vars.*/max_input_vars = 5000/' /etc/php.ini
Expand Down Expand Up @@ -484,21 +500,24 @@ Resources:
sed -i 's/;opcache.use_cwd=.*/opcache.use_cwd=1/' /etc/php.d/10-opcache.ini
sed -i 's/;opcache.validate_timestamps=.*/opcache.validate_timestamps=1/' /etc/php.d/10-opcache.ini
sed -i 's/;opcache.save_comments=.*/opcache.save_comments=1/' /etc/php.d/10-opcache.ini
sed -i 's/;opcache.enable_file_override=.*/opcache.enable_file_override=60/' /etc/php.d/10-opcache.ini
sed -i 's/;opcache.file_cache_only=.*/opcache.file_cache_only=1/' /etc/php.d/10-opcache.ini
# Install ElastiCache client
if [ $(uname -a | grep -c x86_64) == "1" ]; then
echo "downloading x86 client for ElastiCache"
wget -P /tmp/ https://elasticache-downloads.s3.amazonaws.com/ClusterClient/PHP-8.1/latest-64bit-X86-openssl3
tar -xf '/tmp/latest-64bit-X86-openssl3'
else
echo "downloading ARM-64 client for ElastiCache"
wget -P /tmp/ https://elasticache-downloads.s3.amazonaws.com/ClusterClient/PHP-8.2/latest-64bit-arm-X86-openssl3
tar -xf '/tmp/latest-64bit-arm-X86-openssl3'
fi
mv amazon-elasticache-cluster-client.so /usr/lib64/php/modules/
echo 'extension=amazon-elasticache-cluster-client.so;' > /etc/php.d/50-elasticache.ini
#if [ $(uname -a | grep -c x86_64) == "1" ]; then
# echo "downloading x86 client for ElastiCache"
# wget -P /tmp/ https://elasticache-downloads.s3.amazonaws.com/ClusterClient/PHP-8.1/latest-64bit-X86-openssl3
# tar -xf '/tmp/latest-64bit-X86-openssl3'
#else
# echo "downloading ARM-64 client for ElastiCache"
# wget -P /tmp/ https://elasticache-downloads.s3.amazonaws.com/ClusterClient/PHP-8.2/latest-64bit-arm-X86-openssl3
# tar -xf '/tmp/latest-64bit-arm-X86-openssl3'
#fi
#mv amazon-elasticache-cluster-client.so /usr/lib64/php/modules/
#echo 'extension=amazon-elasticache-cluster-client.so;' > /etc/php.d/50-elasticache.ini
# Install Memcached client - note that ElastiCache client is failing on AL2023
dnf install libmemcached libmemcached-devel -y -q
/usr/bin/yes 'no' | pecl install memcached
echo 'extension=memcached.so' > /etc/php.d/41-memcached.ini
# Mount EFS
availabilityzone=$(ec2-metadata -z | awk '{print $2}' | sed 's/(.)//')
Expand Down

0 comments on commit 77206ae

Please sign in to comment.