fix: 数据库状态不正常时,禁用部分设置

This commit is contained in:
ssongliu 2022-12-12 19:04:45 +08:00 committed by ssongliu
parent 23996b25c3
commit 5272d44558
10 changed files with 74 additions and 58 deletions

View File

@ -263,19 +263,7 @@ func (a AppInstallService) GetUpdateVersions(installId uint) ([]dto.AppVersion,
}
func (a AppInstallService) ChangeAppPort(req dto.PortUpdate) error {
ComposeFile := fmt.Sprintf("%s/%s/%s/docker-compose.yml", constant.AppInstallDir, req.Key, req.Name)
updateInstallInfoInDB(req.Key, "port", strconv.FormatInt(req.Port, 10))
stdout, err := compose.Down(ComposeFile)
if err != nil {
return errors.New(stdout)
}
stdout, err = compose.Up(ComposeFile)
if err != nil {
return errors.New(stdout)
}
return nil
return updateInstallInfoInDB(req.Key, "port", true, strconv.FormatInt(req.Port, 10))
}
func (a AppInstallService) DeleteCheck(installId uint) ([]dto.AppResource, error) {
@ -447,18 +435,18 @@ func syncById(installId uint) error {
return appInstallRepo.Save(&appInstall)
}
func updateInstallInfoInDB(appKey, param string, value interface{}) {
func updateInstallInfoInDB(appKey, param string, isRestart bool, value interface{}) error {
if param != "password" && param != "port" {
return
return nil
}
appInstall, err := appInstallRepo.LoadBaseInfoByKey(appKey)
if err != nil {
return
return nil
}
envPath := fmt.Sprintf("%s/%s/%s/.env", constant.AppInstallDir, appKey, appInstall.Name)
lineBytes, err := ioutil.ReadFile(envPath)
if err != nil {
return
return err
}
envKey := "PANEL_DB_ROOT_PASSWORD="
if param == "port" {
@ -475,12 +463,12 @@ func updateInstallInfoInDB(appKey, param string, value interface{}) {
}
file, err := os.OpenFile(envPath, os.O_WRONLY|os.O_TRUNC, 0666)
if err != nil {
return
return err
}
defer file.Close()
_, err = file.WriteString(strings.Join(newFiles, "\n"))
if err != nil {
return
return err
}
oldVal, newVal := "", ""
@ -502,4 +490,15 @@ func updateInstallInfoInDB(appKey, param string, value interface{}) {
"http_port": value,
}, commonRepo.WithByID(appInstall.ID))
}
ComposeFile := fmt.Sprintf("%s/%s/%s/docker-compose.yml", constant.AppInstallDir, appKey, appInstall.Name)
stdout, err := compose.Down(ComposeFile)
if err != nil {
return errors.New(stdout)
}
stdout, err = compose.Up(ComposeFile)
if err != nil {
return errors.New(stdout)
}
return nil
}

View File

@ -330,8 +330,12 @@ func (u *MysqlService) ChangePassword(info dto.ChangeDBInfo) error {
}
}
}
updateInstallInfoInDB("mysql", "password", info.Value)
updateInstallInfoInDB("phpmyadmin", "password", info.Value)
if err := updateInstallInfoInDB("mysql", "password", false, info.Value); err != nil {
return err
}
if err := updateInstallInfoInDB("phpmyadmin", "password", true, info.Value); err != nil {
return err
}
return nil
}

View File

