diff --git a/.gitignore b/.gitignore index 2a9b8469..9128f999 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,5 @@ /db /manual_log /scripts -/bak \ No newline at end of file +/bak +/.tmp \ No newline at end of file diff --git a/back/api/system.ts b/back/api/system.ts index 5b747ab3..7f84d8be 100644 --- a/back/api/system.ts +++ b/back/api/system.ts @@ -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({ diff --git a/back/data/sock.ts b/back/data/sock.ts index ee7d6b11..12dca74d 100644 --- a/back/data/sock.ts +++ b/back/data/sock.ts @@ -16,4 +16,5 @@ export type SockMessageType = | 'uninstallDependence' | 'updateSystemVersion' | 'manuallyRunScript' - | 'runSubscriptionEnd'; + | 'runSubscriptionEnd' + | 'reloadSystem'; diff --git a/back/services/system.ts b/back/services/system.ts index 108eb928..5cb69581 100644 --- a/back/services/system.ts +++ b/back/services/system.ts @@ -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) { diff --git a/shell/update.sh b/shell/update.sh index 1639dd0b..0f7e834b 100755 --- a/shell/update.sh +++ b/shell/update.sh @@ -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,9 +268,9 @@ 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 else echo -e "\n更新青龙源文件失败,请检查网络...\n" @@ -288,13 +303,16 @@ check_update_dep() { if [[ $exit_status -eq 0 ]]; then echo -e "\n依赖检测安装成功...\n" + echo -e "\n更新包下载成功...\n" - 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 + 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 + 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 ;; diff --git a/src/pages/setting/checkUpdate.tsx b/src/pages/setting/checkUpdate.tsx index 64c0254f..c05bc81a 100644 --- a/src/pages/setting/checkUpdate.tsx +++ b/src/pages/setting/checkUpdate.tsx @@ -47,7 +47,7 @@ const CheckUpdate = ({ socketMessage, systemInfo }: any) => { ), - okText: '强制更新', + okText: '重新下载', onOk() { showUpdatingModal(); request @@ -82,7 +82,7 @@ const CheckUpdate = ({ socketMessage, systemInfo }: any) => { {lastLog} ), - 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: (
 {
     });
   };
 
+  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: (
+                
+                  系统将在
+                  
+                  秒后自动刷新
+                
+              ),
+              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: (
-          
-            系统将在
-            
-            秒后自动刷新
-          
-        ),
-        duration: 30,
-      });
+    if (_message.includes('更新包下载成功')) {
       setTimeout(() => {
-        window.location.reload();
-      }, 30000);
+        showReloadModal();
+      }, 1000);
     }
   }, [socketMessage]);