|
|
@@ -174,8 +174,9 @@ func (p *program) upgradeService(service serviceUpgradeConfig) (string, string,
|
|
|
return "", "", false, fmt.Errorf("获取当前版本目录失败: %w", err)
|
|
|
}
|
|
|
|
|
|
- targetName := nextVersionDir(currentDir)
|
|
|
- targetDir := filepath.Join(service.InstallPath, targetName)
|
|
|
+ targetVersion := nextVersionDir(currentDir)
|
|
|
+ targetDir := filepath.Join(service.InstallPath, targetVersion)
|
|
|
+ targetName := filepath.Join(targetVersion, service.Name)
|
|
|
pkg := filepath.Join(os.TempDir(), service.Name+".tar.gz")
|
|
|
defer os.Remove(pkg)
|
|
|
|
|
|
@@ -248,10 +249,10 @@ func getCurrentVersionDir(installPath string, serviceName string) (string, error
|
|
|
|
|
|
target = filepath.Clean(target)
|
|
|
|
|
|
- name := filepath.Base(target)
|
|
|
+ name := filepath.Base(filepath.Dir(target))
|
|
|
switch name {
|
|
|
case "a", "b", "c":
|
|
|
- return target, nil
|
|
|
+ return filepath.Join(installPath, name), nil
|
|
|
default:
|
|
|
return "", fmt.Errorf("当前软链接指向无效的版本目录: %s", target)
|
|
|
}
|
|
|
@@ -286,9 +287,14 @@ func installPackage(pkg string, targetDir string, service serviceUpgradeConfig)
|
|
|
}
|
|
|
|
|
|
program := filepath.Join(tempDir, service.Name)
|
|
|
- if _, err := os.Stat(program); err != nil {
|
|
|
+
|
|
|
+ info, err := os.Stat(program)
|
|
|
+ if err != nil {
|
|
|
return fmt.Errorf("检查%s服务程序失败: %w", service.Name, err)
|
|
|
}
|
|
|
+ if info.IsDir() || info.Size() == 0 || info.Mode().Perm()&0111 == 0 {
|
|
|
+ return fmt.Errorf("检查%s服务程序失败: 文件异常", service.Name)
|
|
|
+ }
|
|
|
|
|
|
if err := os.RemoveAll(targetDir); err != nil {
|
|
|
return fmt.Errorf("清理%s版本目录失败: %w", service.Name, err)
|
|
|
@@ -373,11 +379,13 @@ func switchServiceVersion(serviceName string, installPath string, targetName str
|
|
|
_ = os.Remove(tempLink)
|
|
|
|
|
|
if err := os.Symlink(targetName, tempLink); err != nil {
|
|
|
+ exec.Command("systemctl", "start", service).Run()
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
if err := os.Rename(tempLink, currentLink); err != nil {
|
|
|
_ = os.Remove(tempLink)
|
|
|
+ exec.Command("systemctl", "start", service).Run()
|
|
|
return err
|
|
|
}
|
|
|
|