@@ -107,10 +107,10 @@ Parameters:
107107
108108 LatestAmiId :
109109 Type : AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
110- Default : /aws/service/ami-amazon-linux-latest/amzn2 -ami-hvm-x86_64-gp2
110+ Default : /aws/service/ami-amazon-linux-latest/al2023 -ami-kernel-default-x86_64
111111 LatestArmAmiId :
112112 Type : AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
113- Default : /aws/service/ami-amazon-linux-latest/amzn2 -ami-hvm-arm64-gp2
113+ Default : /aws/service/ami-amazon-linux-latest/al2023 -ami-kernel-default-arm64
114114
115115 MoodleLocale :
116116 Description : " The main language of the Moodle site, during initial configuration."
@@ -167,6 +167,7 @@ Conditions:
167167 - !Equals ["r6",!Select [0, !Split [ "g.", !Ref InstanceType]]]
168168
169169Resources :
170+ # ########################## TODO put this in the codepipeline template
170171 MoodleRepo :
171172 Type : AWS::CodeCommit::Repository
172173 Properties :
@@ -265,9 +266,6 @@ Resources:
265266 moodle_git_config :
266267 - moodle-git-config
267268 moodle-git-config :
268- packages :
269- yum :
270- git : []
271269 files :
272270 /tmp/appspec.yml :
273271 content : !Sub |
@@ -300,7 +298,6 @@ Resources:
300298 #!/bin/bash
301299 sudo systemctl start php-fpm
302300 sudo systemctl start httpd
303-
304301 mode : ' 000755'
305302 owner : root
306303 group : root
@@ -457,8 +454,8 @@ Resources:
457454 chown -R apache:apache /var/www/moodle/temp
458455 chown -R apache:apache /var/www/moodle/local
459456
460- availabilityzone=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone )
461- region=${!availabilityzone:0:-1}
457+ availabilityzone=$(ec2-metadata -z | awk '{print $2}' | sed 's/(.)//' )
458+ region=$(ec2-metadata -z | awk '{print $2}' | sed 's/[a-z]$//')
462459
463460 export EnvDatabaseType=$(aws ssm get-parameters --region $region --names /Moodle/${ProjectName}/DB/Type --query Parameters[0].Value)
464461 export EnvDatabaseType=`echo $EnvDatabaseType | sed -e 's/^"//' -e 's/"$//'`
@@ -494,7 +491,7 @@ Resources:
494491 export EnvElastiCacheEngine=$(aws ssm get-parameters --region $region --names /Moodle/${ProjectName}/Cache/session/Engine --query Parameters[0].Value)
495492 export EnvElastiCacheEngine=`echo $EnvElastiCacheEngine | sed -e 's/^"//' -e 's/"$//'`
496493
497- # setting up elasticache dependencies for cache
494+ # Setting up ElastiCache dependencies for cache
498495 if [ "$EnvIsMoodleSetupCompleted" != "No" ] && [ "$EnvElastiCacheClusterEndpointAddress" != "null" -a "$EnvElastiCacheClusterEndpointAddress" != "" ]; then
499496 sed -i "s/\$SessionEndpoint = .*/\$SessionEndpoint = '"$EnvElastiCacheClusterEndpointAddress"';/" /var/www/moodle/html/config.php
500497
@@ -504,154 +501,20 @@ Resources:
504501 # update Moodle source to use DYNAMIC_CLIENT_MODE so Moodle can detect changes to the elasticache cluster membership
505502 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
506503 fi
507-
508-
509504 else
510505 sed -i "s/\$SessionEndpoint = .*/\$SessionEndpoint = '';/" /var/www/moodle/html/config.php
511506 fi
512-
513- sudo systemctl restart php-fpm
514507 mode : 000500
515508 owner : root
516509 group : root
517-
518510 /tmp/before_install.sh :
519511 content :
520512 !Sub |
521513 # !/bin/bash -xe
522-
523- cd /opt/codedeploy-agent/deployment-root/$DEPLOYMENT_GROUP_ID/$DEPLOYMENT_ID/deployment-archive/.pipeline/
524-
525- availabilityzone=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
526- region=${!availabilityzone:0:-1}
527-
528- export EnvDatabaseType=$(aws ssm get-parameters --region $region --names /Moodle/${ProjectName}/DB/Type --query Parameters[0].Value)
529- export EnvDatabaseType=`echo $EnvDatabaseType | sed -e 's/^"//' -e 's/"$//'`
530-
531- if [ "$EnvDatabaseType" == "MySQL" ]; then
532- # Installing and configuring MYSQL libs.
533- sh install_mysql_dependencies.sh
534- else
535- # Installing and configuring PGSQL libs.
536- sh install_pgsql_dependencies.sh
537- fi
538-
539- # increasing PHP max_input_vars to 5000
540- sed -i 's/; max_input_vars.*/max_input_vars = 5000/' /etc/php.ini
541-
542- # Configuring OPCache
543- sh configure_opcache.sh
544-
545- # configuring Cache clients
546- sh install_cacheclient.sh
547-
548- # Setting up EFS shared file storage
549- sh setup_efs.sh
550- mode : 000500
551- owner : root
552- group : root
553- /tmp/setup_efs.sh :
554- content :
555- !Sub |
556- # !/bin/bash -xe
557-
558- availabilityzone=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
559- region=${!availabilityzone:0:-1}
560-
561- # Mount shared storage
562- if grep -qs '/var/www/moodle/data ' /proc/mounts; then
563- echo "/var/www/moodle/data is mounted."
564- else
565- export EnvElasticFileSystem=$(aws ssm get-parameters --region $region --names /Moodle/${ProjectName}/SharedFile/ElasticFileSystem --query Parameters[0].Value)
566- export EnvElasticFileSystem=`echo $EnvElasticFileSystem | sed -e 's/^"//' -e 's/"$//'`
567-
568- sudo mkdir -p /$EnvElasticFileSystem
569- sudo mountpoint -q /$EnvElasticFileSystem || sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 $EnvElasticFileSystem.efs.${AWS::Region}.amazonaws.com:/ /$EnvElasticFileSystem
570-
571- # Create directories for Moodle
572- sudo mkdir -p /$EnvElasticFileSystem/data
573- sudo mkdir -p /$EnvElasticFileSystem/cache
574- sudo mkdir -p /$EnvElasticFileSystem/temp
575-
576- chown apache:apache /$EnvElasticFileSystem/data/
577- chown apache:apache /$EnvElasticFileSystem/cache/
578- chown apache:apache /$EnvElasticFileSystem/temp/
579-
580- sudo umount -f /$EnvElasticFileSystem
581-
582- mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 $EnvElasticFileSystem.efs.${AWS::Region}.amazonaws.com:/data /var/www/moodle/data
583- # mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 $EnvElasticFileSystem.efs.${AWS::Region}.amazonaws.com:/cache /var/www/moodle/cache
584- # mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 $EnvElasticFileSystem.efs.${AWS::Region}.amazonaws.com:/temp /var/www/moodle/temp
585- fi
586- mode : 000500
587- owner : root
588- group : root
589- /tmp/install_pgsql_dependencies.sh :
590- content :
591- !Sub |
592- # !/bin/bash -xe
593- amazon-linux-extras install -y postgresql13
594- yum install -y php-pgsql
514+ echo "Nothing to do"
595515 mode : 000500
596516 owner : root
597517 group : root
598- /tmp/install_mysql_dependencies.sh :
599- content :
600- !Sub |
601- # !/bin/bash -xe
602-
603- amazon-linux-extras install -y mariadb10.5
604- yum install -y php-mysqlnd
605- mode : 000500
606- owner : root
607- group : root
608- /tmp/configure_opcache.sh :
609- content :
610- !Sub |
611- # !/bin/bash -xe
612- # create hidden opcache directory locally & change owner to apache
613- if [ ! -d /var/www/.opcache ]; then
614- mkdir -p /var/www/.opcache
615- fi
616- # Ensure opcache is enabled and add settings recomended by moodle at https://docs.moodle.org/34/en/OPcache
617- sed -i 's/;opcache.file_cache=.*/opcache.file_cache=\/var\/www\/.opcache/' /etc/php.d/10-opcache.ini
618- sed -i 's/opcache.memory_consumption=.*/opcache.memory_consumption=512/' /etc/php.d/10-opcache.ini
619- sed -i 's/opcache.max_accelerated_files=.*/opcache.max_accelerated_files=8000/' /etc/php.d/10-opcache.ini
620- sed -i 's/;opcache.revalidate_freq=.*/opcache.revalidate_freq=300/' /etc/php.d/10-opcache.ini
621- sed -i 's/;opcache.use_cwd=.*/opcache.use_cwd=1/' /etc/php.d/10-opcache.ini
622- sed -i 's/;opcache.validate_timestamps=.*/opcache.validate_timestamps=1/' /etc/php.d/10-opcache.ini
623- sed -i 's/;opcache.save_comments=.*/opcache.save_comments=1/' /etc/php.d/10-opcache.ini
624- sed -i 's/;opcache.enable_file_override=.*/opcache.enable_file_override=60/' /etc/php.d/10-opcache.ini
625- mode : 000500
626- owner : root
627- group : root
628- /tmp/install_cacheclient.sh :
629- content :
630- !Sub |
631- # !/bin/bash -xe
632-
633- # Install memcached and then remove it. Memcached is not actually needed. We install amazon-elasticache-cluster-client.so instead. However Moodle does not detect memcached is installed. Therefore, this tricks Moodle into thinking it is installed.
634- sudo yum install -y php-pecl-memcached
635- sudo yum remove -y php-pecl-memcached
636- sudo yum install -y php-redis
637- sudo yum install -y openssl11
638-
639- if [ $(uname -a | grep -c x86_64) == "1" ]; then
640- echo "downloading x86 client for ElastiCache"
641- wget -P /tmp/ https://elasticache-downloads.s3.amazonaws.com/ClusterClient/PHP-8.0/latest-64bit-X86-openssl1.1
642- tar -xf '/tmp/latest-64bit-X86-openssl1.1'
643- else
644- echo "downloading ARM-64 client for ElastiCache"
645- wget -P /tmp/ https://elasticache-downloads.s3.amazonaws.com/ClusterClient/PHP-8.0/latest-64bit-arm-openssl1.1
646- tar -xf '/tmp/latest-64bit-arm-openssl1.1'
647- fi
648-
649- cp 'amazon-elasticache-cluster-client.so' /usr/lib64/php/modules/
650- echo 'extension=amazon-elasticache-cluster-client.so;' > /etc/php.d/50-elasticache.ini
651- mode : 000500
652- owner : root
653- group : root
654-
655518 /tmp/moodle-git-config.sh :
656519 content : !Sub |
657520 #!/bin/bash -x
@@ -707,11 +570,11 @@ Resources:
707570 git push -u origin main
708571
709572 # get instance id
710- instance_id=$(curl -s http://169.254.169.254/latest/meta-data/instance-id )
573+ instance_id=$(ec2-metadata -i | awk '{print $2}' | sed 's/(.)//' )
711574
712575 # get region from instance meta-data
713- availabilityzone=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone )
714- region=${!availabilityzone:0:-1}
576+ availabilityzone=$(ec2-metadata -z | awk '{print $2}' | sed 's/(.)//' )
577+ region=$(ec2-metadata -z | awk '{print $2}' | sed 's/[a-z]$//')
715578
716579 # wait for Moodle setup to be completed
717580 echo "Start checking whether Moodle setup completed or not"
@@ -756,7 +619,6 @@ Resources:
756619 command : ./moodle-git-config.sh
757620 cwd : /tmp
758621 ignoreErrors : false
759-
760622 Properties :
761623 LaunchTemplateData :
762624 BlockDeviceMappings :
@@ -778,7 +640,7 @@ Resources:
778640 # !/bin/bash -xe
779641 sudo systemctl enable amazon-ssm-agent
780642 sudo systemctl start amazon-ssm-agent
781- sudo systemctl status amazon-ssm-agent
643+ dnf install -y git
782644
783645 /opt/aws/bin/cfn-init --configsets moodle_git_config --verbose --stack ${AWS::StackName} --resource PipelineHelperLaunchTemplate --region ${AWS::Region}
784646 /opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource PipelineHelperASGroup --region ${AWS::Region}
0 commit comments