acantril / learn-cantrill-io-labs

Standard and Advanced Demos for learn.cantrill.io courses

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update for Advanced Demo - Web App - Single Server to Elastic Evolution - STAGE 2

eliezerchavez opened this issue · comments

In section https://github.com/acantril/learn-cantrill-io-labs/blob/master/aws-elastic-wordpress-evolution/02_LABINSTRUCTIONS/STAGE2%20-%20Automate%20the%20build%20using%20a%20Launch%20Template.md#stage-2a---create-the-launch-template
Change:
Under T2/T3 Unlimited select Enable
for:
Under Credit specification select Unlimited

image

Suggested change for section https://github.com/acantril/learn-cantrill-io-labs/blob/master/aws-elastic-wordpress-evolution/02_LABINSTRUCTIONS/STAGE2%20-%20Automate%20the%20build%20using%20a%20Launch%20Template.md#stage-2b---add-userdata

#!/bin/bash

DBPassword=$(aws ssm get-parameters --region us-east-1 --names /A4L/Wordpress/DBPassword --with-decryption --query Parameters[0].Value | tr -d \")
DBRootPassword=$(aws ssm get-parameters --region us-east-1 --names /A4L/Wordpress/DBRootPassword --with-decryption --query Parameters[0].Value | tr -d \" | tr -d \")
DBUser=$(aws ssm get-parameters --region us-east-1 --names /A4L/Wordpress/DBUser --query Parameters[0].Value | tr -d \")
DBName=$(aws ssm get-parameters --region us-east-1 --names /A4L/Wordpress/DBName --query Parameters[0].Value | tr -d \")
DBEndpoint=$(aws ssm get-parameters --region us-east-1 --names /A4L/Wordpress/DBEndpoint --query Parameters[0].Value | tr -d \")

yum -y update

yum install -y mariadb-server httpd
amazon-linux-extras install -y lamp-mariadb10.2-php7.2 php7.2
amazon-linux-extras install -y epel
yum install -y stress

systemctl enable httpd
systemctl enable mariadb
systemctl start httpd
systemctl start mariadb

mysqladmin -u root password $DBRootPassword

cd /var/www/html
curl -sL http://wordpress.org/latest.tar.gz | tar -zxvf -
cp -frv wordpress/* .
rm -fr wordpress/ latest.tar.gz

cp ./wp-config-sample.php ./wp-config.php
sed -i -e "s/'database_name_here'/'$DBName'/g" -e "s/'username_here'/'$DBUser'/g" -e "s/'password_here'/'$DBPassword'/g" -e "s/'localhost'/'$DBEndpoint'/g" wp-config.php


usermod -a -G apache ec2-user   
chown -R ec2-user:apache /var/www
chmod 2775 /var/www
find /var/www -type d -exec chmod 2775 {} \;
find /var/www -type f -exec chmod 0664 {} \;

cat <<EOF | mysql -u root --password=$DBRootPassword
CREATE DATABASE $DBName;
CREATE USER '$DBUser'@'localhost' IDENTIFIED BY '$DBPassword';
GRANT ALL ON $DBName.* TO '$DBUser'@'localhost';
FLUSH PRIVILEGES;
EOF

reviewing the user data changes.

the solution suggested by @eliezerchavez works
the script that you provided @acantril for some reason do not work as expected

hi, it does work fine, i've just tested it. @herrmadbeef
I suspect you made a mistake and changing to this new script fixed it because you did another run through.

I tested several Times !
I used the script provided b @eliezerchavez

when I used yours I always got the following error

image

The scripts do the same thing ... it's just a more efficient way of doing it @herrmadbeef
But to repeat again, i've just tested it with my script and confirmed it works ok.
There are also no other reports of any issues.

@acantril
same Launch template
the only difference is this

Failed

#!/bin/bash -xe

Working

#!/bin/bash

I can show you the error and the change if you want
OR
I can create a branch with just with the change

Ok you keep saying "failed"
I've tested it, it's working fine
i've asked a few students to test, it's working fine.
Trust me, you had a typo of some kind or some other issue
the -xe does nothing which could cause this to fail.

if you want to see what the issue is
try with my script
connect to the instance
then look at the cloud-init logs and see where the failure is.
this will tell you what the issue is.

Failed to connect to database either means the database server is not running
it isn't installed
or the password you chose isn't the one i suggested and is causing issues.