Skip to content

Commit a4a0c47

Browse files
authored
Merge pull request #8 from zeroae/chore/live-probe
Add healthcheck
2 parents 9734b27 + 36055e6 commit a4a0c47

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ RUN addgroup -S mobius3 && \
88
WORKDIR /home/mobius3
99

1010
RUN pip install mobius3==0.0.34
11+
COPY zmobius3.py /usr/bin/zmobius3
1112

1213
USER mobius3
1314

main.tf

+17-11
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ module "volume_label" {
1212
label_order = ["name"]
1313
}
1414

15-
# TODO: Implement a health check
1615
# TODO: Support different user/groups
1716
module "mobius3" {
1817
source = "git::https://github.com/cloudposse/terraform-aws-ecs-container-definition.git?ref=tags/0.57.0"
@@ -23,7 +22,7 @@ module "mobius3" {
2322
user = var.user
2423

2524
command = [
26-
"mobius3",
25+
"zmobius3",
2726
"/srv/data",
2827
var.bucket_id,
2928
"https://{}.s3.${var.bucket_region}.amazonaws.com/",
@@ -33,21 +32,28 @@ module "mobius3" {
3332
"--log-level", "INFO"
3433
]
3534

36-
mount_points = [
37-
{
38-
containerPath = "/srv/data"
39-
sourceVolume = module.volume_label.id
40-
readOnly = false
41-
}
42-
]
35+
healthcheck = {
36+
command = ["/bin/sh", "-c",
37+
"cat /tmp/ruok | grep imok"
38+
]
39+
retries = 3
40+
timeout = 3
41+
interval = 10
42+
startPeriod = 60
43+
}
44+
45+
mount_points = [{
46+
containerPath = "/srv/data"
47+
sourceVolume = module.volume_label.id
48+
readOnly = false
49+
}]
4350

4451
log_configuration = var.log_configuration
4552
}
4653

4754
locals {
4855
output_container_depends_on = {
4956
containerName = module.mobius3.json_map_object["name"]
50-
# TODO: Use HEALTHY once we have a healthcheck
51-
condition = "START"
57+
condition = "HEALTHY"
5258
}
5359
}

zmobius3.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python
2+
import mobius3
3+
4+
5+
super_async_main = mobius3.async_main
6+
7+
8+
async def async_main(syncer_args):
9+
stop = await super_async_main(syncer_args)
10+
with open("/tmp/ruok", "w") as f:
11+
f.write("imok")
12+
return stop
13+
14+
15+
if __name__ == "__main__":
16+
mobius3.async_main = async_main
17+
mobius3.main()
18+
19+

0 commit comments

Comments
 (0)