浏览代码

#IQRV #comment [Script] 添加重启搜狗输入法服务的操作

gifur 4 年之前
父节点
当前提交
8b2c63d63f

+ 3 - 3
Module/include/CommEntityUtil.hpp

@@ -348,7 +348,7 @@ static bool ShelllExecute(const std::string& cmd, std::string& succResult, std::
 {
     char buf_ps[1024];
     char ps[1024] = { 0 };
-    char result[1024] = { 0 };
+    char result[1025] = { 0 };
     FILE* ptr;
     
     strcpy(ps, cmd.c_str());
@@ -356,9 +356,9 @@ static bool ShelllExecute(const std::string& cmd, std::string& succResult, std::
 
     if ((ptr = popen(ps, "r")) != NULL) {
         while (fgets(buf_ps, 1024, ptr) != NULL) {
-            strcat(result, buf_ps);
-            if (strlen(result) > 1024)
+            if(strlen(result) + strlen(buf_ps) > 1024)
                 break;
+            strcat(result, buf_ps);
         }
         pclose(ptr);
         succResult = result;

+ 5 - 0
Module/include/EventCode.h

@@ -712,6 +712,11 @@ ERR_ACCESSAUTH_SHA1_HASH}
 #define LOG_EVT_USB_LIGHT_ON 0x21400004
 #define LOG_EVT_USB_LIGHT_OFF 0x21400005
 #define LOG_DEVICECONTROL_BROWSER_CACHE_CLEAER 0x21400006
+#define LOG_DEVICECONTROL_SOGOU_SCRIPTS_NOT_EXISTS 0x21400007
+#define LOG_DEVICECONTROL_SOGOU_SCRIPTS_EXECUTE_SUCC 0x21400008
+#define LOG_DEVICECONTROL_SOGOU_SCRIPTS_EXECUTE_FAILED 0x21400009
+
+
 //#define LOG_ERR_DEVICECONTROL_RESTART 0x21480001
 
 #define Sensors_Public_Start					0x21E90000

+ 101 - 0
Module/mod_DeviceControl/DeviceControlFSM.cpp

@@ -3,6 +3,8 @@
 #include "GetDevInfoHelper.h"
 #include "EventCode.h"
 #include "fileutil.h"
+#include "toolkit.h"
+#include "CommEntityUtil.hpp"
 
 #if defined(RVC_OS_WIN)
 static const char DEFAULT_ADAPTER_LIBRARY_NAME[] = "DeviceControl.cmbsz.1.1.dll";
@@ -123,6 +125,7 @@ ErrorCodeEnum CDeviceControlFSM::OnInit()
 	}
 
 	DoBrowserCacheClearJob();
+	DoRestartSogouServicesJob();
 
 	return Error_Succeed;
 }
@@ -189,6 +192,104 @@ void CDeviceControlFSM::DoBrowserCacheClearJob()
 	}
 }
 
