Change function Download module and format type print log

This commit is contained in:
HaiMD 2020-04-13 10:45:29 +07:00
parent 11a715ed34
commit 56c9eaec33
6 changed files with 116 additions and 326 deletions

View File

@ -1,303 +0,0 @@
2020-04-07 06:26:11.080419966 +0900 KST m=+36709.226992508
Error Publish message CMS BI
2020-04-07 06:26:11.084932647 +0900 KST m=+36709.231505064
Number reconnect publish msg: 1
2020-04-07 06:26:11.20256125 +0900 KST m=+36709.349133642
Lostconnect chanel subcriber: MQTT_OnConnectHandler
2020-04-07 06:26:11.230794851 +0900 KST m=+36709.377367256
Number reconnect subcriber msg: 2
2020-04-07 06:26:11.236062617 +0900 KST m=+36709.382634996
Recall function Subscribe MQTT
2020-04-07 06:26:15.014195752 +0900 KST m=+36713.160768169
MQTT CMS BeetsoftConnected
2020-04-07 06:26:15.01505725 +0900 KST m=+36713.161629617
Lostconnect chanel subcriber: MQTT_OnConnectHandler
2020-04-07 06:26:15.045926609 +0900 KST m=+36713.192499001
Number reconnect subcriber msg: 3
2020-04-07 06:26:15.050528953 +0900 KST m=+36713.197101320
Recall function Subscribe MQTT
2020-04-07 06:26:15.186509794 +0900 KST m=+36713.333082186
Ping_broker_sub() OKIE
2020-04-07 06:26:15.223918322 +0900 KST m=+36713.370490752
================>> Subcriber is OKIE <==========
2020-04-07 10:06:45.696330989 +0900 KST m=+49943.842903381
Message:{"method":"close_ssh","status": 1}
2020-04-07 10:10:27.084995356 +0900 KST m=+0.011226089
Stop Check_engine
2020-04-07 10:10:27.145781306 +0900 KST m=+0.072012014
Stop Engine
2020-04-07 10:10:27.221252448 +0900 KST m=+0.147483193
Status_Checkengine () exit status 1
2020-04-07 10:10:27.250046658 +0900 KST m=+0.176277666
====>>>>Check_engine not run
2020-04-07 10:10:27.257989078 +0900 KST m=+0.184219823
RunCheck() ok
2020-04-07 10:10:31.305352967 +0900 KST m=+4.231583737
MQTT CMS BeetsoftConnected
2020-04-07 10:10:31.305686841 +0900 KST m=+4.231917548
Lostconnect chanel subcriber: MQTT_OnConnectHandler
2020-04-07 10:10:31.336252675 +0900 KST m=+4.262483432
Number reconnect subcriber msg: 1
2020-04-07 10:10:31.343759146 +0900 KST m=+4.269989903
Recall function Subscribe MQTT
2020-04-07 10:10:31.484817964 +0900 KST m=+4.411048684
Ping_broker_sub() OKIE
2020-04-07 10:10:31.5081366 +0900 KST m=+4.434367358
================>> Subcriber is OKIE <==========
2020-04-07 10:11:57.238579075 +0900 KST m=+90.164809833
Message response cms:{"method":"open_ssh","status": 1,"params": {"port": "2465"}}
2020-04-07 10:11:57.27928489 +0900 KST m=+90.205515635
Cmd openssh new:autossh -M 0 -f -N -R 2465:localhost:22 boxai@ssh_tunnel.beetai.com > /dev/null 2>&1 &
2020-04-07 10:12:02.050956968 +0900 KST m=+94.977187675
Cmd close :kill $(pgrep ssh)
2020-04-07 10:12:02.130358243 +0900 KST m=+95.056589001
Message:{"method":"close_ssh","status": 1}
2020-04-07 11:16:45.794114019 +0900 KST m=+0.068860823
Stop Check_engine
2020-04-07 11:16:45.830566193 +0900 KST m=+0.105313034
Stop Engine
2020-04-07 11:16:45.895177716 +0900 KST m=+0.169924544
Status_Checkengine () exit status 1
2020-04-07 11:16:45.89922439 +0900 KST m=+0.173971244
====>>>>Check_engine not run
2020-04-07 11:16:45.908386603 +0900 KST m=+0.183133419
RunCheck() ok
2020-04-07 11:16:49.89811135 +0900 KST m=+4.172858191
MQTT CMS BeetsoftConnected
2020-04-07 11:16:49.921483212 +0900 KST m=+4.196230065
Lostconnect chanel subcriber: MQTT_OnConnectHandler
2020-04-07 11:16:50.064492182 +0900 KST m=+4.339239035
Number reconnect subcriber msg: 1
2020-04-07 11:16:50.161568378 +0900 KST m=+4.436315231
Recall function Subscribe MQTT
2020-04-07 11:16:50.688594283 +0900 KST m=+4.963341124
Ping_broker_sub() OKIE
2020-04-07 11:28:10.160419894 +0900 KST m=+0.056612799
Stop Check_engine
2020-04-07 11:28:10.200286405 +0900 KST m=+0.096479322
Stop Engine
2020-04-07 11:28:10.271141202 +0900 KST m=+0.167334094
Status_Checkengine () exit status 1
2020-04-07 11:28:10.27793324 +0900 KST m=+0.174126132
====>>>>Check_engine not run
2020-04-07 11:28:10.295852764 +0900 KST m=+0.192045656
RunCheck() ok
2020-04-07 11:28:14.429790431 +0900 KST m=+4.325983348
MQTT CMS BeetsoftConnected
2020-04-07 11:28:14.434804381 +0900 KST m=+4.330997423
Lostconnect chanel subcriber: MQTT_OnConnectHandler
2020-04-07 11:28:14.522056665 +0900 KST m=+4.418249557
Number reconnect subcriber msg: 1
2020-04-07 11:28:14.586845488 +0900 KST m=+4.483038367
Recall function Subscribe MQTT
2020-04-07 11:28:14.891877376 +0900 KST m=+4.788070268
Ping_broker_sub() OKIE
2020-04-07 11:28:14.926097937 +0900 KST m=+4.822290854
================>> Subcriber is OKIE <==========
2020-04-07 11:28:26.198839845 +0900 KST m=+16.095032737
Stop Check_engine
2020-04-07 11:28:26.275141167 +0900 KST m=+16.171334034
Stop Engine
2020-04-07 11:28:26.486460221 +0900 KST m=+16.382653113
API get module :http://api.biface_kr.beetai.com/api/model/get_model/263
2020-04-07 11:28:26.583846368 +0900 KST m=+16.480039247
Path:/home/admin/monitor/engine/FacePro_263/FaceRecognition/build/features.json
2020-04-07 11:28:26.588540267 +0900 KST m=+16.484733159
Save thanh cong modules
2020-04-07 11:28:26.616853829 +0900 KST m=+16.513046708
Response to server --> update modules Error
2020-04-07 11:28:26.622318279 +0900 KST m=+16.518511146
Message:{"method":"update_model","status": 1}
2020-04-07 11:34:57.307322565 +0900 KST m=+0.057778023
Stop Check_engine
2020-04-07 11:34:57.337238201 +0900 KST m=+0.087693635
Stop Engine
2020-04-07 11:34:57.399773236 +0900 KST m=+0.150228657
Status_Checkengine () exit status 1
2020-04-07 11:34:57.405998349 +0900 KST m=+0.156453795
====>>>>Check_engine not run
2020-04-07 11:34:57.417440486 +0900 KST m=+0.167895919
RunCheck() ok
2020-04-07 11:35:06.386659931 +0900 KST m=+9.137115377
MQTT CMS BeetsoftConnected
2020-04-07 11:35:06.388544368 +0900 KST m=+9.138999827
Lostconnect chanel subcriber: MQTT_OnConnectHandler
2020-04-07 11:35:06.460674503 +0900 KST m=+9.211129937
Number reconnect subcriber msg: 1
2020-04-07 11:35:06.501506514 +0900 KST m=+9.251961923
Recall function Subscribe MQTT
2020-04-07 11:35:06.882706537 +0900 KST m=+9.633161983
Ping_broker_sub() OKIE
2020-04-07 11:35:06.927125323 +0900 KST m=+9.677580781
================>> Subcriber is OKIE <==========
2020-04-07 11:36:11.158582532 +0900 KST m=+0.075096198
Stop Check_engine
2020-04-07 11:36:11.20423523 +0900 KST m=+0.120748871
Stop Engine
2020-04-07 11:36:11.300082139 +0900 KST m=+0.216595842
Status_Checkengine () exit status 1
2020-04-07 11:36:11.3218008 +0900 KST m=+0.238314491
====>>>>Check_engine not run
2020-04-07 11:36:11.359831124 +0900 KST m=+0.276344815
RunCheck() ok
2020-04-07 11:36:15.370420071 +0900 KST m=+4.286933775
MQTT CMS BeetsoftConnected
2020-04-07 11:36:15.381743008 +0900 KST m=+4.298256724
Lostconnect chanel subcriber: MQTT_OnConnectHandler
2020-04-07 11:36:15.443682618 +0900 KST m=+4.360196334
Number reconnect subcriber msg: 1
2020-04-07 11:36:15.473554442 +0900 KST m=+4.390068121
Recall function Subscribe MQTT
2020-04-07 11:36:15.842054128 +0900 KST m=+4.758567807
Ping_broker_sub() OKIE
2020-04-07 11:36:15.881851302 +0900 KST m=+4.798364968
================>> Subcriber is OKIE <==========
2020-04-07 11:46:08.7594031 +0900 KST m=+0.013336051
Stop Check_engine
2020-04-07 11:46:08.81896539 +0900 KST m=+0.072898478
Stop Engine
2020-04-07 11:46:08.895592208 +0900 KST m=+0.149525397
Status_Checkengine () exit status 1
2020-04-07 11:46:08.927968935 +0900 KST m=+0.181902311
====>>>>Check_engine not run
2020-04-07 11:46:08.935994968 +0900 KST m=+0.189927894
RunCheck() ok
2020-04-07 11:46:12.929799072 +0900 KST m=+4.183732011
MQTT CMS BeetsoftConnected
2020-04-07 11:46:12.930397824 +0900 KST m=+4.184330763
Lostconnect chanel subcriber: MQTT_OnConnectHandler
2020-04-07 11:46:12.963770118 +0900 KST m=+4.217703069
Number reconnect subcriber msg: 1
2020-04-07 11:46:12.979999742 +0900 KST m=+4.233932730
Recall function Subscribe MQTT
2020-04-07 11:46:13.363673793 +0900 KST m=+4.617606757
Ping_broker_sub() OKIE
2020-04-07 11:46:13.380354225 +0900 KST m=+4.634287189
================>> Subcriber is OKIE <==========
2020-04-07 11:46:36.611343441 +0900 KST m=+27.865276392
Message response cms:{"method":"open_ssh","status": 1,"params": {"port": "2466"}}
2020-04-07 11:46:36.638973661 +0900 KST m=+27.892906674
Cmd openssh new:autossh -M 0 -f -N -R 2466:localhost:22 boxai@ssh_tunnel.beetai.com > /dev/null 2>&1 &
2020-04-07 11:46:41.277133552 +0900 KST m=+32.531066515
Cmd close :kill $(pgrep ssh)
2020-04-07 11:46:41.357834268 +0900 KST m=+32.611767232
Message:{"method":"close_ssh","status": 1}
2020-04-07 11:51:02.948266284 +0900 KST m=+294.202199197
Stop Check_engine
2020-04-07 11:51:03.021681337 +0900 KST m=+294.275614251
Stop Engine
2020-04-07 11:51:03.178315663 +0900 KST m=+294.432248627
API get module :http://api.biface_kr.beetai.com/api/model/get_model/263
2020-04-07 11:51:03.269057903 +0900 KST m=+294.522990841
Path:/home/admin/monitor/engine/FacePro_263/FaceRecognition/build/features.json
2020-04-07 11:51:03.287753025 +0900 KST m=+294.541686001
Save thanh cong modules
2020-04-07 11:51:03.327277221 +0900 KST m=+294.581210197
Response to server --> update modules Error
2020-04-07 11:51:03.331905242 +0900 KST m=+294.585838193
Message:{"method":"update_model","status": 1}
2020-04-07 11:58:06.382478385 +0900 KST m=+717.636411323
Stop Check_engine
2020-04-07 11:58:06.434587385 +0900 KST m=+717.688520299
Stop Engine
2020-04-07 11:58:06.55001063 +0900 KST m=+717.803943619
API get module :http://api.biface_kr.beetai.com/api/model/get_model/263
2020-04-07 11:58:06.737011667 +0900 KST m=+717.990944618
Path:/home/admin/monitor/engine/FacePro_263/FaceRecognition/build/features.json
2020-04-07 11:58:06.76557314 +0900 KST m=+718.019506079
Save thanh cong modules
2020-04-07 11:58:06.802949955 +0900 KST m=+718.056882906
Response to server --> update modules Error
2020-04-07 11:58:06.808624034 +0900 KST m=+718.062556985
Message:{"method":"update_model","status": 1}
2020-04-07 12:01:38.421545027 +0900 KST m=+929.675477991
Stop Check_engine
2020-04-07 12:01:38.468994274 +0900 KST m=+929.722927237
Stop Engine
2020-04-07 12:01:38.564148969 +0900 KST m=+929.818081945
API get module :http://api.biface_kr.beetai.com/api/model/get_model/263
2020-04-07 12:01:38.650863713 +0900 KST m=+929.904796814
Path:/home/admin/monitor/engine/FacePro_263/FaceRecognition/build/features.json
2020-04-07 12:01:38.680428983 +0900 KST m=+929.934361947
Save thanh cong modules
2020-04-07 12:01:38.722174728 +0900 KST m=+929.976107679
Response to server --> update modules Error
2020-04-07 12:01:38.730380053 +0900 KST m=+929.984312966
Message:{"method":"update_model","status": 1}

