mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-22 18:41:37 +00:00
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>
This commit is contained in:
parent
8c70f94a26
commit
245e64ac94
@ -57,7 +57,8 @@ RUN \
|
||||
rc-update add containerd default && \
|
||||
rc-update add aws default && \
|
||||
rc-update add azure default && \
|
||||
rc-update add gcp default && \
|
||||
rc-update add gcp-hostname default && \
|
||||
rc-update add gcp-startup default && \
|
||||
true
|
||||
|
||||
CMD ["/mkinitrd.sh"]
|
||||
|
@ -1,29 +0,0 @@
|
||||
#!/sbin/openrc-run
|
||||
|
||||
description="Bootstrap procedure if running on Docker GCP edition"
|
||||
|
||||
depend()
|
||||
{
|
||||
need docker
|
||||
need net
|
||||
}
|
||||
|
||||
start()
|
||||
{
|
||||
[ "$(mobyplatform)" != "gcp" ] && exit 0
|
||||
ebegin "Running GCP-specific initialization"
|
||||
|
||||
ebegin "Run startup script"
|
||||
|
||||
temp_file=$(mktemp)
|
||||
curl -s http://metadata.google.internal/computeMetadata/v1/instance/attributes/startup-script -H "Metadata-Flavor: Google" > ${temp_file}
|
||||
[ -s "${temp_file}" ] && sh "${temp_file}"
|
||||
rm -f "${temp_file}"
|
||||
|
||||
eend 0
|
||||
}
|
||||
|
||||
stop()
|
||||
{
|
||||
[ "$(mobyplatform)" != "gcp" ] && exit 0
|
||||
}
|
34
alpine/packages/gcp/etc/init.d/gcp-hostname
Executable file
34
alpine/packages/gcp/etc/init.d/gcp-hostname
Executable file
@ -0,0 +1,34 @@
|
||||
#!/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
|
||||
}
|
40
alpine/packages/gcp/etc/init.d/gcp-startup
Executable file
40
alpine/packages/gcp/etc/init.d/gcp-startup
Executable file
@ -0,0 +1,40 @@
|
||||
#!/sbin/openrc-run
|
||||
|
||||
description="Run startup/shudown scripts on Docker GCP edition"
|
||||
|
||||
depend()
|
||||
{
|
||||
need net
|
||||
}
|
||||
|
||||
metadata() {
|
||||
curl -sH 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/${1}
|
||||
}
|
||||
|
||||
start()
|
||||
{
|
||||
[ "$(mobyplatform)" != "gcp" ] && exit 0
|
||||
|
||||
ebegin "Run startup script"
|
||||
|
||||
temp_file=$(mktemp)
|
||||
metadata /instance/attributes/startup-script > ${temp_file}
|
||||
[ -s "${temp_file}" ] && sh "${temp_file}"
|
||||
rm -f "${temp_file}"
|
||||
|
||||
eend 0
|
||||
}
|
||||
|
||||
stop()
|
||||
{
|
||||
[ "$(mobyplatform)" != "gcp" ] && exit 0
|
||||
|
||||
ebegin "Run shutdown script"
|
||||
|
||||
temp_file=$(mktemp)
|
||||
metadata /instance/attributes/shutdown-script > ${temp_file}
|
||||
[ -s "${temp_file}" ] && sh "${temp_file}"
|
||||
rm -f "${temp_file}"
|
||||
|
||||
eend 0
|
||||
}
|
Loading…
Reference in New Issue
Block a user