]>
Commit | Line | Data |
---|---|---|
1c21ebf8 MT |
1 | #!/bin/sh |
2 | ######################################################################## | |
3 | # Begin $rc_base/init.d/aws | |
4 | ######################################################################## | |
5 | ||
6 | . /etc/sysconfig/rc | |
7 | . ${rc_functions} | |
8 | ||
1c21ebf8 MT |
9 | # https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/identify_ec2_instances.html |
10 | running_on_ec2() { | |
11 | local uuid | |
12 | ||
13 | # Check if the hypervisor UUID starts with ec2 | |
14 | if [ -r "/sys/hypervisor/uuid" ]; then | |
15 | uuid=$(</sys/hypervisor/uuid) | |
16 | ||
17 | [ "${uuid:0:3}" = "ec2" ] && return 0 | |
18 | fi | |
19 | ||
20 | # Check if the DMI product UUID starts with EC2 | |
21 | if [ -r "/sys/devices/virtual/dmi/id/product_uuid" ]; then | |
22 | uuid=$(</sys/devices/virtual/dmi/id/product_uuid) | |
23 | ||
24 | [ "${uuid:0:3}" = "EC2" ] && return 0 | |
25 | fi | |
26 | ||
27 | # We are not running on AWS EC2 | |
28 | return 1 | |
29 | } | |
30 | ||
31 | case "${1}" in | |
32 | start) | |
33 | # Do nothing if we are not running on AWS EC2 | |
464c2755 | 34 | running_on_ec2 || exit 0 |
1c21ebf8 MT |
35 | |
36 | # Find the first interface to use | |
81e1e80e MT |
37 | for i in /sys/class/net/red* /sys/class/net/eth* \ |
38 | /sys/class/net/*; do | |
1c21ebf8 MT |
39 | [ -d "${i}" ] || continue |
40 | i=$(basename ${i}) | |
41 | ||
42 | # Skip loopback | |
43 | [ "${i}" = "lo" ] && continue | |
44 | ||
45 | # Use whatever we have found | |
46 | intf="${i}" | |
47 | break | |
48 | done | |
49 | ||
50 | # Check if we found a network interface | |
51 | if [ ! -n "${intf}" ]; then | |
52 | echo_failure | |
53 | ||
54 | boot_mesg -n "Could not find a network interface" ${FAILURE} | |
55 | boot_mesg "" ${NORMAL} | |
56 | fi | |
57 | ||
bd3bcb45 MT |
58 | # Run a DHCP client and set up the system accordingly |
59 | dhclient -sf /etc/rc.d/helper/aws-setup "${intf}" | |
1c21ebf8 | 60 | |
bd3bcb45 | 61 | # End DHCP client immediately |
9a56118b | 62 | dhclient -sf /etc/rc.d/helper/aws-setup -r "${intf}" &>/dev/null |
ba062943 | 63 | |
c5465a94 MT |
64 | # Rename network devices |
65 | udevadm trigger --action="add" --subsystem-match="net" | |
66 | ||
ba062943 | 67 | exit 0 |
1c21ebf8 MT |
68 | ;; |
69 | ||
70 | status) | |
71 | if running_on_ec2; then | |
72 | echo "This system is running on AWS EC2" | |
73 | exit 0 | |
74 | else | |
75 | echo "This system is NOT running on AWS EC2" | |
76 | exit 1 | |
77 | fi | |
78 | ;; | |
79 | ||
80 | *) | |
81 | echo "Usage: ${0} {start|status}" | |
82 | exit 1 | |
83 | ;; | |
84 | esac | |
85 | ||
86 | # End $rc_base/init.d/aws |