Skip to content

Commit ffb7fea

Browse files
authored
Improve DCV virtual session creation
Install both Apache and Nginx Certbot plugins
1 parent 78b3484 commit ffb7fea

3 files changed

+125
-115
lines changed

AmazonLinux-2-LAMP-server.yaml

+66-70
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,6 @@ Parameters:
143143
- Intel/AMD (x86_64)
144144
- Graviton (arm64)
145145
Default: Graviton (arm64)
146-
instanceType:
147-
Type: String
148-
Description: "https://console.aws.amazon.com/ec2/#InstanceTypes"
149-
Default: t4g.xlarge
150146

151147
ec2Name:
152148
Type: String
@@ -157,6 +153,10 @@ Parameters:
157153
Description: "https://console.aws.amazon.com/ec2/#KeyPairs"
158154
ConstraintDescription: Specify a key pair
159155
AllowedPattern: ".+"
156+
instanceType:
157+
Type: String
158+
Description: "https://console.aws.amazon.com/ec2/#InstanceTypes"
159+
Default: t4g.xlarge
160160
ec2TerminationProtection:
161161
Type: String
162162
Description: "https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_ChangingDisableAPITermination.html"
@@ -264,9 +264,9 @@ Parameters:
264264
Type: String
265265
Description: https://aws.amazon.com/ebs/general-purpose/
266266
AllowedValues:
267-
- "gp3"
268-
- "gp2"
269-
Default: "gp3"
267+
- gp3
268+
- gp2
269+
Default: gp3
270270

