|
|
@@ -11,6 +11,7 @@ import (
|
|
|
"os/exec"
|
|
|
"strings"
|
|
|
|
|
|
+ "hnyfkj.com.cn/rtu/linux/baseapp"
|
|
|
"hnyfkj.com.cn/rtu/linux/utils/jsonrpc2"
|
|
|
)
|
|
|
|
|
|
@@ -189,11 +190,17 @@ func serviceLogHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ if true {
|
|
|
+ baseapp.Logger.Debugf("[服务日志流启动] unit=%s", unit)
|
|
|
+ }
|
|
|
+
|
|
|
defer func() {
|
|
|
if cmd.Process != nil {
|
|
|
cmd.Process.Kill()
|
|
|
}
|
|
|
cmd.Wait()
|
|
|
+
|
|
|
+ baseapp.Logger.Debugf("[服务日志流关闭] unit=%s", unit)
|
|
|
}()
|
|
|
|
|
|
scanner := bufio.NewScanner(stdout)
|
|
|
@@ -214,11 +221,17 @@ func serviceLogHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
|
|
|
func runShellAndWrite(w http.ResponseWriter, cmd string) {
|
|
|
+ baseapp.Logger.Debugf("[执行命令] %s", cmd)
|
|
|
+
|
|
|
out, err := exec.Command("sh", "-c", cmd).CombinedOutput()
|
|
|
if err != nil {
|
|
|
- http.Error(w, err.Error()+"\n"+string(out), http.StatusInternalServerError)
|
|
|
+ baseapp.Logger.Errorf("[命令失败] %s err=%v", cmd, err)
|
|
|
+
|
|
|
+ http.Error(w, err.Error()+"\n"+string(out),
|
|
|
+ http.StatusInternalServerError)
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
w.Write(out)
|
|
|
}
|
|
|
|
|
|
@@ -235,8 +248,14 @@ func netDNS(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
|
|
|
func callRPCResult(ctx context.Context, port int, method string, params any, result any) error {
|
|
|
- client, err := jsonrpc2.NewRPCClient(fmt.Sprintf("http://127.0.0.1:%d/rpc", port))
|
|
|
+ url := fmt.Sprintf("http://127.0.0.1:%d/rpc", port)
|
|
|
+
|
|
|
+ req, _ := json.Marshal(params)
|
|
|
+ baseapp.Logger.Debugf("[接收RPC请求] %s %s params=%s\n", url, method, string(req))
|
|
|
+
|
|
|
+ client, err := jsonrpc2.NewRPCClient(url)
|
|
|
if err != nil {
|
|
|
+ baseapp.Logger.Errorf("[执行RPC错误] %s err=%v\n", method, err)
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
@@ -245,11 +264,18 @@ func callRPCResult(ctx context.Context, port int, method string, params any, res
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
+ baseapp.Logger.Debugf("[发送RPC应答] %s result=%s\n", method, string(resp.Result))
|
|
|
+
|
|
|
return json.Unmarshal(resp.Result, result)
|
|
|
}
|
|
|
|
|
|
func callRPCResponse(w http.ResponseWriter, r *http.Request, port int, method string, params any) {
|
|
|
- client, err := jsonrpc2.NewRPCClient(fmt.Sprintf("http://127.0.0.1:%d/rpc", port))
|
|
|
+ url := fmt.Sprintf("http://127.0.0.1:%d/rpc", port)
|
|
|
+
|
|
|
+ req, _ := json.Marshal(params)
|
|
|
+ baseapp.Logger.Debugf("[接收RPC请求] %s %s params=%s\n", url, method, string(req))
|
|
|
+
|
|
|
+ client, err := jsonrpc2.NewRPCClient(url)
|
|
|
if err != nil {
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
return
|
|
|
@@ -257,10 +283,13 @@ func callRPCResponse(w http.ResponseWriter, r *http.Request, port int, method st
|
|
|
|
|
|
resp, err := client.Call(r.Context(), method, params)
|
|
|
if err != nil {
|
|
|
+ baseapp.Logger.Errorf("[执行RPC错误] %s err=%v\n", method, err)
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ baseapp.Logger.Debugf("[发送RPC应答] %s result=%s\n", method, string(resp.Result))
|
|
|
+
|
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
|
json.NewEncoder(w).Encode(resp.Result)
|
|
|
}
|