fix: failed upload license at first time

This commit is contained in:
2024-04-17 15:35:25 +08:00
parent fda9f383dd
commit 6035ec1951

View File

@@ -7,7 +7,6 @@ import (
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
"time"
"be.ems/lib/dborm" "be.ems/lib/dborm"
"be.ems/lib/log" "be.ems/lib/log"
@@ -154,21 +153,21 @@ func DeleteLcenseFile(w http.ResponseWriter, r *http.Request) {
services.ResponseStatusOK204NoContent(w) services.ResponseStatusOK204NoContent(w)
} }
type MMLRequest struct { // type MMLRequest struct {
MML []string `json:"mml"` // MML []string `json:"mml"`
} // }
var TIME_DELAY_AFTER_WRITE time.Duration = 200 // var TIME_DELAY_AFTER_WRITE time.Duration = 200
var TIME_DEAD_LINE time.Duration = 10 // var TIME_DEAD_LINE time.Duration = 10
func init() { // func init() {
if config.GetYamlConfig().MML.Sleep != 0 { // if config.GetYamlConfig().MML.Sleep != 0 {
TIME_DELAY_AFTER_WRITE = time.Duration(config.GetYamlConfig().MML.Sleep) // TIME_DELAY_AFTER_WRITE = time.Duration(config.GetYamlConfig().MML.Sleep)
} // }
if config.GetYamlConfig().MML.DeadLine != 0 { // if config.GetYamlConfig().MML.DeadLine != 0 {
TIME_DEAD_LINE = time.Duration(config.GetYamlConfig().MML.DeadLine) // TIME_DEAD_LINE = time.Duration(config.GetYamlConfig().MML.DeadLine)
} // }
} // }
func UploadLicenseFileData(w http.ResponseWriter, r *http.Request) { func UploadLicenseFileData(w http.ResponseWriter, r *http.Request) {
log.Info("UploadLicenseFileData processing... ") log.Info("UploadLicenseFileData processing... ")
@@ -274,7 +273,8 @@ func UploadLicenseFileData(w http.ResponseWriter, r *http.Request) {
} }
// backup system.ini to system.ini.bak // backup system.ini to system.ini.bak
sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip) sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip)
cpCmd := fmt.Sprintf("sudo cp -f %s/system.ini %s/system.ini.bak", neLicensePath, neLicensePath) cpCmd := fmt.Sprintf("sudo test -f %s/system.ini && cp -f %s/system.ini %s/system.ini.bak",
neLicensePath, neLicensePath, neLicensePath)
cmd = exec.Command("ssh", sshHost, cpCmd) cmd = exec.Command("ssh", sshHost, cpCmd)
out, err = cmd.CombinedOutput() out, err = cmd.CombinedOutput()
log.Debugf("Exec output: %v", string(out)) log.Debugf("Exec output: %v", string(out))