Files
Adam Mizerski 13d5f20e5b nuageinit: fix support on OpenStack
Change added in 90a7728cd8 contained a
lot of bugs:
- If all network interfaces correctly respond to DHCP, then pwait was
waiting forever.
- If there was more than 1 interface, then "cat
/tmp/ephemeraldhcp.*.pid" joined pid numbers into one long string.
- "for iface in $left; do kill -15 $left; done" is not using $iface.

Tested by:	[email protected]
Sponsored by:	OVHcloud
Pull Request:	https://github.com/freebsd/freebsd-src/pull/2436
2026-09-17 17:32:37 +02:00

104 lines
2.3 KiB
Bash
Executable File

#!/bin/sh
#
# PROVIDE: nuageinit
# REQUIRE: mountcritlocal zfs devmatch
# BEFORE: NETWORKING
# KEYWORD: firstboot
. /etc/rc.subr
name="nuageinit"
desc="Limited Cloud Init configuration"
start_cmd="nuageinit_start"
stop_cmd=":"
rcvar="nuageinit_enable"
fetch_openstack()
{
cd /media/nuageinit/openstack/latest
for file in meta_data.json network_data.json user_data; do
fetch http://169.254.169.254/openstack/latest/$file || :
done
if [ -f user_data ]; then
chmod 755 user_data
fi
cd -
}
nuageinit_start()
{
local citype
# detect cloud init provider
# according to the specification, the config drive
# is either formatted in vfat or iso9660 and labeled
# config-2
for f in iso9660 msdosfs; do
drive="/dev/$f/[cC][oO][nN][fF][iI][gG]-2"
if [ -e $drive ]; then
citype=config-2
break
fi
drive="/dev/$f/[cC][iI][dD][aA][tT][aA]"
if [ -e $drive ]; then
citype=nocloud
break
fi
unset drive
done
if [ -n "$drive" ]; then
mkdir -p /media/nuageinit
fs=$(fstyp $drive 2> /dev/null)
mount -t $fs $drive /media/nuageinit
else
product=$(kenv smbios.system.product)
case "$product" in
OpenStack*)
mkdir -p /media/nuageinit/openstack/latest
for iface in $(ifconfig -l ether); do
timeout 10s dhclient -p /tmp/ephemeraldhcp.$iface.pid $iface \
|| rm -f /tmp/ephemeraldhcp.$iface.pid
done
fetch_openstack
for pidfile in /tmp/ephemeraldhcp.*.pid; do
pkill -F $pidfile
done
citype=config-2
;;
*)
# try to detect networked based instance
err 1 "Impossible to find a cloud init provider"
;;
esac
fi
# according to the specification, the content is either
# in the openstack or ec2 directory
case "$citype" in
config-2)
for d in openstack ec2; do
dir=/media/nuageinit/$d/latest
if [ -d $dir ]; then
/usr/libexec/nuageinit $dir $citype 2>&1 | tee -a /var/log/nuageinit.log
break
fi
done
;;
nocloud)
/usr/libexec/nuageinit /media/nuageinit $citype 2>&1 | tee -a /var/log/nuageinit.log
;;
esac
if [ -x /var/cache/nuageinit/bootcmds ]; then
echo "Executing 'bootcmd'" | tee -a /var/log/nuageinit.log
/var/cache/nuageinit/bootcmds 2>&1 | tee -a /var/log/nuageinit.log
fi
if [ -n "$drive" ]; then
umount /media/nuageinit
rmdir /media/nuageinit
else
rm -rf /media/nuageinit
fi
}
load_rc_config $name
run_rc_command "$1"