271271
enableBackup:
272272
Type: String
@@ -1254,33 +1254,6 @@ Resources:
12541254
mode: "000755"
12551255
owner: "ec2-user"
12561256
group: "ec2-user"
1257-
"/usr/lib/systemd/system/certbot-renew.timer":
1258-
content: |
1259-
[Unit]
1260-
Description=This is the timer to set the schedule for automated renewals
1261-
1262-
[Timer]
1263-
OnCalendar=*-*-* 00/12:00:00
1264-
RandomizedDelaySec=12hours
1265-
Persistent=true
1266-
1267-
[Install]
1268-
WantedBy=timers.target
1269-
mode: "000644"
1270-
owner: "root"
1271-
group: "root"
1272-
"/usr/lib/systemd/system/certbot-renew.service":
1273-
content: |
1274-
[Unit]
1275-
Description=This service automatically renews any certbot certificates found
1276-
1277-
[Service]
1278-
EnvironmentFile=/etc/sysconfig/certbot
1279-
Type=oneshot
1280-
ExecStart=/usr/bin/certbot renew --noninteractive --no-random-sleep-on-renew $PRE_HOOK $POST_HOOK $RENEW_HOOK $DEPLOY_HOOK $CERTBOT_ARGS
1281-
mode: "000644"
1282-
owner: "root"
1283-
group: "root"
12841257
"/etc/systemd/system/dcv-virtual-session.service":
12851258
content: |
12861259
[Unit]
@@ -1304,20 +1277,14 @@ Resources:
13041277
for dcvUser in "${dcvUsers[@]}"
13051278
do
13061279
if (! /usr/bin/dcv list-sessions | grep -q $dcvUser); then
1307-
case $dcvUser in
1308-
root)
1309-
/usr/bin/dcv create-session $dcvUser --owner root --storage-root /root
1310-
;;
1311-
*)
1312-
/usr/bin/dcv create-session $dcvUser --owner $dcvUser --user $dcvUser --storage-root /home/$dcvUser
1313-
;;
1314-
esac
1280+
/usr/bin/dcv create-session $dcvUser --owner $dcvUser --storage-root %home% --type virtual
13151281
fi
13161282
done
1283+
date
13171284
/usr/bin/dcv list-sessions
13181285
sleep 5
13191286
done
1320-
mode: "000755"
1287+
mode: "000744"
13211288
owner: "root"
13221289
group: "root"
13231290
"/etc/systemd/system/dcv-post-reboot.service":
@@ -1404,15 +1371,6 @@ Resources:
14041371
yum clean all
14051372
yum update -q -y
14061373
1407-
# remove AWSCLI version 1
1408-
yum remove -q -y awscli
1409-
cd /tmp/cfn
1410-
# AWS CLI v2: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
1411-
curl -s https://awscli.amazonaws.com/awscli-exe-linux-$(arch).zip -o awscliv2.zip
1412-
unzip -q -o awscliv2.zip
1413-
./aws/install -b /usr/bin
1414-
echo "export AWS_CLI_AUTO_PROMPT=on-partial" >> /home/ec2-user/.bashrc
1415-
14161374
# yum-cron
14171375
yum install -q -y yum-cron
14181376
sed -i 's/apply_updates = no/apply_updates = yes/g' /etc/yum/yum-cron.conf
@@ -1454,10 +1412,63 @@ Resources:
14541412
usermod -aG docker ec2-user
14551413
fi
14561414
1415+
# AWS CLI: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
1416+
yum remove -q -y awscli
1417+
cd /tmp/cfn
1418+
# AWS CLI v2: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
1419+
curl -s https://awscli.amazonaws.com/awscli-exe-linux-$(arch).zip -o awscliv2.zip
1420+
unzip -q -o awscliv2.zip
1421+
./aws/install -b /usr/bin
1422+
echo "export AWS_CLI_AUTO_PROMPT=on-partial" >> /home/ec2-user/.bashrc
1423+
1424+
# Certbot: https://certbot.eff.org/instructions?ws=other&os=pip
1425+
yum install -q -y augeas-libs
1426+
amazon-linux-extras install -q -y python3.8
1427+
1428+
/usr/bin/python3.8 -m venv /opt/certbot/
1429+
/opt/certbot/bin/pip install --upgrade pip
1430+
/opt/certbot/bin/pip install certbot
1431+
/opt/certbot/bin/pip install certbot-dns-route53
1432+
/opt/certbot/bin/pip install certbot-apache
1433+
/opt/certbot/bin/pip install certbot-nginx
1434+
ln -s /opt/certbot/bin/certbot /usr/bin/certbot
1435+
1436+
touch /etc/sysconfig/certbot
1437+
chmod og-rwx /etc/sysconfig/certbot
1438+
systemctl daemon-reload
1439+
systemctl enable --now certbot-renew.timer
1440+
14571441
rm -f ${!0}
14581442
mode: "000740"
14591443
owner: "root"
14601444
group: "root"
1445+
"/usr/lib/systemd/system/certbot-renew.timer":
1446+
content: |
1447+
[Unit]
1448+
Description=This is the timer to set the schedule for automated renewals
1449+
1450+
[Timer]
1451+
OnCalendar=*-*-* 00/12:00:00
1452+
RandomizedDelaySec=12hours
1453+
Persistent=true
1454+
1455+
[Install]
1456+
WantedBy=timers.target
1457+
mode: "000640"
1458+
owner: "root"
1459+
group: "root"
1460+
"/usr/lib/systemd/system/certbot-renew.service":
1461+
content: |
1462+
[Unit]
1463+
Description=This service automatically renews any certbot certificates found
1464+
1465+
[Service]
1466+
EnvironmentFile=/etc/sysconfig/certbot
1467+
Type=oneshot
1468+
ExecStart=/usr/bin/certbot renew --noninteractive --no-random-sleep-on-renew $PRE_HOOK $POST_HOOK $RENEW_HOOK $DEPLOY_HOOK $CERTBOT_ARGS
1469+
mode: "000640"
1470+
owner: "root"
1471+
group: "root"
14611472
commands:
14621473
install:
14631474
command: "/root/install-sw.sh >> /var/log/install-sw.log 2>&1"
@@ -1470,6 +1481,9 @@ Resources:
14701481
mkdir -p /tmp/cfn
14711482
cd /tmp/cfn
14721483
1484+
# Update OS
1485+
yum update -q -y
1486+
14731487
# DCV prereq: https://docs.aws.amazon.com/dcv/latest/adminguide/setting-up-installing-linux-prereq.html
14741488
yum install -q -y gdm gnome-session gnome-classic-session gnome-session-xsession
14751489
yum install -q -y xorg-x11-server-Xorg xorg-x11-fonts-Type1 xorg-x11-drivers
@@ -1701,27 +1715,10 @@ Resources:
17011715
amazon-linux-extras install -y redis6 memcached1.5
17021716
systemctl enable --now redis memcached
17031717
1704-
# Certbot: https://certbot.eff.org/instructions?ws=other&os=pip
1705-
yum install -q -y augeas-libs
1706-
amazon-linux-extras install -y python3.8
1707-
/usr/bin/python3.8 -m venv /opt/certbot/
1708-
/opt/certbot/bin/pip install --upgrade pip
1709-
/opt/certbot/bin/pip install certbot
1710-
/opt/certbot/bin/pip install certbot-dns-route53
1711-
ln -s /opt/certbot/bin/certbot /usr/bin/certbot
1712-
1713-
# Certbot update script
1714-
# https://certbot.org/renewal-setup: use systemd timer
1715-
touch /etc/sysconfig/certbot
1716-
chmod og-rwx /etc/sysconfig/certbot
1717-
systemctl daemon-reload
1718-
systemctl enable certbot-renew.timer
1719-
17201718
# Web server
17211719
export WEB="${webOption}"
17221720
case $WEB in
17231721
Apache)
1724-
/opt/certbot/bin/pip install certbot-apache
17251722
yum install -q -y httpd mod_ssl mod_fcgid
17261723
systemctl enable httpd
17271724
cp /etc/httpd/conf.modules.d/00-mpm.conf /etc/httpd/conf.modules.d/00-mpm.conf."`date +"%Y-%m-%d"`"
@@ -1757,7 +1754,6 @@ Resources:
17571754
systemctl restart httpd
17581755
;;
17591756
Nginx)
1760-
/opt/certbot/bin/pip install certbot-nginx
17611757
amazon-linux-extras install -y nginx1
17621758
systemctl enable nginx
17631759

