Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
so-operation-api
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
smart-operation
so-operation-api
Commits
91dd310d
Commit
91dd310d
authored
Jul 07, 2023
by
陈子龙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
自动化运维 立即执行 fix
parent
fa231ac6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
11 deletions
+17
-11
src/service/task_manage.go
src/service/task_manage.go
+17
-11
No files found.
src/service/task_manage.go
View file @
91dd310d
...
...
@@ -185,19 +185,19 @@ func (t *TaskManageSvc) ListTaskManage(req request.ListTaskManageReq) (total int
return
}
func
(
t
*
TaskManageSvc
)
ExecScript
(
req
request
.
ExecScriptReq
)
(
data
map
[
string
]
interface
{},
err
error
)
{
func
(
t
*
TaskManageSvc
)
ExecScript
(
req
request
.
ExecScriptReq
)
(
err
error
)
{
if
req
.
ScriptUrl
!=
""
{
minioClient
,
err
:=
client
.
GetMinioConnect
()
if
err
!=
nil
{
return
nil
,
resp
.
DbConnectError
.
WithError
(
err
)
return
resp
.
DbConnectError
.
WithError
(
err
)
}
object
,
err
:=
minioClient
.
GetObject
(
context
.
Background
(),
conf
.
Options
.
MinioBucket
,
req
.
ScriptUrl
,
minio
.
GetObjectOptions
{})
if
err
!=
nil
{
return
nil
,
resp
.
FileExecError
.
WithError
(
err
)
return
resp
.
FileExecError
.
WithError
(
err
)
}
obj
,
err
:=
io
.
ReadAll
(
object
)
if
err
!=
nil
{
return
nil
,
resp
.
FileExecError
.
WithError
(
err
)
return
resp
.
FileExecError
.
WithError
(
err
)
}
req
.
Script
=
string
(
obj
)
}
...
...
@@ -225,24 +225,24 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq) (data map[string]i
//写入执行脚本
f2
,
err
:=
os
.
Create
(
"/etc/ansible/ansible.yml"
)
if
err
!=
nil
{
return
nil
,
resp
.
FileExecError
.
WithError
(
err
)
return
resp
.
FileExecError
.
WithError
(
err
)
}
defer
f2
.
Close
()
_
,
err
=
f2
.
Write
([]
byte
(
req
.
Script
))
if
err
!=
nil
{
return
nil
,
resp
.
FileExecError
.
WithError
(
err
)
return
resp
.
FileExecError
.
WithError
(
err
)
}
//写入额外yml参数
if
req
.
Type
==
1
{
//写入执行脚本
f3
,
err
:=
os
.
Create
(
"/etc/ansible/ansible_extra.yml"
)
if
err
!=
nil
{
return
nil
,
resp
.
FileExecError
.
WithError
(
err
)
return
resp
.
FileExecError
.
WithError
(
err
)
}
defer
f3
.
Close
()
_
,
err
=
f3
.
Write
([]
byte
(
req
.
Value
))
if
err
!=
nil
{
return
nil
,
resp
.
FileExecError
.
WithError
(
err
)
return
resp
.
FileExecError
.
WithError
(
err
)
}
req
.
Value
=
fmt
.
Sprintf
(
"@/etc/ansible/ansible_extra.yml"
)
}
...
...
@@ -268,8 +268,16 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq) (data map[string]i
//执行命令
err
=
cmd
.
Run
()
if
err
!=
nil
{
cmd
.
Stderr
=
os
.
Stderr
fmt
.
Println
(
cmd
.
Stderr
)
err
=
resp
.
FileExecError
.
WithError
(
err
)
return
}
fmt
.
Println
(
"执行成功"
)
fmt
.
Println
(
"stdout:"
,
stdout
)
//cmd.Stdout = os.Stdout
//cmd.Stderr = os.Stderr
//stdout, err := cmd.StdoutPipe()
//if err != nil {
// fmt.Println("执行出错:", err)
...
...
@@ -280,8 +288,6 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq) (data map[string]i
// log.Fatal(err)
//}
fmt
.
Println
(
"执行成功"
)
fmt
.
Println
(
"stdout:"
,
stdout
)
//outputBuf := bufio.NewReader(stdout)
//output, isPrefix, err := outputBuf.ReadLine()
//output, err := cmd.Output()
...
...
@@ -293,7 +299,7 @@ func (t *TaskManageSvc) ExecScript(req request.ExecScriptReq) (data map[string]i
//data["step"] = isPrefix
//data["output"] = string(output)
//data["output"] = string(output)
return
data
,
nil
return
nil
}
func
GetOutput
(
reader
*
bufio
.
Reader
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment