Skip to content

Commit

Permalink
fix: 升级 1pctl 被覆盖后,手动替换 BASE_DIR
Browse files Browse the repository at this point in the history
  • Loading branch information
ssongliu committed Mar 14, 2023
1 parent fb5c342 commit 42e522a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
10 changes: 5 additions & 5 deletions backend/app/service/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions backend/app/service/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion backend/configs/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package configs

type ServerConfig struct {
BaseDir string `mapstructure:"base_dir"`
System System `mapstructure:"system"`
LogConfig LogConfig `mapstructure:"log"`
}
4 changes: 2 additions & 2 deletions backend/init/viper/viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 42e522a

Please sign in to comment.