From 7226c31dfbbefd3f182b72ab1e4ab31f11ea0f83 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 1 Oct 2022 00:49:14 +0200 Subject: [PATCH] nd: increase services stop timeout to 10min but in parallel 10min looks quite excessive but based on conversations in https://github.com/bitcoin/bitcoin/commit/7fb7acfc, better safe than sorry. same for lnd. in any case, 30sec was indeed far too short to begin with, especially for bitcoind. services are now stopped in parallel, though. so, the poweroff sequence goes faster. --- src/nd.zig | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/nd.zig b/src/nd.zig index 76d6c4a..45f1d1d 100644 --- a/src/nd.zig +++ b/src/nd.zig @@ -216,10 +216,26 @@ pub fn main() !void { /// shut down important services manually. /// TODO: make this OS-agnostic fn svShutdown(allocator: std.mem.Allocator) void { - // sv waits 7sec by default but bitcoind needs more + // sv waits 7sec by default but bitcoind and lnd need more // http://smarden.org/runit/ - var stop_lnd = std.ChildProcess.init(&.{"sv", "-w", "25", "stop", "lnd"}, allocator); - _ = stop_lnd.spawnAndWait() catch |err| logger.err("stop lnd: {any}", .{err}); - var stop_btc = std.ChildProcess.init(&.{"sv", "-w", "30", "stop", "bitcoind"}, allocator); - _ = stop_btc.spawnAndWait() catch |err| logger.err("stop bitcoind: {any}", .{err}); + const Argv = []const []const u8; + const cmds: []const Argv = &.{ + &.{"sv", "-w", "600", "stop", "lnd"}, + &.{"sv", "-w", "600", "stop", "bitcoind"}, + }; + var procs: [cmds.len]?std.ChildProcess = undefined; + for (cmds) |argv, i| { + var p = std.ChildProcess.init(argv, allocator); + if (p.spawn()) { + procs[i] = p; + } else |err| { + logger.err("{s}: {any}", .{argv, err}); + } + } + for (procs) |_, i| { + var p = procs[i]; + if (p != null) { + _ = p.?.wait() catch |err| logger.err("{any}", .{err}); + } + } }