@ -63,22 +63,11 @@ func (u *RedisService) UpdateConf(req dto.RedisConfUpdate) error {
}
func (u *RedisService) ChangePassword(req dto.ChangeDBInfo) error {
redisInfo, err := appInstallRepo.LoadBaseInfoByKey("redis")
if err != nil {
if err := updateInstallInfoInDB("redis", "password", true, req.Value); err != nil {
return err
}
ComposeFile := fmt.Sprintf("%s/redis/%s/docker-compose.yml", constant.AppInstallDir, redisInfo.Name)
updateInstallInfoInDB("redis", "password", req.Value)
updateInstallInfoInDB("redis-commander", "password", req.Value)
stdout, err := compose.Down(ComposeFile)
if err != nil {
return errors.New(stdout)
}
stdout, err = compose.Up(ComposeFile)
if err != nil {
return errors.New(stdout)
if err := updateInstallInfoInDB("redis-commander", "password", true, req.Value); err != nil {
return err
}
return nil

View File

@ -23,7 +23,7 @@ export const updateMysqlAccess = (params: Database.ChangeInfo) => {
return http.post(`/databases/change/access`, params);
};
export const updateMysqlPassword = (params: Database.ChangeInfo) => {
return http.post(`/databases/change/[password]`, params);
return http.post(`/databases/change/password`, params);
};
export const updateMysqlVariables = (params: Array<Database.VariablesUpdate>) => {
return http.post(`/databases/variables/update`, params);

View File

@ -74,6 +74,7 @@ export default {
updateSuccess: 'Update Success',
uploadSuccess: 'Update Success',
operate: 'Operate',
inputOrSelect: 'Please select or enter',
},
login: {
firstLogin: 'First login, please create an initial administrator user!',

View File

@ -76,6 +76,7 @@ export default {
uploadSuccess: '上传成功',
operate: '操作',
operateConfirm: '如果确认操作请手动输入',
inputOrSelect: '请选择或输入',
},
login: {
firstLogin: '首次登录请创建初始管理员用户',

View File

@ -119,6 +119,7 @@
style="width: 100%"
allow-create
clearable
:placeholder="$t('commons.msg.inputOrSelect')"
filterable
v-model="row.sourceDir"
>

View File

@ -22,10 +22,18 @@
{{ $t('commons.button.save') }}
</el-button>
</el-collapse-item>
<el-collapse-item :title="$t('database.currentStatus')" name="2">
<el-collapse-item
:disabled="mysqlStatus !== 'Running'"
:title="$t('database.currentStatus')"
name="2"
>
<Status ref="statusRef" />
</el-collapse-item>
<el-collapse-item :title="$t('database.performanceTuning')" name="3">
<el-collapse-item
:disabled="mysqlStatus !== 'Running'"
:title="$t('database.performanceTuning')"
name="3"
>
<Variables ref="variablesRef" />
</el-collapse-item>
<el-collapse-item :title="$t('database.portSetting')" name="4">
@ -50,7 +58,7 @@
<ContainerLog ref="dialogContainerLogRef" />
</el-collapse-item>
<el-collapse-item :title="$t('database.slowLog')" name="6">
<el-collapse-item :disabled="mysqlStatus !== 'Running'" :title="$t('database.slowLog')" name="6">
<SlowLog ref="slowLogRef" />
</el-collapse-item>
</el-collapse>

View File

@ -11,14 +11,21 @@
v-model:loading="loading"
></AppStatus>
<el-button style="margin-top: 20px" type="primary" plain @click="goDashboard" icon="Position">
Redis-Commander
</el-button>
<Setting ref="settingRef" style="margin-top: 10px" />
<div v-show="redisIsExist">
<el-button style="margin-top: 20px" type="primary" plain @click="goDashboard" icon="Position">
Redis-Commander
<el-card width="30%" v-if="redisStatus != 'Running' && !isOnSetting && redisIsExist" class="mask-prompt">
<span style="font-size: 14px">{{ $t('database.mysqlBadStatus') }}</span>
<el-button type="primary" link style="font-size: 14px; margin-bottom: 5px" @click="onSetting">
{{ $t('database.setting') }}
</el-button>
<Terminal style="margin-top: 10px" v-show="!isOnSetting" ref="terminalRef" />
<span style="font-size: 14px">{{ $t('database.adjust') }}</span>
</el-card>
<div v-show="redisIsExist" :class="{ mask: redisStatus != 'Running' }">
<Terminal style="margin-top: 10px" ref="terminalRef" />
</div>
<el-dialog
@ -58,7 +65,7 @@ const terminalRef = ref();
const settingRef = ref();
const isOnSetting = ref(false);
const redisIsExist = ref(false);
const redisSattus = ref();
const redisStatus = ref();
const redisCommandPort = ref();
const commandVisiable = ref(false);
@ -66,7 +73,7 @@ const commandVisiable = ref(false);
const onSetting = async () => {
isOnSetting.value = true;
terminalRef.value.onClose();
settingRef.value!.acceptParams({ status: redisSattus.value });
settingRef.value!.acceptParams({ status: redisStatus.value });
};
const goRouter = async (path: string) => {
@ -90,9 +97,9 @@ const loadDashboardPort = async () => {
const checkExist = (data: App.CheckInstalled) => {
redisIsExist.value = data.isExist;
redisSattus.value = data.status;
redisStatus.value = data.status;
loading.value = false;
if (redisIsExist.value) {
if (redisStatus.value === 'Running') {
loadDashboardPort();
terminalRef.value.acceptParams();
}

View File

@ -74,20 +74,19 @@
v-model="redisConf"
:readOnly="true"
/>
<el-button
type="primary"
size="default"
@click="onSaveFile"
style="width: 90px; margin-top: 5px"
>
<el-button type="primary" @click="onSaveFile" style="margin-top: 5px">
{{ $t('commons.button.save') }}
</el-button>
</div>
</el-collapse-item>
<el-collapse-item :title="$t('database.status')" name="2">
<el-collapse-item :disabled="redisStatus !== 'Running'" :title="$t('database.status')" name="2">
<Status ref="statusRef" />
</el-collapse-item>
<el-collapse-item :title="$t('database.persistence')" name="3">
<el-collapse-item
:disabled="redisStatus !== 'Running'"
:title="$t('database.persistence')"
name="3"
>
<Persistence ref="persistenceRef" />
</el-collapse-item>
</el-collapse>
@ -275,8 +274,15 @@ const onSubmitSave = async () => {
file: redisConf.value,
restartNow: true,
};
await updateRedisConfByFile(param);
ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
loading.value = true;
await updateRedisConfByFile(param)
.then(() => {
loading.value = false;
ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
})
.catch(() => {
loading.value = true;
});
};
const loadform = async () => {