/// <summary> /// Ottiene un Master valorizzato coi valori ottenuti direttamente dal sistema operativo /// Potrebbe non corrispondere al Master salvato /// Viene utilizzato per ottenere le differenze tra i parametri salvati e quelli effettivamente applicati /// </summary> /// <returns></returns> public static MachineStatus GetRunning() { //var STOPWATCH = new System.Diagnostics.Stopwatch(); //STOPWATCH.Start(); var master = new MachineStatus(); master.Info.Uptime = Uptime.Get(); master.Info.CpuInfo = CpuInfo.Get(); master.Info.MemInfo = MemInfo.Get(); master.Info.Free = Free.Get(); master.Info.Losetup = Losetup.Get(); master.Info.DiskUsage = DiskUsage.Get(); master.Info.Versions = Versioning.Get(); master.Host = Hostnamectl.Get(); master.TimeDate = new TimeDate() { Timezone = Timedatectl.Get().Timezone }; master.Boot = new Boot(); var modules = Mod.Get(); var bootModules = new SystemModule[modules.Length]; for (var i = 0; i < modules.Length; i++) { bootModules[i] = new SystemModule() { Module = modules[i].Module, Active = true }; } master.Boot.Modules = bootModules; master.Boot.Services = cmds.Systemctl.GetAll(); master.Boot.Parameters = Sysctl.Get(); master.Users.SystemUsers = Passwd.Get(); master.Users.ApplicativeUsers = new ApplicativeUser[] { new ApplicativeUser() { Active = true, Type = AuthenticationType.simple, Id = "master", Claims = new[] { SHA.Generate("master") } } }; master.Network.KnownDns = Dns.GetResolv(); master.Network.KnownHosts = Dns.GetHosts(); master.Network.KnownNetworks = Dns.GetNetworks(); master.Network.Bridges = Brctl.Get(); master.Network.Bonds = Bond.Get(); master.Network.NetworkInterfaces = cmds.Network.Get(); master.Network.RoutingTables = Route.GetRoutingTable(); master.Network.Routing = Route.Get(); master.NsSwitch = NS.Switch.Get(); master.Storage.Mounts = Mount.Get(); master.Storage.Zpools = Zpool.GetPools(); master.Storage.ZfsDatasets = Zfs.GetDatasets(); master.Storage.ZfsSnapshots = Zfs.GetSnapshots(); master.Services.Ssh.PublicKey = Ssh.GetRootPublicKey(); master.Services.Ssh.PrivateKey = Ssh.GetRootPrivateKey(); master.Services.Ssh.AuthorizedKey = Ssh.GetAuthorizedKey(); master.Services.Virsh.Domains = Virsh.GetDomains(); //ConsoleLogger.Log($"[conf] loaded running conf ({STOPWATCH.ElapsedMilliseconds})"); return(master); }
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); }