Skip to content

Commit e4ea591

Browse files
authored
Merge pull request #80 from NexClipper/master
request merge
2 parents d963ded + 3ab02e9 commit e4ea591

File tree

14 files changed

+135
-29
lines changed

14 files changed

+135
-29
lines changed

Dockerfile/agent/klevr

-80.8 KB
Binary file not shown.

Dockerfile/manager/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM ubuntu
2-
LABEL version=0.3
2+
LABEL version=0.2
33

44
COPY ./conf/* /conf/
55
COPY ./klevr-manager /

Dockerfile/manager/klevr-manager

136 KB
Binary file not shown.

Dockerfile/manager/klevr-manager2

19 MB
Binary file not shown.

cmd/klevr-agent/main.go

Lines changed: 65 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"os/exec"
99
"strconv"
1010
"strings"
11+
"sync"
12+
1113
//"bytes"
1214
//"crypto/sha1"
1315
//"encoding/base64"
@@ -80,6 +82,8 @@ var Result_buffer string
8082
var Body common.Body
8183
var Primary_alivecheck_time int64
8284
var ping bool
85+
var doOnce sync.Once
86+
8387
///// Mode_debug = dev or not
8488
//var Mode_debug string = "dev"
8589
//
@@ -581,6 +585,7 @@ func printprimary(){
581585
logger.Debugf("Primary ip : %s, My ip : %s", Primary_ip, Local_ip_add)
582586
}
583587

588+
584589
func getCommand(){
585590
uri := Klevr_manager + "/agents/commands/init"
586591

@@ -591,40 +596,80 @@ func getCommand(){
591596
logger.Error(err)
592597
}
593598

599+
id := Body.Task[0].ID
594600
coms := Body.Task[0].Command
595601
com := strings.Split(coms, "\n")
602+
//logger.Debugf("%v", string(result))
596603

597604
filenum := len(com)
598605

599-
600-
601606
for i:=0; i<filenum-1; i++{
602607
num := strconv.Itoa(i)
603608

604-
if(com[i] == string(readFile(Commands+num))){
609+
var read string
610+
611+
err := json.Unmarshal(readFile(Commands+num), &read)
612+
if err != nil{
613+
logger.Error(err)
614+
}
615+
616+
if(com[i] == read){
605617
logger.Debugf("same command")
606618
} else {
607619
logger.Debugf("%d-----%s", i, com[i])
608620
writeFile(Commands+num, com[i])
621+
622+
execute := SSH_provbee + com[i]
623+
//execute := com[i]
624+
625+
exe := exec.Command("sh", "-c", execute)
626+
errExe := exe.Run()
627+
if errExe != nil{
628+
logger.Error(errExe)
629+
} else {
630+
exe.Wait()
631+
632+
}
633+
634+
635+
logger.Debugf("====%d=====%s", id, coms)
636+
//
637+
//doOnce.Do(func() {
638+
// logger.Debugf("----------------test")
639+
// primaryInit(Body, coms, "done")
640+
//})
609641
}
610642
}
611643

612-
for i:=0; i<filenum-1; i++{
613-
num := strconv.Itoa(i)
614-
command := readFile(Commands+num)
615-
616-
execute := SSH_provbee + string(command)[1:len(string(command))-1]
617-
logger.Debugf(execute)
618-
exe := exec.Command("sh", "-c", execute)
619-
errExe := exe.Run()
620-
if errExe != nil{
621-
logger.Error(errExe)
622-
} else {
623-
exe.Wait()
624-
deleteFile(Commands+num)
625-
}
644+
645+
646+
647+
648+
}
649+
650+
func primaryInit(bod common.Body, command string, status string){
651+
uri := Klevr_manager + "/agents/zones/init"
652+
653+
rb := &common.Body{}
654+
655+
SendMe(rb)
656+
657+
rb.Task = make([]common.Task, 1)
658+
rb.Task[0].ID = bod.Task[0].ID
659+
rb.Task[0].AgentKey = bod.Task[0].AgentKey
660+
rb.Task[0].Command = command
661+
rb.Task[0].Status = status
662+
rb.Task[0].Params = bod.Task[0].Params
663+
rb.Task[0].Result = bod.Task[0].Result
664+
rb.Task[0].Type = bod.Task[0].Type
665+
666+
b, err := json.Marshal(rb)
667+
if err != nil {
668+
logger.Error(err)
626669
}
627670

671+
result := communicator.Post_Json_http(uri, b, Klevr_agent_id_get(), API_key_id, Klevr_zone)
672+
logger.Debugf(string(result))
628673
}
629674

630675
func writeFile(path string, data string) {
@@ -650,6 +695,7 @@ func deleteFile(path string){
650695
if err != nil {
651696
logger.Error(err)
652697
}
698+
653699
}
654700

655701
func main() {
@@ -684,8 +730,8 @@ func main() {
684730

685731
if Check_primary() == "true"{
686732
s := gocron.NewScheduler()
687-
s.Every(10).Seconds().Do(printprimary)
688-
s.Every(10).Seconds().Do(getCommand)
733+
s.Every(5).Seconds().Do(printprimary)
734+
s.Every(5).Seconds().Do(getCommand)
689735

690736
go func() {
691737
<-s.Start()

cmd/klevr-agent/test/test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
test
2+
test
3+
test
4+
test
5+
test
6+
test
7+
test
8+
test
9+
test
10+
test
11+
test

cmd/klevr-manager/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
docker_version="latest"
1+
docker_version="chopa2"
22

33
hello:
44
#
@@ -13,7 +13,8 @@ require:
1313
go get -u
1414
# curl -sL bit.ly/go_req | bash
1515
build: require
16-
GOOS=linux GOARCH=amd64 go build -o ./Docker/klevr-manager ./main.go
16+
go build -o ./Docker/klevr-manager ./main.go
17+
#GOOS=linux GOARCH=amd64 go build -o ./Docker/klevr-manager ./main.go
1718
run:
1819
go run ./main.go -config ../../conf/klevr-manager-local.yml
1920
login:

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ services:
1616
- "3306:3306"
1717

1818
klevr-manager:
19-
image: klevry/klevr-manager
19+
image: klevry/klevr-manager:latest
2020
ports:
2121
- "8090:8090"
2222
depends_on:

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/golang/protobuf v1.4.2 // indirect
1717
github.com/golang/snappy v0.0.1 // indirect
1818
github.com/gorilla/context v1.1.1
19-
github.com/gorilla/mux v1.7.4
19+
github.com/gorilla/mux v1.8.0
2020
github.com/jasonlvhit/gocron v0.0.1
2121
github.com/json-iterator/go v1.1.10 // indirect
2222
github.com/kelseyhightower/envconfig v1.4.0
@@ -31,7 +31,7 @@ require (
3131
github.com/urfave/cli/v2 v2.2.0
3232
github.com/zcalusic/sysinfo v0.0.0-20200228145645-a159d7cc708b
3333
golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect
34-
golang.org/x/sys v0.0.0-20200821140526-fda516888d29 // indirect
34+
golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8 // indirect
3535
golang.org/x/text v0.3.3 // indirect
3636
google.golang.org/protobuf v1.25.0 // indirect
3737
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect

go.sum

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<<<<<<< Updated upstream
12
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
23
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s=
34
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU=
@@ -99,6 +100,8 @@ github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8
99100
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
100101
github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc=
101102
github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
103+
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
104+
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
102105
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
103106
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
104107
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
@@ -233,6 +236,8 @@ golang.org/x/sys v0.0.0-20200820212457-1fb795427249 h1:tKP05IMsVLZ4VeeCEFmrIUmxA
233236
golang.org/x/sys v0.0.0-20200820212457-1fb795427249/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
234237
golang.org/x/sys v0.0.0-20200821140526-fda516888d29 h1:mNuhGagCf3lDDm5C0376C/sxh6V7fy9WbdEu/YDNA04=
235238
golang.org/x/sys v0.0.0-20200821140526-fda516888d29/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
239+
golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8 h1:AvbQYmiaaaza3cW3QXRyPo5kYgpFIzOAfeAAN7m3qQ4=
240+
golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
236241
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
237242
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
238243
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
@@ -276,15 +281,12 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD
276281
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
277282
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
278283
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
279-
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
280284
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
281285
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
282286
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
283287
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
284288
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
285289
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
286-
k8s.io/apimachinery v0.18.6 h1:RtFHnfGNfd1N0LeSrKCUznz5xtUP1elRGvHJbL3Ntag=
287-
k8s.io/apimachinery v0.18.6/go.mod h1:OaXp26zu/5J7p0f92ASynJa1pZo06YlV9fG7BoWbCko=
288290
k8s.io/apimachinery v0.18.8 h1:jimPrycCqgx2QPearX3to1JePz7wSbVLq+7PdBTTwQ0=
289291
k8s.io/apimachinery v0.18.8/go.mod h1:6sQd+iHEqmOtALqOFjSWp2KZ9F0wlU/nWm0ZgsYWMig=
290292
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=

0 commit comments

Comments
 (0)