Skip to content

systemd: build: fix service startup failure when using IMDSv2 #10221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions init/az2-sethostname.in
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
[Unit]
Description=Set Hostname Workaround coreos/bugs#1272
Description=Set Hostname Workaround coreos/bugs#1272 with EC2 IMDSv2 support
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/sh -c "/usr/bin/hostnamectl set-hostname $(curl -s http://169.254.169.254/latest/meta-data/hostname)"

ExecStartPre=/bin/sh -c 'curl -sX PUT "http://169.254.169.254/latest/api/token" \
-H "X-aws-ec2-metadata-token-ttl-seconds: 21600" > /run/imds_token'

ExecStartPre=/bin/sh -c 'curl -s "http://169.254.169.254/latest/meta-data/hostname" \
-H "X-aws-ec2-metadata-token: $(cat /run/imds_token)" > /run/ec2_hostname'

ExecStart=/bin/sh -c '/usr/bin/hostnamectl set-hostname "$(cat /run/ec2_hostname)"'

ExecStartPost=/bin/sh -c 'rm -f /run/imds_token /run/ec2_hostname'

[Install]
WantedBy=multi-user.target
WantedBy=multi-user.target
Loading