I am using GCP WM Instance with Container Optimized OS to run a container image. I use cloud-init
to initialize storage. When I initialize multiple drives, for example several local ssd, then it takes some time and docker container starts before cloud-init
is complete initializing drives. Which means I have race condition. Notice that docker container has started before file system has been initialized.
Apr 27 16:30:44 ch-s01r1 systemd[1]: Started docker-xxxxxx
...
2023-04-27 16:30:52,770 - subp.py[DEBUG]: Running command mkfs.ext4 -L ssd1 -m 0 ...
In Linux such problems are solved with adding dependencies between systemd
services, but I can not find any documentation how to add systemd
dependency either in cloud-init
nor GCP Container Optimized OS.
In terraform I have:
resource "google_compute_instance" "clickhouse-server" {
...
metadata = {
gce-container-declaration = module.gce-container.metadata_value
user-data = data.cloudinit_config.clickhouse_config[count.index].rendered
}
As I understand, those 2 parts start racing: user-data
will cause file system initialization and gce-container-declaration
will trigger container start up.
How do I ensure that container is not being started before cloud-init
is complete?
My cloud-init
file (I use terraform to expand macros):
...
fs_setup:
- label: log
filesystem: ext4
device: log
partition: auto
cmd: mkfs.ext4 -L %(label)s -m 0 -E lazy_itable_init=0,lazy_journal_init=0,discard %(device)s
- label: data
filesystem: ext4
device: data
partition: auto
cmd: mkfs.ext4 -L %(label)s -m 0 -E lazy_itable_init=0,lazy_journal_init=0,discard %(device)s
%{~ for n in range(ssd_count) ~}
- label: ssd${n}
filesystem: ext4
device: ssd${n}
partition: auto
cmd: mkfs.ext4 -L %(label)s -m 0 -E lazy_itable_init=0,lazy_journal_init=0,discard %(device)s
%{~ endfor ~}