Skip to content

Commit

Permalink
main: handle exhausted join failure
Browse files Browse the repository at this point in the history
  • Loading branch information
flowerinthenight committed Sep 30, 2024
1 parent 0623a04 commit 99ba773
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions gcp-mig-startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
mkdir /opt/zgroup/ && cd /opt/zgroup/
wget https://github.com/flowerinthenight/zgroup/releases/download/v0.3.1/zgroup-v0.3.1-x86_64-linux.tar.gz
tar -xzvf zgroup-v0.3.1-x86_64-linux.tar.gz
# ZGROUP_JOIN_PREFIX=0b9303ad-1beb-483f-abb5-bc58e0214531 INTERNAL_IP=$(curl -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/ip) ./zgroup group1 ${INTERNAL_IP}:8080 2>&1 | logger &
9 changes: 7 additions & 2 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub fn main() !void {
if (joined)
std.time.sleep(std.time.ns_per_s * 1)
else
std.time.sleep(bo.pause());
std.time.sleep(if (i >= 100) std.time.ns_per_s else bo.pause());

if (i > 1 and i < 100 and !joined) {
switch (hm.count()) {
Expand Down Expand Up @@ -136,7 +136,12 @@ pub fn main() !void {
join_addr[0..sep],
join_port,
&joined,
) catch |err| log.err("join failed: {any}", .{err});
) catch |err|
log.err("joining thru {s}:{d} failed: {any}", .{
join_addr[0..sep],
join_port,
err,
});
},
4 => {
// Join address is provided. Skip callback.
Expand Down
4 changes: 4 additions & 0 deletions src/scratch.zig
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,7 @@ test "envmap" {
dbg("no PATH\n", .{});
}
}

// gcloud compute instance-templates create sample-template-custom --machine-type e2-micro --metadata=startup-script=''"$(cat gcp-mig-startup.sh)"''
// gcloud compute instance-groups managed create example-rmig --template sample-template-custom --size 3 --region asia-northeast1
// sudo journalctl -u google-startup-scripts.service

0 comments on commit 99ba773

Please sign in to comment.