[ Agent ] [ Executor ] - add systemc shutdown service
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
factoryName="Go Application" nameIsGenerated="true">
|
factoryName="Go Application" nameIsGenerated="true">
|
||||||
<module name="ProjectOctopus"/>
|
<module name="ProjectOctopus"/>
|
||||||
<working_directory value="$PROJECT_DIR$/agent-go"/>
|
<working_directory value="$PROJECT_DIR$/agent-go"/>
|
||||||
|
<useCustomBuildTags value="true"/>
|
||||||
<parameters
|
<parameters
|
||||||
value="-version=dev -agentServerInfoConf=C:\Users\wdd\IdeaProjects\ProjectOctopus\agent-go\octopus-agent-dev.yaml"/>
|
value="-version=dev -agentServerInfoConf=C:\Users\wdd\IdeaProjects\ProjectOctopus\agent-go\octopus-agent-dev.yaml"/>
|
||||||
<kind value="PACKAGE"/>
|
<kind value="PACKAGE"/>
|
||||||
|
|||||||
@@ -87,6 +87,46 @@ func BasicPrettyPrint(resultOk bool, resultLog []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BasicSystemdShutdown(serviceName string) (ok bool, resultLog []string) {
|
||||||
|
|
||||||
|
if !strings.HasSuffix(serviceName, ".service") {
|
||||||
|
serviceName = serviceName + ".service"
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查是否存在
|
||||||
|
execute := PureResultSingleExecute(
|
||||||
|
[]string{
|
||||||
|
"systemctl",
|
||||||
|
"status",
|
||||||
|
"-q",
|
||||||
|
serviceName,
|
||||||
|
})
|
||||||
|
if !execute {
|
||||||
|
return true, []string{
|
||||||
|
serviceName,
|
||||||
|
"该服务器不存在!",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭
|
||||||
|
var shutDownCommand = [][]string{
|
||||||
|
{
|
||||||
|
"systemctl",
|
||||||
|
"stop",
|
||||||
|
serviceName,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"systemctl",
|
||||||
|
"disable",
|
||||||
|
serviceName,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
resultOK := PureResultSingleExecuteBatch(shutDownCommand)
|
||||||
|
|
||||||
|
return resultOK, resultLog
|
||||||
|
}
|
||||||
|
|
||||||
func BasicTransPipelineCommand(pipelineString string) (pipelineCommand [][]string) {
|
func BasicTransPipelineCommand(pipelineString string) (pipelineCommand [][]string) {
|
||||||
|
|
||||||
var pipelineCommandC [][]string
|
var pipelineCommandC [][]string
|
||||||
|
|||||||
@@ -37,3 +37,13 @@ func TestBasicFileExistFalse(t *testing.T) {
|
|||||||
|
|
||||||
assert.Equal(t, exists, false, "文件不存在,应该返回false!")
|
assert.Equal(t, exists, false, "文件不存在,应该返回false!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBasicSystemdShutdown(t *testing.T) {
|
||||||
|
|
||||||
|
ok, resultLog := BasicSystemdShutdown("docker.service")
|
||||||
|
//ok, resultLog := BasicSystemdShutdown("docker")
|
||||||
|
//ok, resultLog := BasicSystemdShutdown("fwd")
|
||||||
|
|
||||||
|
t.Logf("result ok is %v resultLog is %v", ok, resultLog)
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package executor
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -117,3 +118,51 @@ func TestPipelineCommandExecutor(t *testing.T) {
|
|||||||
t.Logf("command result are 下 \n")
|
t.Logf("command result are 下 \n")
|
||||||
BasicPrettyPrint(ok, resultLog)
|
BasicPrettyPrint(ok, resultLog)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSimple(t *testing.T) {
|
||||||
|
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
var output bytes.Buffer
|
||||||
|
|
||||||
|
fmt.Printf("output address is => %p \n", &output)
|
||||||
|
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
var output bytes.Buffer
|
||||||
|
fmt.Printf("out is => %#v\n", output)
|
||||||
|
|
||||||
|
command := exec.Command("ls")
|
||||||
|
command.StdoutPipe()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFileBasedPipe(t *testing.T) {
|
||||||
|
reader, writer, err := os.Pipe()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error: Couldn't create the named pipe: %s\n", err)
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
|
||||||
|
output := make([]byte, 100)
|
||||||
|
n, err := reader.Read(output)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error: Couldn't read data from the named pipe: %s\n", err)
|
||||||
|
}
|
||||||
|
fmt.Printf("Read %d byte(s). [file-based pipe]\n", n)
|
||||||
|
|
||||||
|
fmt.Printf("Read content are => %s\n", string(output))
|
||||||
|
|
||||||
|
}()
|
||||||
|
|
||||||
|
input := make([]byte, 26)
|
||||||
|
for i := 65; i <= 90; i++ {
|
||||||
|
input[i-65] = byte(i)
|
||||||
|
}
|
||||||
|
n, err := writer.Write(input)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error: Couldn't write data to the named pipe: %s\n", err)
|
||||||
|
}
|
||||||
|
fmt.Printf("Written %d byte(s). [file-based pipe]\n", n)
|
||||||
|
//time.Sleep(200 * time.Millisecond)
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user