| | |
| | | |
| | | //upgrade |
| | | func (sv SysService) Upgrade(identifier string,filename string) (bool,error) { |
| | | if !bakBeforeUpgrade() { |
| | | return false,errors.New("更新前备份失败") |
| | | } |
| | | configPatchPath := "" |
| | | if config.Server.PatchPath != "" { |
| | | configPatchPath = config.Server.PatchPath |
| | |
| | | } else { |
| | | return false,errors.New("升级文件已丢失,请重新上传") |
| | | } |
| | | } |
| | | |
| | | func bakBeforeUpgrade() bool { |
| | | configBakPath := "" |
| | | if config.Server.BakPath != "" { |
| | | configBakPath = config.Server.BakPath |
| | | } else { |
| | | configBakPath = "/opt/vasystem/bak" |
| | | } |
| | | if util.Exists(configBakPath) { |
| | | //只保留最新的版本 |
| | | if err := os.RemoveAll(configBakPath);err != nil { |
| | | return false |
| | | } |
| | | } |
| | | if !util.CreateDirectory(configBakPath) { |
| | | return false |
| | | } |
| | | b, err := ExecCmd("cp /opt/vasystem/bin /opt/vasystem/bak") |
| | | logger.Debug("bakBeforeUpgrade result:",string(b)) |
| | | if err != nil { |
| | | return false |
| | | } |
| | | return true |
| | | } |
| | | |
| | | //更新系统程序 |
| | |
| | | logger.Debug("mergeChunks result:",string(b),"cmd: ./mergeAll.sh ", chunkPath, storePath) |
| | | return true |
| | | } |
| | | } |
| | | |
| | | func ExecCmd(cmdStr string) ([]byte,error) { |
| | | var cmd *exec.Cmd |
| | | cmd = exec.Command("/bin/sh", "-c",cmdStr) |
| | | return cmd.Output() |
| | | } |