Skip to content

Commit

Permalink
runtime/runner: trigger termination on SIGINT
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddrysdale committed Apr 15, 2020
1 parent 7b73b84 commit c66093d
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions oak/server/loader/oak_runner_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

#include <csignal>
#include <sstream>
#include <string>

Expand All @@ -30,6 +31,12 @@ ABSL_FLAG(std::string, ca_cert, "", "Path to the PEM-encoded CA root certificate
ABSL_FLAG(std::string, private_key, "", "Path to the private key");
ABSL_FLAG(std::string, cert_chain, "", "Path to the PEM-encoded certificate chain");

namespace {

absl::Notification server_done;

void sigint_handler(int) { server_done.Notify(); }

std::shared_ptr<grpc::ServerCredentials> BuildTlsCredentials(std::string pem_root_certs,
std::string private_key,
std::string cert_chain) {
Expand All @@ -40,10 +47,12 @@ std::shared_ptr<grpc::ServerCredentials> BuildTlsCredentials(std::string pem_roo
return grpc::SslServerCredentials(options);
}

} // namespace

int main(int argc, char* argv[]) {
absl::ParseCommandLine(argc, argv);

// Create loader instance.
// Create the loader instance.
std::unique_ptr<oak::OakLoader> loader = absl::make_unique<oak::OakLoader>();

// Load application configuration.
Expand Down Expand Up @@ -71,14 +80,16 @@ int main(int argc, char* argv[]) {
OAK_LOG(ERROR) << "Failed to create application";
return 1;
}

std::stringstream address;
address << "0.0.0.0:" << application_config->grpc_port();
OAK_LOG(INFO) << "Oak Application: " << address.str();

// Wait (same as `sleep(86400)`).
absl::Notification server_timeout;
server_timeout.WaitForNotificationWithTimeout(absl::Hours(24));
// Wait until notification of signal termination.
std::signal(SIGINT, sigint_handler);
server_done.WaitForNotification();

OAK_LOG(ERROR) << "Terminate Oak Application";
loader->TerminateApplication();

return 0;
Expand Down

0 comments on commit c66093d

Please sign in to comment.