Browse Source

修复重复执行命令

master
root 4 days ago
parent
commit
f0529d8903
  1. 4
      CoreAgent.API/Configurations/netcommand.json
  2. 7
      CoreAgent.Infrastructure/Services/Network/CellularNetworkService.cs

4
CoreAgent.API/Configurations/netcommand.json

@ -35,12 +35,12 @@
},
{
"type": 0,
"template": "pkill tcpdump",
"template": "tcpdump",
"timeout": 5000,
"isEnabled": true,
"needReturnResult": false,
"needBackgroundExecution": false,
"canBeKilled": false,
"canBeKilled": true,
"hasParameters": false
},
{

7
CoreAgent.Infrastructure/Services/Network/CellularNetworkService.cs

@ -192,7 +192,7 @@ public class CellularNetworkService : ICellularNetworkService
{
if (command.CanBeKilled)
{
await KillProcessAsync(command.Template, command.Timeout);
return await KillProcessAsync(command.Template, command.Timeout);
}
var result = await _commandExecutor.ExecuteCommandAsync(command.Template, new CancellationTokenSource(),command.Timeout);
@ -205,11 +205,12 @@ public class CellularNetworkService : ICellularNetworkService
}
}
private async Task KillProcessAsync(string template,int Timeout)
private async Task<bool> KillProcessAsync(string template,int Timeout)
{
string killCmd = $"ps -ef | grep {template} | grep -v grep | awk '{{print $2}}' | xargs kill -9";
await _commandExecutor.ExecuteCommandAsync(killCmd, new CancellationTokenSource());
var result = await _commandExecutor.ExecuteCommandAsync(killCmd, new CancellationTokenSource());
_logger.LogInformation("已终止进程: {Template}", template);
return result.IsSuccess;
}
private async Task<bool> EnableNetworkInterfaceAsync(NetworkConfiguration networkConfig)

Loading…
Cancel
Save