Skip to content

Commit 0b8e573

Browse files
author
Thomas Roos
committed
aws-iot-greengrass-lite-demo-ec2-image: fix flaky ssh, rauc grow partition
Sometimes /home/user is not bind mount from data partition before cloud-init creates .ssh folder. These change fix this. As well as a rauc grow partition is not always running. Resulting in a non fully resized data partition.
1 parent d494856 commit 0b8e573

5 files changed

Lines changed: 54 additions & 48 deletions

File tree

meta-aws-demos/recipes-core/images/aws-iot-greengrass-lite-demo-ec2-image/aws-iot-greengrass-lite-demo-ec2-image.bb

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -63,55 +63,26 @@ rootfs_user_fstab () {
6363
# Allow user to use sudo
6464
echo "user ALL=(ALL) NOPASSWD: ALL" >> ${IMAGE_ROOTFS}/etc/sudoers
6565

66-
6766
# enable serial console auto login for root
6867
sed -i '/^\s*ExecStart\b/ s/getty /&--autologin root /' \
6968
"${IMAGE_ROOTFS}${systemd_system_unitdir}/serial-getty@.service"
7069

71-
# reload services after data partition is mounted
72-
cat > ${IMAGE_ROOTFS}/lib/systemd/system/reload-systemd-data.service << 'EOF'
73-
[Unit]
74-
Description=Reload systemd services from data partition
75-
After=data.mount
76-
77-
[Service]
78-
Type=oneshot
79-
ExecStart=/bin/systemctl daemon-reload
80-
ExecStart=/bin/systemctl start --all
81-
RemainAfterExit=yes
82-
EOF
83-
84-
ln -sf /lib/systemd/system/reload-systemd-data.service ${IMAGE_ROOTFS}/lib/systemd/system/reload-systemd-data.service
85-
8670
# not necessary for this image
8771
rm ${IMAGE_ROOTFS}//usr/lib/systemd/system/systemd-vconsole-setup.service
8872

8973
# move all exising systemd services to the lib system directory and the remaining dir will be the bind mount point
9074
cp -a ${IMAGE_ROOTFS}/etc/systemd/system/* ${IMAGE_ROOTFS}/lib/systemd/system/
9175
rm -rf ${IMAGE_ROOTFS}/etc/systemd/system/*
9276

93-
# cloud-intit service needs to be started after data partition is mounted
94-
mkdir -p ${IMAGE_ROOTFS}/lib/systemd/system/cloud-init.service.d/
95-
cat << EOF > ${IMAGE_ROOTFS}/lib/systemd/system/cloud-init.service.d/overrides.conf
77+
# cloud-init-local service also needs to wait for data partition mounts
78+
mkdir -p ${IMAGE_ROOTFS}/lib/systemd/system/cloud-init-local.service.d/
79+
cat << EOF > ${IMAGE_ROOTFS}/lib/systemd/system/cloud-init-local.service.d/overrides.conf
9680
[Unit]
97-
After=local-fs.target
98-
After=rauc-grow-data-partition.service
81+
RequiresMountsFor=/etc/ssh/
9982
RequiresMountsFor=/home
10083
RequiresMountsFor=/root
101-
RequiresMountsFor=/etc/ssh/
102-
103-
[Service]
104-
Restart=on-failure
105-
RestartSec=30
106-
StartLimitInterval=90
107-
StartLimitBurst=3
108-
ExecStopPost=/usr/bin/cloud-init clean
109-
110-
[Install]
111-
WantedBy=multi-user.target
11284
EOF
11385

114-
11586
# overwrite the default fstab, adding customization for this image
11687
cat << EOF > ${IMAGE_ROOTFS}/${sysconfdir}/fstab
11788
/dev/root / auto rw 1 1
@@ -167,7 +138,6 @@ fi
167138
install -d ${IMAGE_ROOTFS}/data/etc/ssh/
168139
mv -f ${IMAGE_ROOTFS}/etc/ssh/* ${IMAGE_ROOTFS}/data/etc/ssh/
169140

170-
171141
}
172142

173143
####

meta-aws-demos/recipes-core/rauc/files/rauc-grow-data-partition.service

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
22

3-
SRC_URI += "file://rauc.service.d/override.conf"
3+
SRC_URI:append = " file://rauc.service.d/override.conf"
44

55
do_install:append() {
66
install -d ${D}${systemd_system_unitdir}/rauc.service.d
77
install -m 0644 ${WORKDIR}/rauc.service.d/override.conf ${D}${systemd_system_unitdir}/rauc.service.d/
88
}
99

10+
do_install:append:rpi() {
11+
# Remove ExecStart line for mmcblk0
12+
sed -i '/ExecStart=.*mmcblk0.*resizepart 6/d' ${D}${systemd_system_unitdir}/rauc-grow-data-partition.service
13+
}
14+
1015
# enable debug logs for rauc to see stats of adaptive updates
11-
FILES:${PN} += "${systemd_system_unitdir}/rauc.service.d/override.conf"
16+
FILES:${PN}:append = " ${systemd_system_unitdir}/rauc.service.d/override.conf"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
2+
3+
SRC_URI:append = " file://cloud-init.service"
4+
5+
do_install:append() {
6+
install -m 0644 ${WORKDIR}/cloud-init.service ${D}${systemd_system_unitdir}/cloud-init.service
7+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[Unit]
2+
Description=Initial cloud-init job (metadata service crawler)
3+
DefaultDependencies=no
4+
Wants=cloud-init-local.service
5+
Wants=sshd-keygen.service
6+
Wants=sshd.service
7+
After=cloud-init-local.service
8+
After=systemd-networkd-wait-online.service
9+
After=networking.service
10+
After=rauc-grow-data-partition.service
11+
Before=network-online.target
12+
Before=sshd-keygen.service
13+
Before=sshd.service
14+
Before=shutdown.target
15+
Conflicts=shutdown.target
16+
ConditionPathExists=!/etc/cloud/cloud-init.disabled
17+
ConditionKernelCommandLine=!cloud-init=disabled
18+
ConditionEnvironment=!KERNEL_CMDLINE=cloud-init=disabled
19+
20+
[Service]
21+
Type=oneshot
22+
ExecStart=/usr/bin/cloud-init init
23+
RemainAfterExit=yes
24+
TimeoutSec=0
25+
Restart=on-failure
26+
RestartSec=30
27+
StartLimitInterval=90
28+
StartLimitBurst=3
29+
ExecStopPost=/usr/bin/cloud-init clean
30+
31+
# Output needs to appear in instance console output
32+
StandardOutput=journal+console
33+
34+
[Install]
35+
WantedBy=cloud-init.target
36+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)