## template:jinja
#!/bin/sh

# PROVIDE: cloudconfig
# REQUIRE: cloudinit cloudinitlocal
# BEFORE:  cloudfinal

. /etc/rc.subr

PATH="{{ prefix }}/sbin:{{ prefix }}/bin:/usr/sbin:/usr/bin:/sbin:/bin"

name="cloudconfig"
command="{{prefix}}/bin/cloud-init"
start_cmd="cloudconfig_start"
stop_cmd=":"
rcvar="cloudinit_enable"

cloudconfig_start()
{
    echo "${command} starting"
    if kenv -q kernel_options | grep -q 'cloud-init=disabled'; then
        warn "cloud-init is disabled via kernel_options."
    elif test -e {{prefix}}/etc/cloud/cloud-init.disabled; then
        warn "cloud-init is disabled via cloud-init.disabled file."
    else
        ${command} modules --mode config
    fi
}

load_rc_config 'cloudinit'

: ${cloudinit_enable="NO"}

run_rc_command "$1"
