This is an automated email from the ASF dual-hosted git repository.

miaoliyao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/shardingsphere-on-cloud.git


The following commit(s) were added to refs/heads/main by this push:
     new afe0aa6  feat: pitr agent service add shell flags and example for 
execute command (#197)
afe0aa6 is described below

commit afe0aa6ec1fb8b1a08dadb5628f10034bb303aab
Author: lltgo <[email protected]>
AuthorDate: Thu Feb 9 18:23:12 2023 +0800

    feat: pitr agent service add shell flags and example for execute command 
(#197)
    
    * feat: pitr agent service add shell flags.
    
    * chore: update licensed
---
 pitr/agent/main.go              |  5 +++-
 pitr/agent/pkg/cmds/cmd.go      | 61 +++++++++++++++++++++++++++++++++++++++++
 pitr/agent/pkg/cmds/cmd_test.go | 30 ++++++++++++++++++++
 3 files changed, 95 insertions(+), 1 deletion(-)

diff --git a/pitr/agent/main.go b/pitr/agent/main.go
index e9d4324..bebaecb 100644
--- a/pitr/agent/main.go
+++ b/pitr/agent/main.go
@@ -51,15 +51,18 @@ var (
        port     string
        tlsCrt   string
        tlsKey   string
+       shell    string
 )
 
 func init() {
        // 参数通过 flag 输入
        flag.StringVar(&logLevel, "logLevel", "info", "optional:log 
level,option values:info or debug")
-       flag.StringVar(&port, "port", "443", "optional:443 is default")
+       flag.StringVar(&port, "port", "443", "HTTP service port")
 
        flag.StringVar(&tlsCrt, "tlsCrt", "", "Require:TLS certificate file 
path")
        flag.StringVar(&tlsKey, "tlsKey", "", "Require:TLS key file path")
+
+       flag.StringVar(&shell, "shell", "/bin/sh", "Shell path")
 }
 
 func main() {
diff --git a/pitr/agent/pkg/cmds/cmd.go b/pitr/agent/pkg/cmds/cmd.go
new file mode 100644
index 0000000..ec3196d
--- /dev/null
+++ b/pitr/agent/pkg/cmds/cmd.go
@@ -0,0 +1,61 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+ */
+
+package cmds
+
+import (
+       "bufio"
+       "fmt"
+       "io"
+       "os/exec"
+)
+
+func command(name string, args ...string) error {
+       c := "-c"
+       args = append([]string{c}, args...)
+
+       cmd := exec.Command(name, args...)
+
+       stdout, err := cmd.StdoutPipe()
+       if err != nil {
+               return fmt.Errorf("can not obtain stdout pipe for 
command[args=%+v]:%s", args, err)
+       }
+       if err := cmd.Start(); err != nil {
+               return fmt.Errorf("the command is err[args=%+v]:%s", args, err)
+       }
+
+       reader := bufio.NewReader(stdout)
+
+       index := 1
+       for {
+               line, err := reader.ReadString('\n')
+               if io.EOF == err {
+                       break
+               } else if err != nil {
+                       return fmt.Errorf("read string is err[args=%+v]:%s", 
args, err)
+               }
+
+               fmt.Print(index, "\t", line)
+               index++
+       }
+
+       if err := cmd.Wait(); err != nil {
+               return fmt.Errorf("cmd wait is err[args=%+v]:%s", args, err)
+       }
+
+       return nil
+}
diff --git a/pitr/agent/pkg/cmds/cmd_test.go b/pitr/agent/pkg/cmds/cmd_test.go
new file mode 100644
index 0000000..6ccf23f
--- /dev/null
+++ b/pitr/agent/pkg/cmds/cmd_test.go
@@ -0,0 +1,30 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+ */
+
+package cmds
+
+import "testing"
+
+const (
+       sh = "/bin/sh"
+)
+
+func TestCommand(t *testing.T) {
+       if err := command(sh, "ping www.baidu.com"); err != nil {
+               t.Fatal(err)
+       }
+}

Reply via email to