Binary file not shown.

View File

@ -76,12 +76,14 @@ var STT_test bool
//============================> Main <==========================
func main() {
file.Println("----------------------START MAIN -------------------------")
// mqtt.DEBUG = log.New(os.Stderr, "DEBUG ", log.Ltime) // | log.Lshortfile)
//box.GetDir() // Check thu muc goc
fmt.Println("FUC......U")
file.Check_path(box.Path_log_luncher)
file.Check_path(box.Path_log_engine)
file.Write_log("<------------------------------------------------------->", box.Path_log_luncher)
file.Write_log("<-------------------- START MAIN ----------------------->", box.Path_log_luncher)
file.Write_log("<------------------------------------------------------->", box.Path_log_luncher)
box.Stop_check_engine()
box.Stop_engine()

View File

@ -1,5 +0,0 @@
set GOOS=linux
set GOARCH=arm
set GOARM=5
go build
pause

View File

@ -1,7 +1,7 @@
package box
import (
"beetai/file"
"Beetai_Pro/file"
"bufio"
"bytes"
"encoding/json"
@ -20,6 +20,8 @@ import (
//"path/filepath"
"strconv" // convert string to int
"strings"
"github.com/dustin/go-humanize"
)
// go.lintOnSave": "off"
@ -155,7 +157,67 @@ type Engine_pub struct {
Engine_id int `json:"engine_id"`
}
// Check size of file download
type WriteCounter struct {
Total uint64
}
//==================== FUNCTION ==============================
// Down load file Url
func (wc *WriteCounter) Write(p []byte) (int, error) {
n := len(p)
wc.Total += uint64(n)
wc.PrintProgress()
return n, nil
}
func (wc WriteCounter) PrintProgress() {
// Clear the line by using a character return to go back to the start and remove
// the remaining characters by filling it with spaces
fmt.Printf("\r%s", strings.Repeat(" ", 35))
// Return again and print current status of download
// We use the humanize package to print the bytes in a meaningful way (e.g. 10 MB)
fmt.Printf("\rDownloading... %s complete", humanize.Bytes(wc.Total))
}
func DownloadFile(filepath string, url string) error {
// Create the file, but give it a tmp file extension, this means we won't overwrite a
// file until it's downloaded, but we'll remove the tmp extension once downloaded.
out, err := os.Create(filepath + ".tmp")
if err != nil {
return err
}
// Get the data
resp, err := http.Get(url)
if err != nil {
out.Close()
return err
}
defer resp.Body.Close()
// Create our progress reporter and pass it to be used alongside our writer
counter := &WriteCounter{}
if _, err = io.Copy(out, io.TeeReader(resp.Body, counter)); err != nil {
out.Close()
return err
}
// The progress use the same line so print a new line once it's finished downloading
fmt.Print("\n")
// Close the file without defer so it can happen before Rename()
out.Close()
if err = os.Rename(filepath+".tmp", filepath); err != nil {
return err
}
return nil
}
//---------------------------------------------------------------------------------
func GetDir() {
if file.ReadFile("/admin/ver_sys.txt") == "1" {
path_base = "/home/aibox/Documents/monitor"
@ -911,18 +973,49 @@ func Res_Server(Url string, id_box int, id_engine int) {
} else {
defer resp.Body.Close()
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
file.Write_log("ioutil.ReadAll(resp.Body) Faild of Res_Server ()", Path_log_luncher)
file.Println("ioutil.ReadAll(resp.Body) Faild of Res_Server ()")
}
respon_msg := string(body)
if respon_msg == "{'status': 10000}" {
file.Write_log("Response to server --> update modules Done", Path_log_luncher)
} else {
file.Write_log("Response to server --> update modules Error", Path_log_luncher)
}
// body, err := ioutil.ReadAll(resp.Body)
// if err != nil {
// file.Write_log("ioutil.ReadAll(resp.Body) Faild of Res_Server ()", Path_log_luncher)
// file.Println("ioutil.ReadAll(resp.Body) Faild of Res_Server ()")
// }
// respon_msg := string(body)
// if respon_msg == "{'status': 10000}" {
// file.Write_log("Response to server --> update modules Done", Path_log_luncher)
// } else {
// file.Write_log("Response to server --> update modules Error", Path_log_luncher)
// }
}
func RequestUpdate_Module(url string, id_engine int) {
//http://api1.dev_dc.beetai.com/api/model/get_model/257
// url = /api/model/get_mode/
fmt.Println("RequestUpdate_Module()")
for i := 0; i < len(message.Data.Engines); i++ {
if message.Data.Engines[i].Id == id_engine {
var id_val = strconv.Itoa(message.Data.Engines[i].Id)
fmt.Println(message)
url = message.Data.Engines[i].Url + url + id_val
path := path_base + "/engine/" + message.Data.Engines[i].Name + "/FaceRecognition/build/features.json"
fmt.Println("API get module :" + url)
file.Write_log("API get module :"+url, Path_log_luncher)
file.Write_log("Path:"+path, Path_log_luncher)
file.Write_log("Download Started", Path_log_luncher)
err := DownloadFile(path, url)
if err != nil {
// panic(err)
file.Write_log("Download Error", Path_log_luncher)
} else {
file.Write_log("Download Finished", Path_log_luncher)
file.Write_log("Save thanh cong modules", Path_log_luncher)
Res_Server(message.Data.Engines[i].Url, message.Data.Box_id, message.Data.Engines[i].Id)
}
}
}
}
/*
func RequestUpdate_Module(url string, id_engine int) {
//http://api1.dev_dc.beetai.com/api/model/get_model/257
// url = /api/model/get_mode/
@ -964,7 +1057,7 @@ func RequestUpdate_Module(url string, id_engine int) {
}
}
*/
// List function
func GetIDEngine(path string) string {
var id string = ""
@ -1024,8 +1117,8 @@ func Ssh_close() {
}
func Stop_check_engine() {
file.Println("Stop Check_engine")
file.Write_log("Stop Check_engine \n", Path_log_luncher)
file.Println("Stop_check_engine()\n")
file.Write_log("Stop Check_engine", Path_log_luncher)
file.Println("Stop_check_engine()")
_, err := exec.Command("sh", "-c", "kill $(pgrep Check_engine)").Output()
if err != nil {
//log.Fatal(err)

View File

@ -67,13 +67,16 @@ func Write_log(msg string, path string) {
}
defer file.Close()
_, err = file.WriteString("[")
if IsError(err) {
////return
}
_, err = file.WriteString(time.Now().String())
if IsError(err) {
////return
}
// write some text line-by-line to file
_, err = file.WriteString("\n")
_, err = file.WriteString("] : ")
if IsError(err) {
////return
}