public async Task RemovePavlovServerFromDisk( PavlovServerViewModel server, bool ignoreMostExceptions) { //Todo AuthError?? DataBaseLogger.LogToDatabaseAndResultPlusNotify("Start remove server!", LogEventLevel.Verbose, _notifyService); string result = ""; //start server and stop server to get Saved folder etc. if (ignoreMostExceptions) { try { await RconStatic.SystemDStop(server, _pavlovServerService); } catch (CommandException) { //ignore } } else { await RconStatic.SystemDStop(server, _pavlovServerService); } if (ignoreMostExceptions) { try { await RconStatic.RemovePath(server, server.ServerFolderPath, _pavlovServerService); } catch (CommandException) { //ignore } } else { await RconStatic.RemovePath(server, server.ServerFolderPath, _pavlovServerService); } server.SshServer = await FindOne(server.sshServerId); if (server.SshServer == null) { throw new CommandException("Could not get the sshServer!"); } var oldSSHcrid = new SshServer { SshPassphrase = server.SshServer.SshPassphrase, SshUsername = server.SshServer.SshUsername, SshPassword = server.SshServer.SshPassword, SshKeyFileName = server.SshServer.SshKeyFileName }; server.SshServer.SshPassphrase = server.SshPassphraseRoot; server.SshServer.SshUsername = server.SshUsernameRoot; server.SshServer.SshPassword = server.SshPasswordRoot; if (server.SshKeyFileNameForm != null) { await using var ms = new MemoryStream(); await server.SshKeyFileNameForm.CopyToAsync(ms); var fileBytes = ms.ToArray(); server.SshKeyFileNameRoot = fileBytes; // act on the Base64 data } server.SshServer.SshKeyFileName = server.SshKeyFileNameRoot; server.SshServer.NotRootSshUsername = oldSSHcrid.SshUsername; if (ignoreMostExceptions) { try { await RconStatic.RemovePath(server, "/etc/systemd/system/" + server.ServerSystemdServiceName + ".service", _pavlovServerService); } catch (CommandException) { //ignore } } else { await RconStatic.RemovePath(server, "/etc/systemd/system/" + server.ServerSystemdServiceName + ".service", _pavlovServerService); } //Remove the server from the sudoers file var sudoersPathParent = "/etc/sudoers.d"; var sudoersPath = sudoersPathParent + "/pavlovRconWebserverManagement"; var removed = true; if (ignoreMostExceptions) { try { removed = RconStatic.RemoveServerLineToSudoersFile(server, _notifyService, sudoersPath, _pavlovServerService); } catch (CommandException) { //ignore } } else { removed = RconStatic.RemoveServerLineToSudoersFile(server, _notifyService, sudoersPath, _pavlovServerService); } if (removed) { DataBaseLogger.LogToDatabaseAndResultPlusNotify("server line removed from sudoers file!", LogEventLevel.Verbose, _notifyService); } else { //means that the lines still is in the file!!! var error = "Could not remove the server line from sudoers file!"; DataBaseLogger.LogToDatabaseAndResultPlusNotify(error, LogEventLevel.Fatal, _notifyService); if (!ignoreMostExceptions) { throw new CommandException(error); } } //Handle the presets an newer systemd if (ignoreMostExceptions) { try { RconStatic.AddLineToNewerSystemDsIfNeeded(server, _notifyService, true); } catch (CommandException) { //ignore } } else { RconStatic.AddLineToNewerSystemDsIfNeeded(server, _notifyService, true); } DataBaseLogger.LogToDatabaseAndResultPlusNotify(result, LogEventLevel.Verbose, _notifyService); }