44# Copyright (C) 2013-present admin@magenx.com #
55# All rights reserved. #
66# =================================================================================#
7+ _TIMER_USER_DATA_START=" $( date -R) "
78
89INSTANCE_LOCAL_IP=$( curl -s http://169.254.169.254/latest/meta-data/local-ipv4)
910
@@ -12,6 +13,8 @@ apt-get update
1213apt-get -qqy install ${EXTRA_PACKAGES_DEB}
1314pip3 install git-remote-codecommit
1415
16+ _TIMER_USER_DATA_APT=" $( date -R) "
17+
1518# # create user
1619useradd -d /home/${BRAND} -s /sbin/nologin ${BRAND}
1720# # create root php user
@@ -25,7 +28,7 @@ chown -R ${BRAND}:${PHP_USER} ${WEB_ROOT_PATH} /home/${BRAND}/{.config,.cache,.l
2528chmod 2770 ${WEB_ROOT_PATH}
2629setfacl -R -m u:${BRAND} :rwX,g:${PHP_USER} :r-X,o::-,d:u:${BRAND} :rwX,d:g:${PHP_USER} :r-X,d:o::- ${WEB_ROOT_PATH}
2730cd ${WEB_ROOT_PATH}
28- su ${BRAND} -s /bin/bash -c " git clone -b main ${CODECOMMIT_APP_REPO} ."
31+ su ${BRAND} -s /bin/bash -c " git clone -b %{ if " ${INSTANCE_NAME} " != " staging " } main%{ else }staging%{ endif } ${CODECOMMIT_APP_REPO} ."
2932echo " ${EFS_DNS_TARGET} :/%{ if " ${INSTANCE_NAME} " != " staging" }production%{ else }staging%{ endif }/var ${WEB_ROOT_PATH} /var nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,_netdev 0 0" >> /etc/fstab
3033echo " ${EFS_DNS_TARGET} :/%{ if " ${INSTANCE_NAME} " != " staging" }production%{ else }staging%{ endif }/pub/media ${WEB_ROOT_PATH} /pub/media nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,_netdev 0 0" >> /etc/fstab
3134su ${BRAND} -s /bin/bash -c " mkdir -p {pub/media,var}"
@@ -41,6 +44,8 @@ umount /mnt/efs
4144mount -a
4245fi
4346
47+ _TIMER_USER_DATA_MOUNT=" $( date -R) "
48+
4449chmod 2770 pub/media var
4550chmod +x bin/magento
4651
@@ -61,6 +66,9 @@ debconf-set-selections <<< "phpmyadmin phpmyadmin/dbconfig-install boolean false
6166
6267apt-get -qq update -o Dir::Etc::sourcelist=" sources.list.d/nginx.list" -o Dir::Etc::sourceparts=" -" -o APT::Get::List-Cleanup=" 0"
6368apt-get -qq update -o Dir::Etc::sourcelist=" sources.list.d/php.list" -o Dir::Etc::sourceparts=" -" -o APT::Get::List-Cleanup=" 0"
69+
70+ _TIMER_USER_DATA_LEMP_REPO=" $( date -R) "
71+
6472apt-get -qqy install %{ if " ${INSTANCE_NAME} " == " admin" }composer mariadb-client phpmyadmin%{ endif } nginx php-pear php${PHP_VERSION} %{ for PHP_PKG in split(" " , " ${PHP_PACKAGES_DEB} " ) ~ } php${PHP_VERSION} -${PHP_PKG} %{ endfor }
6573
6674cat > /etc/sysctl.conf << END
@@ -141,7 +149,7 @@ sed -i 's/^\(memory_limit = \)[0-9]*M/\1%{ if "${INSTANCE_NAME}" == "admin" }204
141149sed -i ' s/^\(post_max_size = \)[0-9]*M/\164M/' ${PHP_INI}
142150sed -i ' s/^\(upload_max_filesize = \)[0-9]*M/\132M/' ${PHP_INI}
143151sed -i ' s/expose_php = On/expose_php = Off/' ${PHP_INI}
144- sed -i ' s/;realpath_cache_size =.*/realpath_cache_size = 10M /' ${PHP_INI}
152+ sed -i ' s/;realpath_cache_size =.*/realpath_cache_size = 5M /' ${PHP_INI}
145153sed -i ' s/;realpath_cache_ttl =.*/realpath_cache_ttl = 86400/' ${PHP_INI}
146154sed -i ' s/short_open_tag = Off/short_open_tag = On/' ${PHP_INI}
147155sed -i ' s/;max_input_vars =.*/max_input_vars = 50000/' ${PHP_INI}
177185echo " ${WEB_ROOT_PATH} /app/etc/env.php" >> /etc/opcache-default.blacklist
178186echo " ${WEB_ROOT_PATH} /app/etc/config.php" >> /etc/opcache-default.blacklist
179187
188+ _TIMER_USER_DATA_LEMP_INSTALLED=" $( date -R) "
189+
180190cd /etc/nginx
181191git init
182192git remote add origin ${CODECOMMIT_SERVICES_REPO}
@@ -207,6 +217,8 @@ systemctl daemon-reload
207217systemctl restart nginx.service
208218systemctl restart php* fpm.service
209219
220+ _TIMER_USER_DATA_LEMP_READY=" $( date -R) "
221+
210222hostnamectl set-hostname server.${DOMAIN} --static
211223timedatectl set-timezone ${TIMEZONE}
212224
@@ -220,3 +232,20 @@ dpkg -i amazon-cloudwatch-agent.deb
220232/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c ssm:amazon-cloudwatch-agent-${INSTANCE_NAME} .json
221233
222234chmod 750 /usr/bin/aws
235+
236+ _TIMER_USER_DATA_END=" $( date -R) "
237+
238+ cat > /tmp/timer_user_data_log << END
239+ Instance uptime: $( uptime -s)
240+ User data timer start: $$ {_TIMER_USER_DATA_START}
241+ Command apt-get update: $$ {_TIMER_USER_DATA_APT}
242+ useradd, git, mount ready: $$ {_TIMER_USER_DATA_MOUNT}
243+ LEMP repository ready: $$ {_TIMER_USER_DATA_LEMP_REPO}
244+ LEMP webstack installed: $$ {_TIMER_USER_DATA_LEMP_INSTALLED}
245+ LEMP webstack config ready: $$ {_TIMER_USER_DATA_LEMP_READY}
246+ User data timer end: $$ {_TIMER_USER_DATA_END}
247+
248+ Timer report ready: $( date -R)
249+ END
250+
251+ aws sns publish --topic-arn " ${SNS_TOPIC_ARN} " --message file:///tmp/timer_user_data_log
0 commit comments