+void CDeviceControlFSM::DoRestartSogouServicesJob()
+{
+    LOG_FUNCTION();
+
+    CSmartPointer<IConfigInfo> spConfig;
+    ErrorCodeEnum err = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfig);
+    CSimpleStringA str(true);
+    err = spConfig->ReadConfigValue("Browser", "SogouRestart", str);
+	if (str.Compare("true", true) == 0) {
+		spConfig->WriteConfigValue("Browser", "SogouRestart", NULL);
+		RestartSogouServices();
+	}
+}
+
+ErrorCodeEnum CDeviceControlFSM::RestartSogouServices()
+{
+	LOG_FUNCTION();
+
+	ErrorCodeEnum result(Error_Succeed);
+
+    CSimpleStringA shellScriptPath;
+    GetEntityBase()->GetFunction()->GetPath("Base", shellScriptPath);
+	shellScriptPath += SPLIT_SLASH_STR;
+    shellScriptPath += "res" SPLIT_SLASH_STR "RunScript" SPLIT_SLASH_STR;
+
+	std::string startup_service(shellScriptPath.GetData());
+	startup_service += "startup_sogouservice.sh";
+    std::string shutdown_service(shellScriptPath.GetData());
+	shutdown_service += "shutdown_sogouservice.sh";
+
+	const BOOL s1 = ExistsFileA(startup_service.c_str());
+    const BOOL s2 = ExistsFileA(shutdown_service.c_str());
+
+	if (s1 && s2) {
+		
+        do {
+            std::string succStr, errStr;
+            std::string runStr("bash ");
+            runStr += shutdown_service;
+            if (!SP::Module::Util::ShelllExecute(runStr, succStr, errStr)) {
+                LogWarn(Severity_Middle, Error_Unexpect, LOG_DEVICECONTROL_SOGOU_SCRIPTS_EXECUTE_FAILED,
+                        CSimpleStringA::Format("%s: %s, %s", shutdown_service.c_str(), succStr.c_str(), errStr.c_str()));
+				return Error_Unexpect;
+			} else {
+				Dbg("execute {%s} suc: %s", shutdown_service.c_str(), succStr.c_str());
+			}
+        } while (false);
+
+		Sleep(3000);
+
+        do {
+			char app[MAX_PATH] = { '\0' };
+            tk_process_t* process = NULL;
+            tk_process_option_t option;
+            option.exit_cb = NULL;
+            option.file = NULL;
+            option.flags = 0;
+
+			sprintf(app, "bash %s", startup_service.c_str());
+			option.params = app;
+
+			const int res = process_spawn(&option, &process);
+            if (0 == res) {
+                FREE(process);
+				Dbg("execute {%s} suc", startup_service.c_str());
+			} else {
+                LogWarn(Severity_Middle, Error_Unexpect, LOG_DEVICECONTROL_SOGOU_SCRIPTS_EXECUTE_FAILED,
+                        CSimpleStringA::Format("%s: %d", startup_service.c_str(), res));
+                return Error_Unexpect;
+			}
+
+
+   //         std::string succStr, errStr;
+   //         std::string runStr("bash ");
+   //         runStr += startup_service;
+
+   //         if (!SP::Module::Util::ShelllExecute(runStr, succStr, errStr)) {
+   //             LogWarn(Severity_Middle, Error_Unexpect, LOG_DEVICECONTROL_SOGOU_SCRIPTS_EXECUTE_FAILED,
+   //                     CSimpleStringA::Format("%s: %s, %s", startup_service.c_str(), succStr.c_str(), errStr.c_str()));
+   //             return Error_Unexpect;
+			//} else {
+   //             Dbg("execute {%s} suc: %s", startup_service.c_str(), succStr.c_str());
+			//}
+
+        } while (false);
+
+		LogWarn(Severity_Middle, Error_Unexpect, LOG_DEVICECONTROL_SOGOU_SCRIPTS_EXECUTE_SUCC, "sogou restart succ.");
+
+	} else {
+
+		LogWarn(Severity_Middle, Error_NotExist, LOG_DEVICECONTROL_SOGOU_SCRIPTS_NOT_EXISTS,
+				CSimpleStringA::Format("%s=%d, %s=%d", startup_service.c_str(), s1, shutdown_service.c_str(), s2));
+		result = Error_NotExist;
+	}
+
+	return result;
+}
+
 ErrorCodeEnum CDeviceControlFSM::OnExit()
 {
 	return Error_Succeed;

+ 2 - 0
Module/mod_DeviceControl/DeviceControlFSM.h

@@ -154,6 +154,8 @@ public:
 
 private:
 	void DoBrowserCacheClearJob();
+	void DoRestartSogouServicesJob();
+	ErrorCodeEnum RestartSogouServices();
 
 private:
 	ErrorCodeEnum m_testResult;

+ 29 - 2
addin/res/ManagerDesktop/js/page/browser.js

@@ -8,11 +8,16 @@ function browserGenPage() {
     <div id="browserContent">\
         <div id="browser_all_content">\
             <div id="browser_prompt" class="page_prompt_info page_scenes_info_text hide" style="display: none;"></div>\
-            <div class="clearboth" id="browser_btn_save_div" style="padding-top:50px">\
+            <div class="clearboth" id="browser_cache_btn_save_div" style="padding-top:50px">\
                 <div class="control-label" style="margin-top: 8px;">&nbsp;</div>\
                 <div class="controls"><button class="btn_normal_long"\
                         id="browser_btn_save">浏览器缓存清理</button></div>\
             </div>\
+            <div class="clearboth" id="browser_sogou_btn_save_div" style="padding-top:50px">\
+                <div class="control-label" style="margin-top: 8px;">&nbsp;</div>\
+                <div class="controls"><button class="btn_normal_long"\
+                        id="browser_sogou_btn_restart">重启搜狗输入法服务(针对异常情况)</button></div>\
+            </div>\
             <div class="clearboth" style="padding-top:70px"></div>\
             </div>\
     </div>\
@@ -46,7 +51,28 @@ var browserController = (function() {
         RVC.DeviceControlEntityCtrl.ReadConfigValue(req, function(ret) {
             utilStopSubmitDialog();
             if (ret.errorCode === 0) {
-                utilStartAlertDialog("清理指令已成功下发,请重启应用以进行浏览器缓存清理。");
+                utilStartAlertDialog("清理指令已下发,请重启应用以进行浏览器缓存清理。");
+            } else {
+                RVC.DeviceControlEntityCtrl.commErrorCallback(ret);
+            }
+        });
+    }
+
+    function restartSogouSrvRestartFlag() {
+        let req = new Request();
+        req.configType = 3; //RunConfig
+        req.section = 'Browser';
+        req.option = true; //Write
+        req.key = 'SogouRestart';
+        req.reserved1 = 0;
+        req.reserved2 = 0;
+        req.reserved3 = 'true';
+        req.reserved4 = '';
+        utilStartSubmitDialog();
+        RVC.DeviceControlEntityCtrl.ReadConfigValue(req, function(ret) {
+            utilStopSubmitDialog();
+            if (ret.errorCode === 0) {
+                utilStartAlertDialog("重启指令已下发,请重启应用以执行该操作。");
             } else {
                 RVC.DeviceControlEntityCtrl.commErrorCallback(ret);
             }
@@ -60,6 +86,7 @@ var browserController = (function() {
 
     function initPage() {
         $(document).on('click', '#browser_btn_save', saveButtonHandle);
+        $(document).on('click', '#browser_sogou_btn_restart', restartSogouSrvRestartFlag);
     }
 
     var fistTime = true;

+ 32 - 0
addin/res/RunScript/shutdown_sogouservice.sh

@@ -0,0 +1,32 @@
+#/bin/bash
+
+echo "[SOGOULOG] === Kill monitor Start === "
+MONITOR=sogoumonitor.sh
+ID=`ps -ef | grep "$MONITOR" | grep -v "$0" | grep -v "grep" | awk '{print $2}'`
+for id in $ID
+do
+echo "[SOGOULOG] === $MONITOR is running, Kill monitor === "
+kill -9 $id
+echo "[SOGOULOG] === Kill monitor Done === "
+done
+
+WEBSRV=sogouImeWebSrv
+ID=`ps -ef | grep "$WEBSRV" | grep -v "$0" | grep -v "grep" | awk '{print $2}'`
+for id in $ID
+do
+echo "[SOGOULOG] === $WEBSRV is running, Kill Service === "
+kill -9 $id
+echo "[SOGOULOG] === Kill sogouImeWebSrv Done === "
+done
+
+echo "[SOGOULOG] === Kill Service Start === "
+SOGOUIME=sogouImeService
+ID=`ps -ef | grep "$SOGOUIME" | grep -v "$0" | grep -v "grep" | awk '{print $2}'`
+for id in $ID
+do
+echo "[SOGOULOG] === $SOGOUIME is running, Kill Service === "
+kill -9 $id
+echo "[SOGOULOG] === Kill sogouImeService Done === "
+done
+
+echo "[SOGOULOG] === Kill Service Done === "

+ 9 - 0
addin/res/RunScript/startup_sogouservice.sh

@@ -0,0 +1,9 @@
+#/bin/bash
+
+echo "[SOGOULOG] === Start Service Start === "
+
+bash ./shutdown_service.sh
+/opt/sogouimebs/files/bin/sogouImeWebSrv
+/opt/sogouimebs/files/bin/sogouImeService
+
+echo "[SOGOULOG] === Service Done! === "

+ 0 - 0
addin/res/RunScript/v2.6.0.4229.txt