Skip to content

Commit d6b8ee1

Browse files
authored
Update admin
1 parent edc22e1 commit d6b8ee1

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

user_data/admin

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Copyright (C) 2013-present admin@magenx.com #
55
# All rights reserved. #
66
#=================================================================================#
7+
_TIMER_USER_DATA_START="$(date -R)"
78

89
INSTANCE_LOCAL_IP=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4)
910

@@ -12,6 +13,8 @@ apt-get update
1213
apt-get -qqy install ${EXTRA_PACKAGES_DEB}
1314
pip3 install git-remote-codecommit
1415

16+
_TIMER_USER_DATA_APT="$(date -R)"
17+
1518
## create user
1619
useradd -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
2528
chmod 2770 ${WEB_ROOT_PATH}
2629
setfacl -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}
2730
cd ${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} ."
2932
echo "${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
3033
echo "${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
3134
su ${BRAND} -s /bin/bash -c "mkdir -p {pub/media,var}"
@@ -41,6 +44,8 @@ umount /mnt/efs
4144
mount -a
4245
fi
4346

47+
_TIMER_USER_DATA_MOUNT="$(date -R)"
48+
4449
chmod 2770 pub/media var
4550
chmod +x bin/magento
4651

@@ -61,6 +66,9 @@ debconf-set-selections <<< "phpmyadmin phpmyadmin/dbconfig-install boolean false
6166

6267
apt-get -qq update -o Dir::Etc::sourcelist="sources.list.d/nginx.list" -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
6368
apt-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+
6472
apt-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

6674
cat > /etc/sysctl.conf <<END
@@ -141,7 +149,7 @@ sed -i 's/^\(memory_limit = \)[0-9]*M/\1%{ if "${INSTANCE_NAME}" == "admin" }204
141149
sed -i 's/^\(post_max_size = \)[0-9]*M/\164M/' ${PHP_INI}
142150
sed -i 's/^\(upload_max_filesize = \)[0-9]*M/\132M/' ${PHP_INI}
143151
sed -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}
145153
sed -i 's/;realpath_cache_ttl =.*/realpath_cache_ttl = 86400/' ${PHP_INI}
146154
sed -i 's/short_open_tag = Off/short_open_tag = On/' ${PHP_INI}
147155
sed -i 's/;max_input_vars =.*/max_input_vars = 50000/' ${PHP_INI}
@@ -177,6 +185,8 @@ END
177185
echo "${WEB_ROOT_PATH}/app/etc/env.php" >> /etc/opcache-default.blacklist
178186
echo "${WEB_ROOT_PATH}/app/etc/config.php" >> /etc/opcache-default.blacklist
179187

188+
_TIMER_USER_DATA_LEMP_INSTALLED="$(date -R)"
189+
180190
cd /etc/nginx
181191
git init
182192
git remote add origin ${CODECOMMIT_SERVICES_REPO}
@@ -207,6 +217,8 @@ systemctl daemon-reload
207217
systemctl restart nginx.service
208218
systemctl restart php*fpm.service
209219

220+
_TIMER_USER_DATA_LEMP_READY="$(date -R)"
221+
210222
hostnamectl set-hostname server.${DOMAIN} --static
211223
timedatectl 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

222234
chmod 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

Comments
 (0)