diff --git a/backend/app/service/snapshot.go b/backend/app/service/snapshot.go index 31af28af7..0654ebb9a 100644 --- a/backend/app/service/snapshot.go +++ b/backend/app/service/snapshot.go @@ -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 diff --git a/backend/app/service/upgrade.go b/backend/app/service/upgrade.go index d36e99069..5b5c1ba32 100644 --- a/backend/app/service/upgrade.go +++ b/backend/app/service/upgrade.go @@ -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) diff --git a/backend/configs/config.go b/backend/configs/config.go index a4c237ad7..7d8116b68 100644 --- a/backend/configs/config.go +++ b/backend/configs/config.go @@ -1,7 +1,6 @@ package configs type ServerConfig struct { - BaseDir string `mapstructure:"base_dir"` System System `mapstructure:"system"` LogConfig LogConfig `mapstructure:"log"` } diff --git a/backend/init/viper/viper.go b/backend/init/viper/viper.go index 033723946..3172e0764 100644 --- a/backend/init/viper/viper.go +++ b/backend/init/viper/viper.go @@ -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"