fix: set timeout for run dpkg command

This commit is contained in:
2024-01-11 17:53:21 +08:00
parent 5aeca6ecb4
commit 23b87162dd
3 changed files with 4 additions and 1 deletions

View File

@@ -701,7 +701,8 @@ func ActiveSoftwareToNF(w http.ResponseWriter, r *http.Request) {
} }
} else if fileType == 2 { } else if fileType == 2 {
dpkgCmd := fmt.Sprintf("sudo dpkg -i --force-all '%s'", filePath) dpkgCmd := fmt.Sprintf("sudo dpkg -i --force-all '%s'", filePath)
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) // 设置60秒超时 timeout := time.Duration(config.GetYamlConfig().OMC.CmdTimeout) * time.Second
ctx, cancel := context.WithTimeout(context.Background(), timeout) // 设置超时
defer cancel() defer cancel()
cmd := exec.CommandContext(ctx, "ssh", sshHost, dpkgCmd) cmd := exec.CommandContext(ctx, "ssh", sshHost, dpkgCmd)
var stdout, stderr bytes.Buffer var stdout, stderr bytes.Buffer

View File

@@ -81,6 +81,7 @@ type YamlConfig struct {
TestMode bool `yaml:"testMode"` TestMode bool `yaml:"testMode"`
RBACMode bool `yaml:"rbacMode"` RBACMode bool `yaml:"rbacMode"`
RunDir string `yaml:"runDir"` RunDir string `yaml:"runDir"`
CmdTimeout int `yaml:"cmdTimeout"`
} `yaml:"omc"` } `yaml:"omc"`
Alarm struct { Alarm struct {

View File

@@ -113,6 +113,7 @@ omc:
testMode: false testMode: false
rbacMode: true rbacMode: true
runDir: runDir:
cmdTimeout: 120
# Alarm module setting # Alarm module setting
# Forward interface: # Forward interface: