diff options
author | Scott Murray <scott.murray@konsulko.com> | 2023-06-20 13:10:23 -0400 |
---|---|---|
committer | Scott Murray <scott.murray@konsulko.com> | 2023-06-20 13:12:45 -0400 |
commit | c32fe42f40d0af8b31b6113a3140f52b83be7769 (patch) | |
tree | abeefb1405161486bd37ccf8846be866411eac5e | |
parent | 7a3e870a8349d43a4838604db2c28140c2f76c9f (diff) |
Add sd_notify callricefish_18.0.2ricefish_18.0.1ricefish_18.0.0ricefish/18.0.2ricefish/18.0.1ricefish/18.0.0quillback_17.1.4quillback_17.1.3quillback_17.1.2quillback_17.1.1quillback_17.1.0quillback_17.0.2quillback_17.0.1quillback_17.0.0quillback/17.1.4quillback/17.1.3quillback/17.1.2quillback/17.1.1quillback/17.1.0quillback/17.0.2quillback/17.0.1quillback/17.0.018.0.218.0.118.0.017.1.417.1.317.1.217.1.117.1.017.0.217.0.117.0.0
To avoid races with client applications, add a call to sd_notify
after the gRPC service should be available, so that a Type=notify
systemd unit can be used to start applaunchd. As well, fix up
some naming and comments around what the call to the gRPC server
object's Wait method is for.
Bug-AGL: SPEC-4843
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
Change-Id: I069d3caa4e3cddb0041e2f94ecb568499104dcf2
-rw-r--r-- | src/main-grpc.cc | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/main-grpc.cc b/src/main-grpc.cc index d94e4aa..0347aba 100644 --- a/src/main-grpc.cc +++ b/src/main-grpc.cc @@ -7,6 +7,7 @@ #include <chrono> #include <glib.h> #include <glib-unix.h> +#include <systemd/sd-daemon.h> #include "systemd_manager.h" #include "AppLauncherImpl.h" @@ -27,9 +28,9 @@ static gboolean quit_cb(gpointer user_data) return G_SOURCE_REMOVE; } -void RunGrpcServer(std::shared_ptr<Server> &server) +void WaitGrpcServer(std::shared_ptr<Server> &server) { - // Start server and wait for shutdown + // Wait for shutdown server->Wait(); } @@ -58,12 +59,14 @@ int main(int argc, char *argv[]) exit(1); } std::cout << "Server listening on " << server_address << std::endl; + sd_notify(0, "READY=1"); g_unix_signal_add(SIGTERM, quit_cb, (gpointer) &server); g_unix_signal_add(SIGINT, quit_cb, (gpointer) &server); - // Start gRPC API server on its own thread - std::thread grpc_thread(RunGrpcServer, std::ref(server)); + // Wait on gRPC API server in another thread to keep that + // separate from the glib loop. + std::thread grpc_thread(WaitGrpcServer, std::ref(server)); g_main_loop_run(main_loop); |