Esempio n. 1
0
        public UnitsModule()
            : base("/units")
        {
            Get["/"] = x => {
                List <UnitModel> units = Units.All;
                return(View["page-units", units]);
            };

            Post["/mgmt/enable/{unit}"] = x => {
                string       unit = x.unit;
                CommandModel r    = Systemctl.Enable(unit);
                string       json = JsonConvert.SerializeObject(r.outputTable);
                return(json);
            };

            Post["/mgmt/disable/{unit}"] = x => {
                string       unit = x.unit;
                CommandModel r    = Systemctl.Disable(unit);
                string       json = JsonConvert.SerializeObject(r.outputTable);
                return(json);
            };

            Post["/mgmt/start/{unit}"] = x => {
                string       unit = x.unit;
                CommandModel r    = Systemctl.Start(unit);
                string       json = JsonConvert.SerializeObject(r.outputTable);
                return(json);
            };

            Post["/mgmt/stop/{unit}"] = x => {
                string       unit = x.unit;
                CommandModel r    = Systemctl.Stop(unit);
                string       json = JsonConvert.SerializeObject(r.outputTable);
                return(json);
            };

            Post["/mgmt/restart/{unit}"] = x => {
                string       unit = x.unit;
                CommandModel r    = Systemctl.Restart(unit);
                string       json = JsonConvert.SerializeObject(r.outputTable);
                return(json);
            };

            Post["/mgmt/reload/{unit}"] = x => {
                string       unit = x.unit;
                CommandModel r    = Systemctl.Reload(unit);
                string       json = JsonConvert.SerializeObject(r.outputTable);
                return(json);
            };

            Get["/mgmt/status/{unit}"] = x => {
                string       unit = x.unit;
                CommandModel r    = Systemctl.Status(unit);
                string       json = JsonConvert.SerializeObject(r.outputTable);
                return(json);
            };
        }
Esempio n. 2
0
        public AntdServicesModule()
        {
            Get["/services"] = x => {
                var model       = new PageServicesModel();
                var machineInfo = new MachineInfo();
                var services    = machineInfo.GetUnits("service");
                var mounts      = machineInfo.GetUnits("mount");
                var targets     = machineInfo.GetUnits("target");
                var timers      = machineInfo.GetUnits("timer");
                services.AddRange(mounts);
                services.AddRange(targets);
                services.AddRange(timers);
                model.Units = services;
                return(JsonConvert.SerializeObject(model));
            };

            Get["/services/log"] = x => {
                string unit     = Request.Query.unit;
                var    launcher = new CommandLauncher();
                var    model    = launcher.Launch("journactl-service", new Dictionary <string, string> {
                    { "$service", unit }
                });
                return(JsonConvert.SerializeObject(model));
            };

            Post["/services/start"] = x => {
                string unit = Request.Form.Unit;
                Systemctl.Start(unit);
                return(HttpStatusCode.OK);
            };

            Post["/services/restart"] = x => {
                string unit = Request.Form.Unit;
                Systemctl.Restart(unit);
                return(HttpStatusCode.OK);
            };

            Post["/services/stop"] = x => {
                string unit = Request.Form.Unit;
                Systemctl.Stop(unit);
                return(HttpStatusCode.OK);
            };

            Post["/services/enable"] = x => {
                string unit = Request.Form.Unit;
                Systemctl.Enable(unit);
                return(HttpStatusCode.OK);
            };

            Post["/services/disable"] = x => {
                string unit = Request.Form.Unit;
                Systemctl.Disable(unit);
                return(HttpStatusCode.OK);
            };
        }
Esempio n. 3
0
        public UnitsModule()
        {
            this.RequiresAuthentication();

            Get["/units"] = x => {
                var units = Units.All;
                return(View["page-units", units]);
            };

            Get["/units/list"] = x => {
                return(JsonConvert.SerializeObject(Units.All.OrderBy(u => u.name)));
            };

            Post["/units/mgmt/enable/{unit}"] = x => {
                string unit = x.unit;
                var    r    = Systemctl.Enable(unit);
                return(JsonConvert.SerializeObject(r.outputTable));
            };

            Post["/units/mgmt/disable/{unit}"] = x => {
                string unit = x.unit;
                var    r    = Systemctl.Disable(unit);
                return(JsonConvert.SerializeObject(r.outputTable));
            };

            Post["/units/mgmt/start/{unit}"] = x => {
                string unit = x.unit;
                var    r    = Systemctl.Start(unit);
                return(JsonConvert.SerializeObject(r.outputTable));
            };

            Post["/units/mgmt/stop/{unit}"] = x => {
                string unit = x.unit;
                var    r    = Systemctl.Stop(unit);
                return(JsonConvert.SerializeObject(r.outputTable));
            };

            Post["/units/mgmt/restart/{unit}"] = x => {
                string unit = x.unit;
                var    r    = Systemctl.Restart(unit);
                return(JsonConvert.SerializeObject(r.outputTable));
            };

            Post["/units/mgmt/reload/{unit}"] = x => {
                string unit = x.unit;
                var    r    = Systemctl.Reload(unit);
                return(JsonConvert.SerializeObject(r.outputTable));
            };

            Get["/units/mgmt/status/{unit}"] = x => {
                string unit = x.unit;
                var    r    = Systemctl.Status(unit);
                return(JsonConvert.SerializeObject(r.outputTable));
            };
        }
Esempio n. 4
0
        public void StopService()
        {
            var svcs = HostParametersConfiguration.Conf.ServicesStop;

            foreach (var svc in svcs)
            {
                if (Systemctl.IsEnabled(svc))
                {
                    Systemctl.Disable(svc);
                }
                if (Systemctl.IsActive(svc))
                {
                    Systemctl.Stop(svc);
                }
            }
        }