1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-31 22:18:07 +08:00

fix: 命令执行增加超时时间 (#667)

This commit is contained in:
ssongliu 2023-04-17 14:03:01 +08:00 committed by GitHub
parent 222593ea69
commit 4a9895218e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 7 deletions

View File

@ -29,7 +29,7 @@ func (u *CronjobService) HandleJob(cronjob *model.Cronjob) {
if len(cronjob.Script) == 0 { if len(cronjob.Script) == 0 {
return return
} }
stdout, errExec := cmd.Exec(cronjob.Script) stdout, errExec := cmd.ExecWithTimeOut(cronjob.Script, 5*time.Minute)
if errExec != nil { if errExec != nil {
err = errExec err = errExec
} }
@ -48,7 +48,7 @@ func (u *CronjobService) HandleJob(cronjob *model.Cronjob) {
if len(cronjob.URL) == 0 { if len(cronjob.URL) == 0 {
return return
} }
stdout, errCurl := cmd.Exec("curl " + cronjob.URL) stdout, errCurl := cmd.ExecWithTimeOut("curl "+cronjob.URL, 5*time.Minute)
if err != nil { if err != nil {
err = errCurl err = errCurl
} }
@ -170,7 +170,7 @@ func handleTar(sourceDir, targetDir, name, exclusionRules string) error {
commands := fmt.Sprintf("tar zcvf %s %s %s", targetDir+"/"+name, excludeRules, path) commands := fmt.Sprintf("tar zcvf %s %s %s", targetDir+"/"+name, excludeRules, path)
global.LOG.Debug(commands) global.LOG.Debug(commands)
stdout, err := cmd.Exec(commands) stdout, err := cmd.ExecWithTimeOut(commands, 5*time.Minute)
if err != nil { if err != nil {
global.LOG.Errorf("do handle tar failed, stdout: %s, err: %v", stdout, err) global.LOG.Errorf("do handle tar failed, stdout: %s, err: %v", stdout, err)
return errors.New(stdout) return errors.New(stdout)
@ -187,7 +187,7 @@ func handleUnTar(sourceFile, targetDir string) error {
commands := fmt.Sprintf("tar zxvfC %s %s", sourceFile, targetDir) commands := fmt.Sprintf("tar zxvfC %s %s", sourceFile, targetDir)
global.LOG.Debug(commands) global.LOG.Debug(commands)
stdout, err := cmd.Exec(commands) stdout, err := cmd.ExecWithTimeOut(commands, 5*time.Minute)
if err != nil { if err != nil {
global.LOG.Errorf("do handle untar failed, stdout: %s, err: %v", stdout, err) global.LOG.Errorf("do handle untar failed, stdout: %s, err: %v", stdout, err)
return errors.New(stdout) return errors.New(stdout)

View File

@ -854,7 +854,7 @@ func (u *SnapshotService) handleTar(sourceDir, targetDir, name, exclusionRules s
commands := fmt.Sprintf("tar --warning=no-file-changed -zcf %s %s -C %s .", targetDir+"/"+name, exStr, sourceDir) commands := fmt.Sprintf("tar --warning=no-file-changed -zcf %s %s -C %s .", targetDir+"/"+name, exStr, sourceDir)
global.LOG.Debug(commands) global.LOG.Debug(commands)
stdout, err := cmd.Exec(commands) stdout, err := cmd.ExecWithTimeOut(commands, 10*time.Minute)
if err != nil { if err != nil {
global.LOG.Errorf("do handle tar failed, stdout: %s, err: %v", stdout, err) global.LOG.Errorf("do handle tar failed, stdout: %s, err: %v", stdout, err)
return errors.New(stdout) return errors.New(stdout)
@ -871,7 +871,7 @@ func (u *SnapshotService) handleUnTar(sourceDir, targetDir string) error {
commands := fmt.Sprintf("tar -zxf %s -C %s .", sourceDir, targetDir) commands := fmt.Sprintf("tar -zxf %s -C %s .", sourceDir, targetDir)
global.LOG.Debug(commands) global.LOG.Debug(commands)
stdout, err := cmd.Exec(commands) stdout, err := cmd.ExecWithTimeOut(commands, 10*time.Minute)
if err != nil { if err != nil {
global.LOG.Errorf("do handle untar failed, stdout: %s, err: %v", stdout, err) global.LOG.Errorf("do handle untar failed, stdout: %s, err: %v", stdout, err)
return errors.New(stdout) return errors.New(stdout)

View File

@ -148,7 +148,7 @@ func (u *UpgradeService) Upgrade(req dto.Upgrade) error {
go writeLogs(req.Version) go writeLogs(req.Version)
_ = settingRepo.Update("SystemVersion", req.Version) _ = settingRepo.Update("SystemVersion", req.Version)
_ = settingRepo.Update("SystemStatus", "Free") _ = settingRepo.Update("SystemStatus", "Free")
_, _ = cmd.Exec("systemctl daemon-reload && systemctl restart 1panel.service") _, _ = cmd.ExecWithTimeOut("systemctl daemon-reload && systemctl restart 1panel.service", 1*time.Minute)
}() }()
return nil return nil
} }