public AssetSyncMachineModule() { Get["/syncmachine"] = x => { var settings = new SyncMachineConfiguration(); var set = settings.Get(); var syncedMachines = set.Machines.Any() ? set.Machines : new List <SyncMachineModel>(); var model = new PageAssetSyncMachineModel { IsActive = set.IsActive, SyncedMachines = syncedMachines.OrderBy(_ => _.MachineAddress) }; return(JsonConvert.SerializeObject(model)); }; Post["/syncmachine/set"] = x => { var syncmachineConfiguration = new SyncMachineConfiguration(); syncmachineConfiguration.Set(); return(HttpStatusCode.OK); }; Post["/syncmachine/restart"] = x => { var syncmachineConfiguration = new SyncMachineConfiguration(); syncmachineConfiguration.Start(); return(HttpStatusCode.OK); }; Post["/syncmachine/stop"] = x => { var syncmachineConfiguration = new SyncMachineConfiguration(); syncmachineConfiguration.Stop(); return(HttpStatusCode.OK); }; Post["/syncmachine/enable"] = x => { var dhcpdConfiguration = new SyncMachineConfiguration(); dhcpdConfiguration.Enable(); dhcpdConfiguration.Start(); return(HttpStatusCode.OK); }; Post["/syncmachine/disable"] = x => { var dhcpdConfiguration = new SyncMachineConfiguration(); dhcpdConfiguration.Disable(); dhcpdConfiguration.Stop(); return(HttpStatusCode.OK); }; Post["/syncmachine/machine"] = x => { string machineAddress = Request.Form.MachineAddress; var model = new SyncMachineModel { MachineAddress = machineAddress }; var syncmachineConfiguration = new SyncMachineConfiguration(); syncmachineConfiguration.AddResource(model); return(HttpStatusCode.OK); }; Post["/syncmachine/machine/del"] = x => { string guid = Request.Form.Guid; var syncmachineConfiguration = new SyncMachineConfiguration(); syncmachineConfiguration.RemoveResource(guid); return(HttpStatusCode.OK); }; Post["Accept Configuration", "/syncmachine/accept"] = x => { string file = Request.Form.File; string content = Request.Form.Content; if (File.Exists(file)) { File.Copy(file, $"{file}.sbck", true); } File.WriteAllText(file, content); //todo restart service to apply changes return(HttpStatusCode.OK); }; }
private static void ManagedProcedures() { Logger.Info("[config] managed procedures"); if (!Parameter.IsUnix) { return; } #region [ Samba ] if (SambaConfiguration.IsActive()) { SambaConfiguration.Set(); } #endregion #region [ Syslog ] if (SyslogNgConfiguration.IsActive()) { SyslogNgConfiguration.Set(); } #endregion #region [ Storage ] foreach (var pool in Zpool.ImportList().ToList()) { if (string.IsNullOrEmpty(pool)) { continue; } Logger.Info($"pool {pool} imported"); Zpool.Import(pool); } Logger.Info("storage ready"); #endregion #region [ Scheduler ] Timers.Setup(); Timers.Import(); Timers.Export(); foreach (var zp in Zpool.List()) { Timers.Create(zp.Name.ToLower() + "snap", "hourly", $"/sbin/zfs snap -r {zp.Name}@${{TTDATE}}"); } Timers.StartAll(); new SnapshotCleanup().Start(new TimeSpan(2, 00, 00)); new SyncTime().Start(new TimeSpan(0, 42, 00)); new RemoveUnusedModules().Start(new TimeSpan(2, 15, 00)); Logger.Info("scheduled events ready"); #endregion #region [ Acl ] if (AclConfiguration.IsActive()) { AclConfiguration.Set(); AclConfiguration.ScriptSetup(); } #endregion #region [ Sync ] if (GlusterConfiguration.IsActive()) { GlusterConfiguration.Set(); } if (RsyncConfiguration.IsActive()) { RsyncConfiguration.Set(); } #endregion #region [ SyncMachine ] if (SyncMachineConfiguration.IsActive()) { SyncMachineConfiguration.Set(); } #endregion #region [ C A ] if (CaConfiguration.IsActive()) { CaConfiguration.Set(); } #endregion #region [ Apps ] AppTarget.Setup(); var apps = AppsConfiguration.Get().Apps; foreach (var app in apps) { var units = app.UnitLauncher; foreach (var unit in units) { if (Systemctl.IsActive(unit) == false) { Systemctl.Restart(unit); } } } //AppTarget.StartAll(); Logger.Info("apps ready"); #endregion }