fix: activate ne pkg issue
This commit is contained in:
@@ -686,71 +686,76 @@ func ActiveSoftwareToNF(w http.ResponseWriter, r *http.Request) {
|
|||||||
if !config.GetYamlConfig().OMC.TestMode {
|
if !config.GetYamlConfig().OMC.TestMode {
|
||||||
filePath := (*neVersion)[0]["file_path"]
|
filePath := (*neVersion)[0]["file_path"]
|
||||||
sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip)
|
sshHost := fmt.Sprintf("%s@%s", config.GetYamlConfig().NE.User, neInfo.Ip)
|
||||||
fileType := global.IsRpmOrDebPackage(filePath)
|
srcFile := fmt.Sprintf("%s/actpkg.sh", config.GetYamlConfig().OMC.BinDir)
|
||||||
if fileType == 1 {
|
|
||||||
rpmCmd := fmt.Sprintf("sudo rpm -Uvh '%s'", filePath)
|
|
||||||
cmd := exec.Command("ssh", sshHost, rpmCmd)
|
|
||||||
out, err := cmd.CombinedOutput()
|
|
||||||
log.Debugf("Exec output: %v", string(out))
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Faile to execute rpm command:", err)
|
|
||||||
services.ResponseInternalServerError500ProcessError(w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else if fileType == 2 {
|
|
||||||
srcFile := fmt.Sprintf("%s/spawndpkg.sh", config.GetYamlConfig().OMC.BinDir)
|
|
||||||
|
|
||||||
scpDir := fmt.Sprintf("%s@%s:%s", config.GetYamlConfig().NE.User,
|
scpDir := fmt.Sprintf("%s@%s:%s", config.GetYamlConfig().NE.User,
|
||||||
neInfo.Ip, config.GetYamlConfig().NE.ScpDir)
|
neInfo.Ip, config.GetYamlConfig().NE.ScpDir)
|
||||||
cmd := exec.Command("scp", "-r", srcFile, scpDir)
|
cmd := exec.Command("scp", "-r", srcFile, scpDir)
|
||||||
_, err := cmd.CombinedOutput()
|
_, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Faile to scp NF: neType=%s, neId=%s, ip=%s", neType, neId, neInfo.Ip)
|
log.Errorf("Faile to scp NF: neType=%s, neId=%s, ip=%s", neType, neId, neInfo.Ip)
|
||||||
services.ResponseInternalServerError500ProcessError(w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var inputStr string = "n"
|
|
||||||
var timeout int = 180
|
|
||||||
if config.GetYamlConfig().NE.DpkgOverwrite {
|
|
||||||
inputStr = "y"
|
|
||||||
}
|
|
||||||
if config.GetYamlConfig().NE.DpkgTimeout != 0 {
|
|
||||||
timeout = config.GetYamlConfig().NE.DpkgTimeout
|
|
||||||
}
|
|
||||||
dpkgCmd := fmt.Sprintf("sudo %s/spawndpkg.sh %d %s '%s'",
|
|
||||||
config.GetYamlConfig().NE.ScpDir, timeout, inputStr, filePath)
|
|
||||||
err = RunSSHCmd(sshHost, dpkgCmd)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Faile to execute dpkg command: %s, error: %v", dpkgCmd, err)
|
|
||||||
services.ResponseInternalServerError500ProcessError(w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// timeout := time.Duration(config.GetYamlConfig().OMC.CmdTimeout) * time.Second
|
|
||||||
// ctx, cancel := context.WithTimeout(context.Background(), timeout) // 设置超时
|
|
||||||
// defer cancel()
|
|
||||||
// cmd := exec.CommandContext(ctx, "ssh", sshHost, dpkgCmd)
|
|
||||||
// var stdout, stderr bytes.Buffer
|
|
||||||
// cmd.Stdout = &stdout
|
|
||||||
// cmd.Stderr = &stderr
|
|
||||||
// err := cmd.Start()
|
|
||||||
// if err != nil {
|
|
||||||
// log.Error("Faile to execute dpkg command: %v, err: %s", err, stderr.String())
|
|
||||||
// services.ResponseInternalServerError500ProcessError(w, err)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// out, err := cmd.CombinedOutput()
|
|
||||||
// log.Debugf("Exec output: %v", string(out))
|
|
||||||
// if err != nil {
|
|
||||||
// log.Error("Faile to execute dpkg command:", err)
|
|
||||||
// services.ResponseInternalServerError500ProcessError(w, err)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
} else {
|
|
||||||
err := global.ErrCMUnknownSoftwareFormat
|
|
||||||
log.Error(err)
|
|
||||||
services.ResponseInternalServerError500ProcessError(w, err)
|
services.ResponseInternalServerError500ProcessError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dpkgCmd := fmt.Sprintf("sudo %s/actpkg.sh '%s'",
|
||||||
|
config.GetYamlConfig().NE.ScpDir, filePath)
|
||||||
|
err = RunSSHCmd(sshHost, dpkgCmd)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Faile to execute dpkg command: %s, error: %v", dpkgCmd, err)
|
||||||
|
services.ResponseInternalServerError500ProcessError(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// fileType := global.IsRpmOrDebPackage(filePath)
|
||||||
|
// if fileType == 1 {
|
||||||
|
// srcFile := fmt.Sprintf("%s/spawnrpm.sh", config.GetYamlConfig().OMC.BinDir)
|
||||||
|
|
||||||
|
// scpDir := fmt.Sprintf("%s@%s:%s", config.GetYamlConfig().NE.User,
|
||||||
|
// neInfo.Ip, config.GetYamlConfig().NE.ScpDir)
|
||||||
|
// cmd := exec.Command("scp", "-r", srcFile, scpDir)
|
||||||
|
// _, err := cmd.CombinedOutput()
|
||||||
|
// if err != nil {
|
||||||
|
// log.Errorf("Faile to scp NF: neType=%s, neId=%s, ip=%s", neType, neId, neInfo.Ip)
|
||||||
|
// services.ResponseInternalServerError500ProcessError(w, err)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
|
// dpkgCmd := fmt.Sprintf("sudo %s/spawnrpm.sh '%s'",
|
||||||
|
// config.GetYamlConfig().NE.ScpDir, filePath)
|
||||||
|
// err = RunSSHCmd(sshHost, dpkgCmd)
|
||||||
|
// if err != nil {
|
||||||
|
// log.Errorf("Faile to execute dpkg command: %s, error: %v", dpkgCmd, err)
|
||||||
|
// services.ResponseInternalServerError500ProcessError(w, err)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// } else if fileType == 2 {
|
||||||
|
// srcFile := fmt.Sprintf("%s/spawndpkg.sh", config.GetYamlConfig().OMC.BinDir)
|
||||||
|
|
||||||
|
// scpDir := fmt.Sprintf("%s@%s:%s", config.GetYamlConfig().NE.User,
|
||||||
|
// neInfo.Ip, config.GetYamlConfig().NE.ScpDir)
|
||||||
|
// cmd := exec.Command("scp", "-r", srcFile, scpDir)
|
||||||
|
// _, err := cmd.CombinedOutput()
|
||||||
|
// if err != nil {
|
||||||
|
// log.Errorf("Faile to scp NF: neType=%s, neId=%s, ip=%s", neType, neId, neInfo.Ip)
|
||||||
|
// services.ResponseInternalServerError500ProcessError(w, err)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
|
// dpkgCmd := fmt.Sprintf("sudo %s/spawndpkg.sh '%s'",
|
||||||
|
// config.GetYamlConfig().NE.ScpDir, filePath)
|
||||||
|
// err = RunSSHCmd(sshHost, dpkgCmd)
|
||||||
|
// if err != nil {
|
||||||
|
// log.Errorf("Faile to execute dpkg command: %s, error: %v", dpkgCmd, err)
|
||||||
|
// services.ResponseInternalServerError500ProcessError(w, err)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// err := global.ErrCMUnknownSoftwareFormat
|
||||||
|
// log.Error(err)
|
||||||
|
// services.ResponseInternalServerError500ProcessError(w, err)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
switch neTypeLower {
|
switch neTypeLower {
|
||||||
case "omc":
|
case "omc":
|
||||||
restartCmd := fmt.Sprintf("sudo %s/bin/omcsvc.sh restart", config.GetYamlConfig().NE.OmcDir)
|
restartCmd := fmt.Sprintf("sudo %s/bin/omcsvc.sh restart", config.GetYamlConfig().NE.OmcDir)
|
||||||
|
|||||||
16
misc/actpkg.sh
Normal file
16
misc/actpkg.sh
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
expect <<EOF
|
||||||
|
set timeout 180
|
||||||
|
if [[ ${1} == *.deb ]]; then
|
||||||
|
spawn dpkg -i --force-all ${1}
|
||||||
|
elif [[ ${1} == *.rpm ]]; then
|
||||||
|
spawn rpm -Uvh ${1}
|
||||||
|
else
|
||||||
|
exit 1
|
||||||
|
#"The file does not have a .deb or .rpm extension"
|
||||||
|
fi
|
||||||
|
expect {
|
||||||
|
"y/n" { send "n\n";exp_continue }
|
||||||
|
}
|
||||||
|
EOF
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
expect <<EOF
|
|
||||||
set timeout ${1}
|
|
||||||
spawn dpkg -i --force-all ${3}
|
|
||||||
expect {
|
|
||||||
"y/n" { send "${2}\n";exp_continue }
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
Reference in New Issue
Block a user