protected void ReleaseServerReservation(BaseServer server) { Logger.LogInformation("Releasing reservation on server {Id}", server.Id); server.ReservationType = ServerReservationType.None; server.ReservedFor = null; server.BumpUpdatedAt(); }
// TODO: make this async protected async Task PerformProvisioningCommands(BaseServer server, string command) { Logger.LogInformation("Beginning SSH connect to provision server at: {PublicAddress}", server.PublicAddress); // TODO: there should probably be a maximum number of times this is attempted IBaseSSHAccess sshAccess; try { sshAccess = ConnectWithSSH(server); } catch (SocketException) { Logger.LogWarning("Connection failed (socket exception), server is probably not up yet"); return; } catch (SshOperationTimeoutException) { Logger.LogWarning("Connection failed (ssh timed out), server is probably not up yet"); return; } Logger.LogInformation("Connected, running provisioning command..."); var start = DateTime.UtcNow; var result = sshAccess.RunCommand(command); if (!result.Success) { Logger.LogWarning("Failed provision result ({ExitCode}: {Result}", result.ExitCode, result.Result); throw new Exception($"Provisioning commands failed ({result.ExitCode}): {result.Error}"); } // Now fully provisioned server.ProvisionedFully = true; server.Status = ServerStatus.Running; server.LastMaintenance = DateTime.UtcNow; server.WantsMaintenance = false; server.StatusLastChecked = DateTime.UtcNow; server.ReservationType = ServerReservationType.None; server.BumpUpdatedAt(); await Database.SaveChangesAsync(); var elapsed = DateTime.UtcNow - start; Logger.LogInformation("Completed provisioning for server {Id}, elapsed: {Elapsed}", server.Id, elapsed); }