Skip to content

Commit 8fea284

Browse files
committed
fix(*): schedule data containers to specific machines
Currently, whenever database, logger, registry, or builder are rescheduled by fleet, their data container is left on the original machine. The effect for the user is that they lose their data! This commit schedules data containers to a preselected machine. If that machine goes down, the underlying service will go down, but this is preferred to scheduling it on another host that won't have the data. Note that this is an interim fix - stateful data should be stored off-host. closes #1038
1 parent 89cf376 commit 8fea284

5 files changed

Lines changed: 33 additions & 5 deletions

File tree

Makefile

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ COMPONENTS=builder cache controller database logger registry
2424
ALL_COMPONENTS=$(COMPONENTS) router
2525
START_COMPONENTS=registry logger cache database
2626

27-
ALL_UNITS = $(foreach C,$(COMPONENTS),$(wildcard $(C)/systemd/*))
28-
START_UNITS = $(foreach C,$(START_COMPONENTS),$(wildcard $(C)/systemd/*))
27+
ALL_UNITS = $(foreach C,$(COMPONENTS),$(wildcard $(C)/systemd/*.service))
28+
START_UNITS = $(foreach C,$(START_COMPONENTS),$(wildcard $(C)/systemd/*.service))
29+
30+
DATA_CONTAINER_TEMPLATES=builder/systemd/deis-builder-data.service database/systemd/deis-database-data.service logger/systemd/deis-logger-data.service registry/systemd/deis-registry-data.service
2931

3032
all: build run
3133

@@ -40,8 +42,22 @@ full-clean: clean
4042

4143
install: check-fleet install-routers
4244
$(FLEETCTL) load $(START_UNITS)
43-
$(FLEETCTL) load controller/systemd/*
44-
$(FLEETCTL) load builder/systemd/*
45+
$(FLEETCTL) load controller/systemd/*.service
46+
$(FLEETCTL) load builder/systemd/*.service
47+
echo $(shell make install-data-containers)
48+
49+
install-data-containers: check-fleet
50+
@$(foreach T, $(DATA_CONTAINER_TEMPLATES), \
51+
cp $(T).template . ; \
52+
NEW_FILENAME=`ls *.template | sed 's/\.template//g'`; \
53+
mv *.template $$NEW_FILENAME ; \
54+
MACHINE_ID=`$(FLEETCTL) list-machines --no-legend --full list-machines | awk 'BEGIN { OFS="\t"; srand() } { print rand(), $$1 }' | sort -n | cut -f2- | head -1` ; \
55+
sed -e "s/CHANGEME/$$MACHINE_ID/" $$NEW_FILENAME > $$NEW_FILENAME.bak ; \
56+
rm -f $$NEW_FILENAME ; \
57+
mv $$NEW_FILENAME.bak $$NEW_FILENAME ; \
58+
$(FLEETCTL) load $$NEW_FILENAME ; \
59+
rm -f $$NEW_FILENAME ; \
60+
)
4561

4662
install-routers: check-fleet
4763
@$(foreach R, $(ROUTER_UNITS), \
@@ -86,7 +102,7 @@ start: check-fleet start-warning start-routers
86102

87103
@# builder
88104
$(call echo_yellow,"Waiting for deis-builder to start...")
89-
$(FLEETCTL) start -no-block builder/systemd/*
105+
$(FLEETCTL) start -no-block builder/systemd/*.service
90106
@until $(FLEETCTL) list-units | egrep -q "deis-builder.+(running|failed)"; \
91107
do sleep 2; \
92108
printf "\033[0;33mStatus:\033[0m "; $(FLEETCTL) list-units | \

builder/systemd/deis-builder-data.service renamed to builder/systemd/deis-builder-data.service.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ ExecStart=/bin/sh -c "docker inspect deis-builder-data >/dev/null 2>&1 || docker
88

99
[Install]
1010
WantedBy=multi-user.target
11+
12+
[X-Fleet]
13+
X-ConditionMachineBootID=CHANGEME

database/systemd/deis-database-data.service renamed to database/systemd/deis-database-data.service.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ ExecStart=/bin/sh -c "docker inspect deis-database-data >/dev/null 2>&1 || docke
88

99
[Install]
1010
WantedBy=multi-user.target
11+
12+
[X-Fleet]
13+
X-ConditionMachineBootID=CHANGEME

logger/systemd/deis-logger-data.service renamed to logger/systemd/deis-logger-data.service.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ ExecStart=/bin/sh -c "docker inspect deis-logger-data >/dev/null 2>&1 || docker
88

99
[Install]
1010
WantedBy=multi-user.target
11+
12+
[X-Fleet]
13+
X-ConditionMachineBootID=CHANGEME

registry/systemd/deis-registry-data.service renamed to registry/systemd/deis-registry-data.service.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ ExecStart=/bin/sh -c "docker inspect deis-registry-data >/dev/null 2>&1 || docke
88

99
[Install]
1010
WantedBy=multi-user.target
11+
12+
[X-Fleet]
13+
X-ConditionMachineBootID=CHANGEME

0 commit comments

Comments
 (0)