5
. /etc/rc.d/init.d/cloud-functions
8
local i=0 max=${MD_MAX_TRIES} iid="" uptime="" toks="" n="" cmdline=""
10
{ msg "nocloud specified, not using metadata"; return 0; }
11
read cmdline < /proc/cmdline
12
[ -f "${STATE_D}/cloud_tries" ] && read max < "${STATE_D}/cloud_tries"
13
if ! lxc-is-container; then
14
for n in ${cmdline}; do
16
cloud_tries=*) max=${n#cloud_tries=}; break;;
18
msg "kernel option nocloud specified. not using md"; return 0;;
22
[ ${max} -lt 0 ] && max=$((60*60*24*3)) ; # 3 days, is plenty
24
msg "checking ${MDURL}/instance-id"
26
while [ $i -lt ${max} ] && i=$(($i+1)); do
27
read uptime cputime < /proc/uptime
29
if mdget instance-id; then
31
[ "${iid#i-}" != "${iid}" ] && break
32
msg "failed $i/${max}: up ${uptime}. iid had ${iid}"
34
msg "failed $i/${max}: up ${uptime}. request failed"
37
if [ $i -eq "${MD_DEBUG_COUNT}" ]; then
38
msg "after ${MD_DEBUG_COUNT} fails, debugging"
43
if [ -n "${iid}" ]; then
44
msg "successful after ${i}/${max} tries: up ${uptime}. iid=${iid}"
46
msg "failed to read iid from metadata. tried ${max}"; return 1;
50
{ msg "previously ran for ${iid}"; return 0; }
56
mdget public-keys/ "${TMPF}"
57
echo >> "${TMPF}" # while loop will fail if no trailing newline
60
keys="${keys} ${line}"
63
# keys is list of [0-9]=name
64
if [ -n "${keys}" ]; then
65
msg "cloudinit: getting ssh keys: [${keys}]"
66
for toks in ${keys}; do
68
mdget public-keys/${n}/openssh-key - >> /root/.ssh/authorized_keys
76
*) msg "unknown argument ${1}";;