AmazonLinux-2023-LAMP-server.yaml

+11-11
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,6 @@ Parameters:
140140
- Intel/AMD (x86_64)
141141
- Graviton (arm64)
142142
Default: Graviton (arm64)
143-
instanceType:
144-
Type: String
145-
Description: "https://console.aws.amazon.com/ec2/#InstanceTypes"
146-
Default: t4g.xlarge
147143

148144
ec2Name:
149145
Type: String
@@ -154,6 +150,10 @@ Parameters:
154150
Description: "https://console.aws.amazon.com/ec2/#KeyPairs"
155151
ConstraintDescription: Specify a key pair
156152
AllowedPattern: ".+"
153+
instanceType:
154+
Type: String
155+
Description: "https://console.aws.amazon.com/ec2/#InstanceTypes"
156+
Default: t4g.xlarge
157157
ec2TerminationProtection:
158158
Type: String
159159
Description: "https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_ChangingDisableAPITermination.html"
@@ -1304,6 +1304,13 @@ Resources:
13041304
usermod -aG docker ec2-user
13051305
fi
13061306
1307+
# Certbot: https://github.com/amazonlinux/amazon-linux-2023/issues/444
1308+
dnf install -q -y certbot python3-certbot-dns-route53
1309+
dnf install -q -y python3-certbot-apache
1310+
dnf install -q -y python3-certbot-nginx
1311+
systemctl daemon-reload
1312+
systemctl enable --now certbot-renew.timer
1313+
13071314
rm -f ${!0}
13081315
mode: "000740"
13091316
owner: "root"
@@ -1583,16 +1590,10 @@ Resources:
15831590
dnf install -q -y redis6 memcached
15841591
systemctl enable --now redis6 memcached
15851592
1586-
# Certbot: https://github.com/amazonlinux/amazon-linux-2023/issues/444
1587-
dnf install -q -y certbot python3-certbot-dns-route53
1588-
systemctl daemon-reload
1589-
systemctl enable certbot-renew.timer
1590-
15911593
# Web server
15921594
export WEB="${webOption}"
15931595
case $WEB in
15941596
Apache)
1595-
dnf install -q -y python3-certbot-apache
15961597
dnf install -q -y httpd mod_ssl mod_fcgid
15971598
systemctl enable httpd
15981599
@@ -1617,7 +1618,6 @@ Resources:
16171618
;;
16181619
Nginx)
16191620
dnf remove -q -y httpd
1620-
dnf install -q -y python3-certbot-nginx
16211621
dnf install -q -y nginx
16221622
systemctl enable nginx
16231623

0 commit comments

Comments
 (0)