fix: 软件报直装记录版本号
This commit is contained in:
@@ -157,9 +157,8 @@ func (s *NeSoftwareController) Remove(c *gin.Context) {
|
||||
func (s *NeSoftwareController) Install(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
Action string `json:"action" binding:"required,oneof=install upgrade"` // 安装行为
|
||||
Software model.NeSoftware `json:"software" binding:"required"` // 软件包信息
|
||||
Preinput map[string]string `json:"preinput" binding:"required"` // 预先输入参数
|
||||
Software model.NeSoftware `json:"software" binding:"required"` // 软件包信息
|
||||
Preinput map[string]string `json:"preinput" binding:"required"` // 预先输入参数
|
||||
}
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.Software.NeId == "" {
|
||||
@@ -184,8 +183,8 @@ func (s *NeSoftwareController) Install(c *gin.Context) {
|
||||
s.neSoftwareService.Update(neSoftware)
|
||||
}
|
||||
|
||||
// 进行安装检查
|
||||
output, err := s.neSoftwareService.InstallToNeHost(body.Action, body.Software, body.Preinput)
|
||||
// 进行安装
|
||||
output, err := s.neSoftwareService.InstallToNeHost(body.Software, body.Preinput)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
|
||||
@@ -26,7 +26,5 @@ type INeSoftware interface {
|
||||
CheckUniqueTypeAndNameAndVersion(neType, name, version, id string) bool
|
||||
|
||||
// InstallToNeHost 安装包上传到网元主机执行安装命令
|
||||
//
|
||||
// action 安装行为:install upgrade
|
||||
InstallToNeHost(action string, neSoftware model.NeSoftware, preinput map[string]string) (string, error)
|
||||
InstallToNeHost(neSoftware model.NeSoftware, preinput map[string]string) (string, error)
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ func (r *NeSoftwareImpl) Insert(neSoftware model.NeSoftware) string {
|
||||
neVersions := NewNeVersionImpl.SelectList(model.NeVersion{NeType: neSoftware.NeType})
|
||||
if len(neVersions) > 0 {
|
||||
for _, neVersion := range neVersions {
|
||||
neVersion.NewName = neSoftware.Name
|
||||
neVersion.NewVersion = neSoftware.Version
|
||||
neVersion.NewPath = neSoftware.Path
|
||||
neVersion.Status = "3"
|
||||
@@ -76,7 +77,9 @@ func (r *NeSoftwareImpl) Update(neSoftware model.NeSoftware) int64 {
|
||||
})
|
||||
if len(neVersions) > 0 {
|
||||
for _, neVersion := range neVersions {
|
||||
neVersion.NewName = neSoftware.Name
|
||||
neVersion.NewVersion = neSoftware.Version
|
||||
neVersion.Status = "3"
|
||||
neVersion.UpdateBy = neSoftware.UpdateBy
|
||||
NewNeVersionImpl.Update(neVersion)
|
||||
}
|
||||
@@ -125,9 +128,7 @@ func (r *NeSoftwareImpl) CheckUniqueTypeAndNameAndVersion(neType, name, version,
|
||||
}
|
||||
|
||||
// InstallToNeHost 安装包上传到网元主机执行安装命令
|
||||
//
|
||||
// action 安装行为:install upgrade
|
||||
func (r *NeSoftwareImpl) InstallToNeHost(action string, neSoftware model.NeSoftware, preinput map[string]string) (string, error) {
|
||||
func (r *NeSoftwareImpl) InstallToNeHost(neSoftware model.NeSoftware, preinput map[string]string) (string, error) {
|
||||
// 检查文件是否存在
|
||||
localFilePath := file.ParseUploadFilePath(neSoftware.Path)
|
||||
if _, err := os.Stat(localFilePath); err != nil {
|
||||
@@ -159,15 +160,20 @@ func (r *NeSoftwareImpl) InstallToNeHost(action string, neSoftware model.NeSoftw
|
||||
}
|
||||
|
||||
// ========= 安装命令 start =========
|
||||
cmdStrArr := []string{}
|
||||
|
||||
// 命令终止结束标记
|
||||
okFlagStr := fmt.Sprintf("%s software %s successful!", neSoftware.NeType, action)
|
||||
okFlagStr := fmt.Sprintf("%s software install successful!", neSoftware.NeType)
|
||||
// 安装软件包
|
||||
cmdStrArr = append(cmdStrArr, fmt.Sprintf("sudo dpkg -i %s \n", neFilePath))
|
||||
pkgCmdStr := fmt.Sprintf("sudo dpkg -i %s \n", neFilePath)
|
||||
fileExt := filepath.Ext(strings.ToLower(fileName))
|
||||
if strings.HasSuffix(fileExt, "rpm") {
|
||||
pkgCmdStr = fmt.Sprintf("sudo rpm -Uvh %s \n", neFilePath)
|
||||
}
|
||||
|
||||
// 预先参数
|
||||
cmdStrArr := []string{pkgCmdStr}
|
||||
if neSoftware.NeType == "IMS" {
|
||||
if !strings.Contains(fileName, "ims") {
|
||||
if !strings.Contains(strings.ToLower(fileName), "ims") {
|
||||
return "", fmt.Errorf("error file package not ims")
|
||||
}
|
||||
// P/I/S-CSCF Config 配置覆盖
|
||||
@@ -187,22 +193,16 @@ func (r *NeSoftwareImpl) InstallToNeHost(action string, neSoftware model.NeSoftw
|
||||
}
|
||||
cmdStrArr = append(cmdStrArr, "sudo ims-start")
|
||||
// 10s后停止服务
|
||||
if action == "install" {
|
||||
cmdStrArr = append(cmdStrArr, "nohup sh -c \"sleep 15s && sudo ims-stop\" > /dev/null 2>&1 & \n")
|
||||
}
|
||||
cmdStrArr = append(cmdStrArr, "nohup sh -c \"sleep 15s && sudo ims-stop\" > /dev/null 2>&1 & \n")
|
||||
} else if neSoftware.NeType == "OMC" {
|
||||
cmdStrArr = append(cmdStrArr, "sudo /usr/local/omc/bin/omcsvc.sh restart \n")
|
||||
// 10s后停止服务
|
||||
if action == "install" {
|
||||
cmdStrArr = append(cmdStrArr, "nohup sh -c \"sleep 15s && sudo /usr/local/omc/bin/omcsvc.sh stop\" > /dev/null 2>&1 & \n")
|
||||
}
|
||||
cmdStrArr = append(cmdStrArr, "nohup sh -c \"sleep 15s && sudo /usr/local/omc/bin/omcsvc.sh stop\" > /dev/null 2>&1 & \n")
|
||||
} else {
|
||||
neTypeLower := strings.ToLower(neSoftware.NeType)
|
||||
cmdStrArr = append(cmdStrArr, fmt.Sprintf("sudo service %s restart \n", neTypeLower))
|
||||
// 10s后停止服务
|
||||
if action == "install" {
|
||||
cmdStrArr = append(cmdStrArr, fmt.Sprintf("nohup sh -c \"sleep 15s && sudo service %s stop\" > /dev/null 2>&1 & \n", neTypeLower))
|
||||
}
|
||||
cmdStrArr = append(cmdStrArr, fmt.Sprintf("nohup sh -c \"sleep 15s && sudo service %s stop\" > /dev/null 2>&1 & \n", neTypeLower))
|
||||
}
|
||||
|
||||
// 删除软件包
|
||||
@@ -269,5 +269,18 @@ func (r *NeSoftwareImpl) InstallToNeHost(action string, neSoftware model.NeSoftw
|
||||
}()
|
||||
// 等待写入协程完成
|
||||
<-done
|
||||
|
||||
// 更新Version
|
||||
neVersion := NewNeVersionImpl.SelectByNeTypeAndNeID(neSoftware.NeType, neSoftware.NeId)
|
||||
if neVersion.NeId == neSoftware.NeId {
|
||||
neVersion.Name = neSoftware.Name
|
||||
neVersion.Version = neSoftware.Version
|
||||
neVersion.Path = neSoftware.Path
|
||||
neVersion.NewName = "-"
|
||||
neVersion.NewVersion = "-"
|
||||
neVersion.NewPath = "-"
|
||||
neVersion.Status = "1"
|
||||
NewNeVersionImpl.Update(neVersion)
|
||||
}
|
||||
return logMsg, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user