using Khaemhat.Application.Configuration; using Khaemhat.Web.Hosting; try { // scripts/seed.sh: the base data from the command line, without serving anything. if (SeedCommand.Matches(args)) { return await SeedCommand.RunAsync(args).ConfigureAwait(false); } await KhaemhatApp.Build(args).RunAsync().ConfigureAwait(false); } catch (ConfigurationException ex) { // A missing or wrong variable: every problem on stderr, no value printed, exit code 2 (SPEC ยง6). await Console.Error.WriteLineAsync("Khaemhat cannot start, the configuration is not valid:").ConfigureAwait(false); foreach (var error in ex.Errors) { await Console.Error.WriteLineAsync(" - " + error).ConfigureAwait(false); } return 2; } catch (Exception ex) when (ex is not OperationCanceledException) { // The start failed after the configuration was read (system database unreachable, migration refused): the log // already has the details; the container restart policy decides what happens next. await Console.Error.WriteLineAsync("Khaemhat stopped: " + ex.Message).ConfigureAwait(false); return 1; } return Environment.ExitCode;