| #!/bin/sh |
| # PROVIDE: buildlet |
| # REQUIRE: NETWORKING DAEMON |
| # BEFORE: LOGIN |
| |
| . /etc/rc.subr |
| |
| name=buildlet |
| rcvar=buildlet_enable |
| |
| procname=/buildlet |
| pidfile="/var/run/${name}.pid" |
| command=/usr/sbin/daemon |
| command_args="-r -fc -p ${pidfile}" |
| command_args="${command_args} ${procname}" |
| start_precmd="${name}_prestart" |
| stop_cmd=":" |
| |
| load_rc_config $name |
| : ${buildlet_enable:="NO"} |
| |
| buildlet_prestart() |
| { |
| local buildlet_url |
| |
| info $(netstat -rn) |
| info $(cat /etc/resolv.conf) |
| |
| buildlet_url=$(/usr/local/bin/curl -s -H "Metadata-Flavor: Google" \ |
| http://metadata.google.internal/computeMetadata/v1/instance/attributes/buildlet-binary-url) |
| |
| if ! /usr/local/bin/curl -o /buildlet "${buildlet_url}"; then |
| warn "failed to download buildlet from ${buildlet_url}" |
| poweroff |
| return 1 |
| fi |
| |
| chmod a+x /buildlet |
| } |
| |
| run_rc_command "$1" |