public override void DoJob() { if (Application.CurrentConfiguration.Cluster.Active == false) { return; } var clusterStatus = Application.ClusterChecklist; if (clusterStatus == null) { return; } if (clusterStatus.Length < 1) { return; } var nodesKnownHosts = new List <KnownHost>(); for (var i = 0; i < clusterStatus.Length; i++) { var nodeIPs = clusterStatus[i].DiscoveredIpsReach; var nodeName = clusterStatus[i].Hostname; var commonNames = new string[] { CommonString.Append(nodeName, "int", i.ToString()) }; for (var p = 0; p < nodeIPs.Length; p++) { var knownHost = new KnownHost() { IpAddr = nodeIPs[p].IpAddress, CommonNames = commonNames }; nodesKnownHosts.Add(knownHost); } } var currentKnownHosts = Application.CurrentConfiguration.Network.KnownHosts.ToList(); foreach (var nodeHost in nodesKnownHosts) { //i casi possono essere tre: // 1) l'ip non è presente nella CurrentConfiguration -> aggiungo il nuovo KnownHost // 2) l'ip è presente ma i CommonNames sono differenti -> aggiorno solamente i CommonNames del KnownHost corrispondente // 3) l'ip è presente e i CommonNames coincidono -> non faccio nulla if (!currentKnownHosts.Any(_ => CommonString.AreEquals(_.IpAddr, nodeHost.IpAddr) == true)) { currentKnownHosts.Add(nodeHost); } else { var existingCn = currentKnownHosts.FirstOrDefault(_ => CommonString.AreEquals(_.IpAddr, nodeHost.IpAddr) == true).CommonNames; if (CommonString.AreEquals(CommonString.Build(existingCn), CommonString.Build(nodeHost.CommonNames)) == false) { currentKnownHosts.FirstOrDefault(_ => CommonString.AreEquals(_.IpAddr, nodeHost.IpAddr) == true).CommonNames = nodeHost.CommonNames; } } } Application.CurrentConfiguration.Network.KnownHosts = currentKnownHosts.ToArray(); ConfigRepo.Save(); Dns.Set(); }
private static void Main() { var resetEvent = new AutoResetEvent(initialState: false); Console.CancelKeyPress += (s, e) => { e.Cancel = true; resetEvent.Set(); }; STOPWATCH = new Stopwatch(); STOPWATCH.Start(); ConsoleLogger.Log($"[{KeyName}] start"); Scheduler = new JobManager(); OsReadAndWrite(); RemoveLimits(); CreateWorkingDirectories(); MountWorkingDirectories(); OverlayWatcher(); CurrentConfiguration = ConfigRepo.Read(); if (CurrentConfiguration == null) { CurrentConfiguration = new MachineConfig(); CurrentConfiguration.Host.MachineUid = Guid.NewGuid(); CurrentConfiguration.Host.SerialNumber = Guid.NewGuid(); CurrentConfiguration.Host.PartNumber = Guid.NewGuid(); CurrentConfiguration.Users.ApplicativeUsers = new ApplicativeUser[] { new ApplicativeUser() { Active = true, Type = AuthenticationType.simple, Id = "master", Claims = new[] { SHA.Generate("master") } } }; CurrentConfiguration.Network = Default.Network(); CurrentConfiguration.NsSwitch = new NsSwitch() { Aliases = "files", Ethers = "db files", Group = "files winbind", Hosts = "files mdns_minimal [NOTFOUND=return] resolve dns", Netgroup = "files", Networks = "files dns", Passwd = "files winbind", Protocols = "db files", Rpc = "db files", Services = "db files", Shadow = "compat", Netmasks = "files", Bootparams = "files", Automount = "files" }; CurrentConfiguration.Services.Ssh.AuthorizedKey = Ssh.GetAuthorizedKey(); ConfigRepo.Save(); } if (RunningConfiguration == null) { ConsoleLogger.Log("[conf] get running"); //RunningConfiguration = ConfigRepo.GetRunning(); RunningConfiguration = new MachineStatus(); } if (Checklist == null) { Checklist = new MachineStatusChecklistModel(); } Time(); CheckUnitsLocation(); Mounts(); Hostname(); GenerateSecret(); License(); SetServices(); SetModules(); SetParameters(); Users(); Dns(); Network(); Ntpd(); Firewall(); Dhcpd(); Bind(); ApplySetupConfiguration(); Nginx(); ManageSsh(); Samba(); Syslog(); StorageZfs(); Ca(); Apps(); Rsync(); Tor(); ManageVirsh(); ManageCluster(); DirectoryWatchers(); CheckApplicationFileAcls(); var port = CurrentConfiguration.WebService.Port; var uri = $"http://localhost:{port}/"; var webService = new NancyHost(new Uri(uri)); webService.Start(); StaticConfiguration.DisableErrorTraces = false; ConsoleLogger.Log($"[{KeyName}] web service is listening on port {port}"); #region [ Working ] PrepareGuiService(); StartRssdp(); LaunchJobs(); Test(); #endregion ConsoleLogger.Log($"[{KeyName}] loaded in: {STOPWATCH.ElapsedMilliseconds} ms"); resetEvent.WaitOne(); webService.Stop(); STOPWATCH.Stop(); ConsoleLogger.Log($"[{KeyName}] stop"); Environment.Exit(0); }