Files
linuxkit/alpine/packages/gcp/etc/init.d/gcp-hostname
David Gageot 1bf637ca5d Set hostname on GCP
Split GCP startup script in two:

 + One started before Docker, to set the hostname
 + Another to run the startup script

Signed-off-by: David Gageot <david@gageot.net>
2016-12-28 17:51:33 +01:00

35 lines
722 B
Plaintext
Executable File

#!/sbin/openrc-run
description="Set hostname on Docker GCP edition"
depend()
{
need net
before docker
}
metadata() {
curl -sH 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/${1}
}
start()
{
[ "$(mobyplatform)" != "gcp" ] && exit 0
ebegin "Set hostname based on what GCP tells us it should be"
IP=$(metadata instance/network-interfaces/0/ip)
HOSTNAME=$(metadata instance/hostname)
echo "${IP} ${HOSTNAME} ${HOSTNAME%%.*} # Added by Google" >> /etc/hosts
echo "169.254.169.254 metadata.google.internal # Added by Google" >> /etc/hosts
echo ${HOSTNAME%%.*} >/etc/hostname
hostname -F /etc/hostname
eend 0
}
stop()
{
[ "$(mobyplatform)" != "gcp" ] && exit 0
}