Skip to content

Commit

Permalink
pkg/cidata: Terminate user only when the environment changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mhio committed Dec 2, 2023
1 parent bfd7471 commit dc6905b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/cidata/cidata.TEMPLATE.d/boot/07-etc-environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ set -eux
# /etc/environment must be written after 04-persistent-data-volume.sh has run to
# make sure the changes on a restart are applied to the persisted version.

etc_environment_checksum_pre="nofile"
if [ -e /etc/environment ]; then
etc_environment_checksum_pre="$(md5sum /etc/environment||printf 'forcepre')"
sed -i '/#LIMA-START/,/#LIMA-END/d' /etc/environment
fi
cat "${LIMA_CIDATA_MNT}/etc_environment" >>/etc/environment
etc_environment_checksum_post="$(md5sum /etc/environment||printf 'forcepost')"

# It is possible that a requirements script has started an ssh session before
# /etc/environment was updated, so we need to kill it to make sure it will
# restart with the updated environment before "linger" is being enabled.

if command -v loginctl >/dev/null 2>&1; then
if command -v loginctl >/dev/null 2>&1 && [ "${etc_environment_checksum_pre}" != "${etc_environment_checksum_post}" ]; then
loginctl terminate-user "${LIMA_CIDATA_USER}" || true
fi

Expand Down

0 comments on commit dc6905b

Please sign in to comment.