修改系统内更新系统逻辑

This commit is contained in:
whyour 2023-07-13 22:09:45 +08:00
parent 936b565fb1
commit 8affff96f3
6 changed files with 125 additions and 31 deletions

3
.gitignore vendored
View File

@ -28,4 +28,5 @@
/db /db
/manual_log /manual_log
/scripts /scripts
/bak /bak
/.tmp

View File

@ -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( route.put(
'/notify', '/notify',
celebrate({ celebrate({

View File

@ -16,4 +16,5 @@ export type SockMessageType =
| 'uninstallDependence' | 'uninstallDependence'
| 'updateSystemVersion' | 'updateSystemVersion'
| 'manuallyRunScript' | 'manuallyRunScript'
| 'runSubscriptionEnd'; | 'runSubscriptionEnd'
| 'reloadSystem';

View File

@ -154,7 +154,7 @@ export default class SystemService {
} }
public async updateSystem() { 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) => { cp.stdout.on('data', (data) => {
this.sockService.sendMessage({ this.sockService.sendMessage({
@ -180,6 +180,33 @@ export default class SystemService {
return { code: 200 }; 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 }) { public async notify({ title, content }: { title: string; content: string }) {
const isSuccess = await this.notificationService.notify(title, content); const isSuccess = await this.notificationService.notify(title, content);
if (isSuccess) { if (isSuccess) {

View File

@ -229,9 +229,24 @@ usage() {
echo -e "9. $cmd_update resettfa # 禁用两步登录" 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 ## 更新qinglong
update_qinglong() { update_qinglong() {
rm -rf ${dir_tmp}/* rm -rf ${dir_tmp}/*
local needRestart=${1:-"true"}
local mirror="gitee" local mirror="gitee"
local downloadQLUrl="https://gitee.com/whyour/qinglong/repository/archive" local downloadQLUrl="https://gitee.com/whyour/qinglong/repository/archive"
local downloadStaticUrl="https://gitee.com/whyour/qinglong-static/repository/archive" local downloadStaticUrl="https://gitee.com/whyour/qinglong-static/repository/archive"
@ -253,9 +268,9 @@ update_qinglong() {
if [[ $exit_status -eq 0 ]]; then if [[ $exit_status -eq 0 ]]; then
echo -e "\n更新青龙源文件成功...\n" echo -e "\n更新青龙源文件成功...\n"
cd
unzip -oq ${dir_tmp}/ql.zip -d ${dir_tmp} unzip -oq ${dir_tmp}/ql.zip -d ${dir_tmp}
update_qinglong_static update_qinglong_static
else else
echo -e "\n更新青龙源文件失败请检查网络...\n" echo -e "\n更新青龙源文件失败请检查网络...\n"
@ -288,13 +303,16 @@ check_update_dep() {
if [[ $exit_status -eq 0 ]]; then if [[ $exit_status -eq 0 ]]; then
echo -e "\n依赖检测安装成功...\n" echo -e "\n依赖检测安装成功...\n"
echo -e "\n更新包下载成功...\n"
cp -rf ${dir_tmp}/qinglong-${primary_branch}/* ${dir_root}/ if [[ "$needRestart" == 'true' ]]; then
rm -rf $dir_static/* cp -rf ${dir_tmp}/qinglong-${primary_branch}/* ${dir_root}/
cp -rf ${dir_tmp}/qinglong-static-${primary_branch}/* ${dir_static}/ rm -rf $dir_static/*
cp -f $file_config_sample $dir_config/config.sample.sh cp -rf ${dir_tmp}/qinglong-static-${primary_branch}/* ${dir_static}/
cp -f $file_config_sample $dir_config/config.sample.sh
reload_pm2 reload_pm2
fi
else else
echo -e "\n依赖检测安装失败请检查网络...\n" echo -e "\n依赖检测安装失败请检查网络...\n"
fi fi
@ -474,6 +492,9 @@ main() {
fix_config fix_config
eval update_qinglong "$2" $cmd eval update_qinglong "$2" $cmd
;; ;;
reload)
eval reload_qinglong $cmd
;;
extra) extra)
eval run_extra_shell $cmd eval run_extra_shell $cmd
;; ;;

View File

@ -47,7 +47,7 @@ const CheckUpdate = ({ socketMessage, systemInfo }: any) => {
</div> </div>
</> </>
), ),
okText: '强制更新', okText: '重新下载',
onOk() { onOk() {
showUpdatingModal(); showUpdatingModal();
request request
@ -82,7 +82,7 @@ const CheckUpdate = ({ socketMessage, systemInfo }: any) => {
{lastLog} {lastLog}
</pre> </pre>
), ),
okText: '更新', okText: '下载更新',
cancelText: '以后再说', cancelText: '以后再说',
onOk() { onOk() {
showUpdatingModal(); showUpdatingModal();
@ -104,7 +104,7 @@ const CheckUpdate = ({ socketMessage, systemInfo }: any) => {
closable: false, closable: false,
keyboard: false, keyboard: false,
okButtonProps: { disabled: true }, okButtonProps: { disabled: true },
title: '更新中...', title: '下载更新中...',
centered: true, centered: true,
content: ( content: (
<pre <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(() => { useEffect(() => {
if (!modalRef.current || !socketMessage) { if (!modalRef.current || !socketMessage) {
return; return;
@ -130,7 +174,7 @@ const CheckUpdate = ({ socketMessage, systemInfo }: any) => {
} }
const newMessage = `${value}${_message}`; const newMessage = `${value}${_message}`;
const updateFailed = newMessage.includes('失败,请检查'); const updateFailed = newMessage.includes('失败');
modalRef.current.update({ modalRef.current.update({
maskClosable: updateFailed, maskClosable: updateFailed,
@ -162,24 +206,10 @@ const CheckUpdate = ({ socketMessage, systemInfo }: any) => {
.getElementById('log-identifier')! .getElementById('log-identifier')!
.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); .scrollIntoView({ behavior: 'smooth', block: 'nearest' });
if (_message.includes('重启面板')) { if (_message.includes('更新包下载成功')) {
message.warning({
content: (
<span>
<Countdown
className="inline-countdown"
format="ss"
value={Date.now() + 1000 * 30}
/>
</span>
),
duration: 30,
});
setTimeout(() => { setTimeout(() => {
window.location.reload(); showReloadModal();
}, 30000); }, 1000);
} }
}, [socketMessage]); }, [socketMessage]);