public override Response Execute() { try { var systemConnection = Connection.System; //sys bus var systemd1Path = new ObjectPath("/org/freedesktop/systemd1"); var networkManager = systemConnection.CreateProxy <IManager>("org.freedesktop.systemd1", systemd1Path); var result = networkManager.StopUnitAsync(Name, "fail"); result.Wait(); if (result.IsCompletedSuccessfully) { SysMonitorsPool.RemoveDevice(DevidceType.eCPUMonitor, Name); return(new CommandResponse(Guid, GetIdent(), StatCodes.SUCSESS, $"{Name}")); } } catch (Exception) { return(new CommandResponse(Guid, GetIdent(), StatCodes.NO_CONTENT, $"{Name}")); } return(new CommandResponse(Guid, GetIdent(), StatCodes.NO_CONTENT, $"{Name}")); }
public override Response Execute() { //echo 27051989 | sudo -S dbus-send --print-reply --system --type=method_call --dest=org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager.StopUnit string:"foo-daemon.service" string:"fail" try { if (!Utils.GetProcIdByServiceName(out _, Name)) { return(new CommandResponse(Guid, GetIdent(), StatCodes.NO_CONTENT, $"{Name}")); } StringBuilder sb = new StringBuilder(); sb.Append($"echo {Args} | "). Append("sudo -S dbus-send "). Append("--print-reply "). Append("--system "). Append("--type=method_call "). Append("--dest=org.freedesktop.systemd1 "). Append("/org/freedesktop/systemd1 "). Append("org.freedesktop.systemd1.Manager.StopUnit "). Append($"string:\"{Name}\" "). Append("string:\"fail\""); var stopScript = sb.ToString(); if (Utils.ExecuteScript(out _, stopScript)) { Thread.Sleep(1000); // sleep for one second SysMonitorsPool.RemoveDevice(DevidceType.eCPUMonitor, Name); Console.WriteLine($"Invoked command {this}"); return(new CommandResponse(Guid, GetIdent(), StatCodes.SUCSESS, $"{Name}")); } } catch (Exception) { return(new CommandResponse(Guid, GetIdent(), StatCodes.NO_CONTENT, $"{Name}")); } return(new CommandResponse(Guid, GetIdent(), StatCodes.NO_CONTENT, $"{Name}")); }