fix: 升级 1pctl 被覆盖后,手动替换 BASE_DIR

This commit is contained in:
ssongliu 2023-03-14 21:55:28 +08:00 committed by ssongliu
parent fb5c3429e5
commit 42e522abe1
4 changed files with 14 additions and 8 deletions

View File

@ -172,17 +172,17 @@ func (u *SnapshotService) SnapshotCreate(req dto.SnapshotCreate) error {
return
}
if err := u.handlePanelDatas(snap.ID, fileOp, "snapshot", global.CONF.BaseDir+"/1panel", backupPanelDir, localDir, dockerDataDir); err != nil {
if err := u.handlePanelDatas(snap.ID, fileOp, "snapshot", global.CONF.System.BaseDir+"/1panel", backupPanelDir, localDir, dockerDataDir); err != nil {
updateSnapshotStatus(snap.ID, constant.StatusFailed, err.Error())
return
}
_, _ = cmd.Exec("systemctl restart docker")
snapJson := SnapshotJson{
BaseDir: global.CONF.BaseDir,
BaseDir: global.CONF.System.BaseDir,
DockerDataDir: dockerDataDir,
BackupDataDir: localDir,
PanelDataDir: global.CONF.BaseDir + "/1panel",
PanelDataDir: global.CONF.System.BaseDir + "/1panel",
LiveRestoreEnabled: liveRestoreStatus,
}
if err := u.saveJson(snapJson, rootDir); err != nil {
@ -287,8 +287,8 @@ func (u *SnapshotService) SnapshotRecover(req dto.SnapshotRecover) error {
u.OriginalPath = fmt.Sprintf("%s/original_%s", snapJson.BaseDir, snap.Name)
_ = os.MkdirAll(u.OriginalPath, os.ModePerm)
snapJson.OldBaseDir = global.CONF.BaseDir
snapJson.OldPanelDataDir = global.CONF.BaseDir + "/1panel"
snapJson.OldBaseDir = global.CONF.System.BaseDir
snapJson.OldPanelDataDir = global.CONF.System.BaseDir + "/1panel"
snapJson.OldBackupDataDir = localDir
recoverPanelDir := fmt.Sprintf("%s/%s/1panel", baseDir, snap.Name)
liveRestore := false

View File

@ -109,11 +109,18 @@ func (u *UpgradeService) Upgrade(req dto.Upgrade) error {
global.LOG.Errorf("upgrade 1panel failed, err: %v", err)
return
}
if err := cpBinary(tmpDir+"/1pctl", "/usr/local/bin/1pctl"); err != nil {
u.handleRollback(fileOp, originalDir, 2)
global.LOG.Errorf("upgrade 1pctl failed, err: %v", err)
return
}
if _, err := cmd.Execf("sed -i -e 's#BASE_DIR=.*#BASE_DIR=%s#g' /usr/local/bin/1pctl", global.CONF.System.BaseDir); err != nil {
u.handleRollback(fileOp, originalDir, 2)
global.LOG.Errorf("upgrade basedir in 1pctl failed, err: %v", err)
return
}
if err := cpBinary(tmpDir+"/1panel.service", "/etc/systemd/system/1panel.service"); err != nil {
u.handleRollback(fileOp, originalDir, 3)
global.LOG.Errorf("upgrade 1panel.service failed, err: %v", err)

View File

@ -1,7 +1,6 @@
package configs
type ServerConfig struct {
BaseDir string `mapstructure:"base_dir"`
System System `mapstructure:"system"`
LogConfig LogConfig `mapstructure:"log"`
}

View File

@ -71,9 +71,9 @@ func Init() {
}
global.CONF = serverConfig
global.CONF.BaseDir = baseDir
global.CONF.System.BaseDir = baseDir
global.CONF.System.IsDemo = v.GetBool("system.is_demo")
global.CONF.System.DataDir = global.CONF.BaseDir + "/1panel"
global.CONF.System.DataDir = global.CONF.System.BaseDir + "/1panel"
global.CONF.System.Cache = global.CONF.System.DataDir + "/cache"
global.CONF.System.Backup = global.CONF.System.DataDir + "/backup"
global.CONF.System.DbPath = global.CONF.System.DataDir + "/db"