1#!/bin/sh 2# 3 4# PROVIDE: nuageinit 5# REQUIRE: mountcritlocal zfs devmatch 6# BEFORE: NETWORKING 7# KEYWORD: firstboot 8 9. /etc/rc.subr 10 11name="nuageinit" 12desc="Limited Cloud Init configuration" 13start_cmd="nuageinit_start" 14stop_cmd=":" 15rcvar="nuageinit_enable" 16 17fetch_openstack() 18{ 19 cd /media/nuageinit/openstack/latest 20 for file in meta_data.json network_data.json user_data; do 21 fetch http://169.254.169.254/openstack/latest/$file || : 22 done 23 if [ -f user_data ]; then 24 chmod 755 user_data 25 fi 26 cd - 27} 28 29nuageinit_start() 30{ 31 local citype 32 # detect cloud init provider 33 # according to the specification, the config drive 34 # is either formatted in vfat or iso9660 and labeled 35 # config-2 36 for f in iso9660 msdosfs; do 37 drive="/dev/$f/[cC][oO][nN][fF][iI][gG]-2" 38 if [ -e $drive ]; then 39 citype=config-2 40 break 41 fi 42 drive="/dev/$f/[cC][iI][dD][aA][tT][aA]" 43 if [ -e $drive ]; then 44 citype=nocloud 45 break 46 fi 47 unset drive 48 done 49 if [ -n "$drive" ]; then 50 mkdir -p /media/nuageinit 51 fs=$(fstyp $drive 2> /dev/null) 52 mount -t $fs $drive /media/nuageinit 53 else 54 product=$(kenv smbios.system.product) 55 case "$product" in 56 OpenStack*) 57 mkdir -p /media/nuageinit/openstack/latest 58 for iface in $(ifconfig -l ether); do 59 timeout 10s dhclient -p /tmp/ephemeraldhcp.$iface.pid $iface \ 60 || rm -f /tmp/ephemeraldhcp.$iface.pid 61 done 62 fetch_openstack 63 for pidfile in /tmp/ephemeraldhcp.*.pid; do 64 pkill -F $pidfile 65 done 66 citype=config-2 67 ;; 68 *) 69 # try to detect networked based instance 70 err 1 "Impossible to find a cloud init provider" 71 ;; 72 esac 73 fi 74 # according to the specification, the content is either 75 # in the openstack or ec2 directory 76 case "$citype" in 77 config-2) 78 for d in openstack ec2; do 79 dir=/media/nuageinit/$d/latest 80 if [ -d $dir ]; then 81 /usr/libexec/nuageinit $dir $citype 2>&1 | tee -a /var/log/nuageinit.log 82 break 83 fi 84 done 85 ;; 86 nocloud) 87 /usr/libexec/nuageinit /media/nuageinit $citype 2>&1 | tee -a /var/log/nuageinit.log 88 ;; 89 esac 90 if [ -x /var/cache/nuageinit/bootcmds ]; then 91 echo "Executing 'bootcmd'" | tee -a /var/log/nuageinit.log 92 /var/cache/nuageinit/bootcmds 2>&1 | tee -a /var/log/nuageinit.log 93 fi 94 if [ -n "$drive" ]; then 95 umount /media/nuageinit 96 rmdir /media/nuageinit 97 else 98 rm -rf /media/nuageinit 99 fi 100} 101 102load_rc_config $name 103run_rc_command "$1" 104