mirror of
https://github.com/whyour/qinglong.git
synced 2025-07-07 03:46:07 +08:00
修改系统内更新系统逻辑
This commit is contained in:
parent
936b565fb1
commit
8affff96f3
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -29,3 +29,4 @@
|
|||
/manual_log
|
||||
/scripts
|
||||
/bak
|
||||
/.tmp
|
|
@ -116,6 +116,20 @@ export default (app: Router) => {
|
|||
},
|
||||
);
|
||||
|
||||
route.put(
|
||||
'/reload',
|
||||
async (req: Request, res: Response, next: NextFunction) => {
|
||||
const logger: Logger = Container.get('logger');
|
||||
try {
|
||||
const systemService = Container.get(SystemService);
|
||||
const result = await systemService.reloadSystem();
|
||||
res.send(result);
|
||||
} catch (e) {
|
||||
return next(e);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
route.put(
|
||||
'/notify',
|
||||
celebrate({
|
||||
|
|
|
@ -16,4 +16,5 @@ export type SockMessageType =
|
|||
| 'uninstallDependence'
|
||||
| 'updateSystemVersion'
|
||||
| 'manuallyRunScript'
|
||||
| 'runSubscriptionEnd';
|
||||
| 'runSubscriptionEnd'
|
||||
| 'reloadSystem';
|
||||
|
|
|
@ -154,7 +154,7 @@ export default class SystemService {
|
|||
}
|
||||
|
||||
public async updateSystem() {
|
||||
const cp = spawn('ql -l update', { shell: '/bin/bash' });
|
||||
const cp = spawn('ql -l update false', { shell: '/bin/bash' });
|
||||
|
||||
cp.stdout.on('data', (data) => {
|
||||
this.sockService.sendMessage({
|
||||
|
@ -180,6 +180,33 @@ export default class SystemService {
|
|||
return { code: 200 };
|
||||
}
|
||||
|
||||
public async reloadSystem() {
|
||||
const cp = spawn('ql -l reload', { shell: '/bin/bash' });
|
||||
|
||||
cp.stdout.on('data', (data) => {
|
||||
this.sockService.sendMessage({
|
||||
type: 'reloadSystem',
|
||||
message: data.toString(),
|
||||
});
|
||||
});
|
||||
|
||||
cp.stderr.on('data', (data) => {
|
||||
this.sockService.sendMessage({
|
||||
type: 'reloadSystem',
|
||||
message: data.toString(),
|
||||
});
|
||||
});
|
||||
|
||||
cp.on('error', (err) => {
|
||||
this.sockService.sendMessage({
|
||||
type: 'reloadSystem',
|
||||
message: JSON.stringify(err),
|
||||
});
|
||||
});
|
||||
|
||||
return { code: 200 };
|
||||
}
|
||||
|
||||
public async notify({ title, content }: { title: string; content: string }) {
|
||||
const isSuccess = await this.notificationService.notify(title, content);
|
||||
if (isSuccess) {
|
||||
|
|
|
@ -229,9 +229,24 @@ usage() {
|
|||
echo -e "9. $cmd_update resettfa # 禁用两步登录"
|
||||
}
|
||||
|
||||
reload_qinglong() {
|
||||
local primary_branch="master"
|
||||
if [[ "${QL_BRANCH}" == "develop" ]]; then
|
||||
primary_branch="develop"
|
||||
fi
|
||||
|
||||
cp -rf ${dir_tmp}/qinglong-${primary_branch}/* ${dir_root}/
|
||||
rm -rf $dir_static/*
|
||||
cp -rf ${dir_tmp}/qinglong-static-${primary_branch}/* ${dir_static}/
|
||||
cp -f $file_config_sample $dir_config/config.sample.sh
|
||||
|
||||
reload_pm2
|
||||
}
|
||||
|
||||
## 更新qinglong
|
||||
update_qinglong() {
|
||||
rm -rf ${dir_tmp}/*
|
||||
local needRestart=${1:-"true"}
|
||||
local mirror="gitee"
|
||||
local downloadQLUrl="https://gitee.com/whyour/qinglong/repository/archive"
|
||||
local downloadStaticUrl="https://gitee.com/whyour/qinglong-static/repository/archive"
|
||||
|
@ -253,7 +268,7 @@ update_qinglong() {
|
|||
|
||||
if [[ $exit_status -eq 0 ]]; then
|
||||
echo -e "\n更新青龙源文件成功...\n"
|
||||
cd
|
||||
|
||||
unzip -oq ${dir_tmp}/ql.zip -d ${dir_tmp}
|
||||
|
||||
update_qinglong_static
|
||||
|
@ -288,13 +303,16 @@ check_update_dep() {
|
|||
|
||||
if [[ $exit_status -eq 0 ]]; then
|
||||
echo -e "\n依赖检测安装成功...\n"
|
||||
echo -e "\n更新包下载成功...\n"
|
||||
|
||||
if [[ "$needRestart" == 'true' ]]; then
|
||||
cp -rf ${dir_tmp}/qinglong-${primary_branch}/* ${dir_root}/
|
||||
rm -rf $dir_static/*
|
||||
cp -rf ${dir_tmp}/qinglong-static-${primary_branch}/* ${dir_static}/
|
||||
cp -f $file_config_sample $dir_config/config.sample.sh
|
||||
|
||||
reload_pm2
|
||||
fi
|
||||
else
|
||||
echo -e "\n依赖检测安装失败,请检查网络...\n"
|
||||
fi
|
||||
|
@ -474,6 +492,9 @@ main() {
|
|||
fix_config
|
||||
eval update_qinglong "$2" $cmd
|
||||
;;
|
||||
reload)
|
||||
eval reload_qinglong $cmd
|
||||
;;
|
||||
extra)
|
||||
eval run_extra_shell $cmd
|
||||
;;
|
||||
|
|
|
@ -47,7 +47,7 @@ const CheckUpdate = ({ socketMessage, systemInfo }: any) => {
|
|||
</div>
|
||||
</>
|
||||
),
|
||||
okText: '强制更新',
|
||||
okText: '重新下载',
|
||||
onOk() {
|
||||
showUpdatingModal();
|
||||
request
|
||||
|
@ -82,7 +82,7 @@ const CheckUpdate = ({ socketMessage, systemInfo }: any) => {
|
|||
{lastLog}
|
||||
</pre>
|
||||
),
|
||||
okText: '更新',
|
||||
okText: '下载更新',
|
||||
cancelText: '以后再说',
|
||||
onOk() {
|
||||
showUpdatingModal();
|
||||
|
@ -104,7 +104,7 @@ const CheckUpdate = ({ socketMessage, systemInfo }: any) => {
|
|||
closable: false,
|
||||
keyboard: false,
|
||||
okButtonProps: { disabled: true },
|
||||
title: '更新中...',
|
||||
title: '下载更新中...',
|
||||
centered: true,
|
||||
content: (
|
||||
<pre
|
||||
|
@ -119,6 +119,50 @@ const CheckUpdate = ({ socketMessage, systemInfo }: any) => {
|
|||
});
|
||||
};
|
||||
|
||||
const showReloadModal = () => {
|
||||
Modal.confirm({
|
||||
width: 600,
|
||||
maskClosable: false,
|
||||
title: '确认重启',
|
||||
centered: true,
|
||||
content: '系统安装包下载成功,确认重启',
|
||||
okText: '重启',
|
||||
onOk() {
|
||||
request
|
||||
.put(`${config.apiPrefix}system/reload`)
|
||||
.then((_data: any) => {
|
||||
message.warning({
|
||||
content: (
|
||||
<span>
|
||||
系统将在
|
||||
<Countdown
|
||||
className="inline-countdown"
|
||||
format="ss"
|
||||
value={Date.now() + 1000 * 15}
|
||||
/>
|
||||
秒后自动刷新
|
||||
</span>
|
||||
),
|
||||
duration: 15,
|
||||
});
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 14);
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
onCancel() {
|
||||
modalRef.current.update({
|
||||
maskClosable: true,
|
||||
closable: true,
|
||||
okButtonProps: { disabled: false },
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!modalRef.current || !socketMessage) {
|
||||
return;
|
||||
|
@ -130,7 +174,7 @@ const CheckUpdate = ({ socketMessage, systemInfo }: any) => {
|
|||
}
|
||||
|
||||
const newMessage = `${value}${_message}`;
|
||||
const updateFailed = newMessage.includes('失败,请检查');
|
||||
const updateFailed = newMessage.includes('失败');
|
||||
|
||||
modalRef.current.update({
|
||||
maskClosable: updateFailed,
|
||||
|
@ -162,24 +206,10 @@ const CheckUpdate = ({ socketMessage, systemInfo }: any) => {
|
|||
.getElementById('log-identifier')!
|
||||
.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
||||
|
||||
if (_message.includes('重启面板')) {
|
||||
message.warning({
|
||||
content: (
|
||||
<span>
|
||||
系统将在
|
||||
<Countdown
|
||||
className="inline-countdown"
|
||||
format="ss"
|
||||
value={Date.now() + 1000 * 30}
|
||||
/>
|
||||
秒后自动刷新
|
||||
</span>
|
||||
),
|
||||
duration: 30,
|
||||
});
|
||||
if (_message.includes('更新包下载成功')) {
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 30000);
|
||||
showReloadModal();
|
||||
}, 1000);
|
||||
}
|
||||
}, [socketMessage]);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user