File tree Expand file tree Collapse file tree 4 files changed +53
-1
lines changed
Expand file tree Collapse file tree 4 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -32,9 +32,11 @@ make install DESTDIR=%{buildroot} PREFIX=/usr
3232/usr/lib/systemd/system/policy-routes@.service
3333/usr/lib/systemd/system/refresh-policy-routes@.service
3434/usr/lib/systemd/system/refresh-policy-routes@.timer
35+ /usr/lib/systemd/system/set-hostname-imds.service
3536
3637/usr/lib/udev/rules.d/99-vpc-policy-routes.rules
3738%{_bindir }/setup-policy-routes
39+ %{_bindir }/set-hostname-imds
3840%dir %{_datarootdir }/amazon-ec2-net-utils
3941%{_datarootdir }/amazon-ec2-net-utils/lib.sh
4042
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ #
3+ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+ #
5+ # Licensed under the Apache License, Version 2.0 (the "License"). You may
6+ # not use this file except in compliance with the License. A copy of the
7+ # License is located at
8+ #
9+ # http://aws.amazon.com/apache2.0/
10+ #
11+ # or in the "license" file accompanying this file. This file is distributed
12+ # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+ # express or implied. See the License for the specific language governing
14+ # permissions and limitations under the License.
15+
16+ set -eCo pipefail
17+
18+ libdir=${LIBDIR_OVERRIDE:-/ usr/ share/ amazon-ec2-net-utils}
19+
20+ . " ${libdir} /lib.sh"
21+
22+ if [ -s /etc/hostname ]; then
23+ info " Static hostname is already set - not modifying existing hostname"
24+ exit 0
25+ fi
26+
27+ hostname=$( get_imds local-hostname)
28+
29+ if [ -n " $hostname " ]; then
30+ info " Setting hostname to ${hostname} retrieved from IMDS"
31+ hostnamectl hostname ${hostname}
32+ else
33+ error " Unable to retrieve hostname from IMDS - aborting"
34+ exit 1
35+ fi
Original file line number Diff line number Diff line change @@ -71,7 +71,9 @@ get_token() {
7171 while [ " $( date +%s) " -lt $deadline ]; do
7272 for ep in " ${imds_endpoints[@]} " ; do
7373 set +e
74- imds_token=$( make_token_request " $ep " " $intf " )
74+ if [ -n " $intf " ]; then
75+ imds_token=$( make_token_request " $ep " " $intf " )
76+ fi
7577
7678 if [ -z " $imds_token " ]; then
7779 imds_token=$( make_token_request " $ep " )
Original file line number Diff line number Diff line change 1+ [Unit]
2+ Description =Sets the local hostname defined in IMDS
3+ After =network-online.target
4+ Requires =network-online.target
5+
6+ [Service]
7+ Type =oneshot
8+ ExecStart =/usr/bin/set-hostname-imds
9+ StandardOutput =journal+console
10+ StandardError =journal+console
11+
12+ [Install]
13+ WantedBy =multi-user.target
You can’t perform that action at this time.
0 commit comments