125 lines
2.9 KiB
Go
125 lines
2.9 KiB
Go
package action_engine
|
|
|
|
import (
|
|
// "bytes"
|
|
// "encoding/json"
|
|
|
|
"fmt"
|
|
// "github.com/eclipse/paho.mqtt.golang"
|
|
//"io"
|
|
// "log"
|
|
// "net"
|
|
// "os"
|
|
"os/exec"
|
|
// "time"
|
|
//"io/ioutil"
|
|
//"path/filepath"
|
|
// "strconv" // convert string to int
|
|
//"strings"
|
|
)
|
|
|
|
var debug int = 1
|
|
|
|
func Kill_engine() {
|
|
if debug == 1 {
|
|
fmt.Printf("Kill_engine()\n")
|
|
}
|
|
out1, _ := exec.Command("sh", "-c", "ps -A | grep loop_run").Output()
|
|
if len(out1) != 0 {
|
|
_, err := exec.Command("sh", "-c", " kill $(pgrep loop_run)").Output()
|
|
if err != nil {
|
|
//log.Fatal(err)
|
|
}
|
|
}
|
|
out2, _ := exec.Command("sh", "-c", "ps -A | grep FaceRecognition").Output()
|
|
if len(out2) != 0 {
|
|
_, err := exec.Command("sh", "-c", " kill $(pgrep FaceRecognition)").Output() // kill $(pgrep FaceRecognition)
|
|
if err != nil {
|
|
//log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
}
|
|
func Stop_check_engine() {
|
|
fmt.Println("Kill Check_engine")
|
|
if debug == 1 {
|
|
fmt.Printf("Stop_check_engine()\n")
|
|
}
|
|
_, err := exec.Command("sh", "-c", "kill $(pgrep Check_engine)").Output()
|
|
if err != nil {
|
|
//log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func Tranfer_engine() {
|
|
if debug == 1 {
|
|
fmt.Printf("Tranfer_engine()\n")
|
|
fmt.Printf("Begin backup engine\n")
|
|
}
|
|
_, err := exec.Command("sh", "-c", "cd /root/monitor/backup").Output()
|
|
if err != nil {
|
|
_, err1 := exec.Command("sh", "-c", "mkdir /root/monitor/backup").Output()
|
|
if err1 != nil {
|
|
//log.Fatal(err)
|
|
fmt.Printf(" Backup engine Error\n")
|
|
}
|
|
}
|
|
|
|
if debug == 1 {
|
|
fmt.Printf("Create forder backup\n")
|
|
}
|
|
// Xoa file engine cu trong backup
|
|
_, err0 := exec.Command("sh", "-c", "cd /root/monitor/backup/monitor/").Output()
|
|
if err0 == nil {
|
|
_, err1 := exec.Command("sh", "-c", "rm -rf /root/monitor/backup/monitor/").Output()
|
|
if err1 != nil {
|
|
//log.Fatal(err1)
|
|
fmt.Printf(" Xoa file engine cu trong backup Error\n")
|
|
}
|
|
}
|
|
_, err2 := exec.Command("sh", "-c", "mv /root/monitor/face_recognition/ /root/monitor/backup/").Output()
|
|
if err2 != nil {
|
|
//log.Fatal(err2)
|
|
fmt.Printf("Move mv /root/monitor/face_recognition/ /root/monitor/backup/ error\n")
|
|
|
|
}
|
|
// fmt.Printf("Done copy\n")
|
|
}
|
|
func Backup_engine() {
|
|
if debug == 1 {
|
|
fmt.Printf("Backup_engine()\n")
|
|
}
|
|
_, err := exec.Command("sh", "-c", "rm -rf /root/monitor/face_recognition/").Output()
|
|
if err != nil {
|
|
//log.Fatal(err)
|
|
} else {
|
|
_, err1 := exec.Command("sh", "-c", "mv /root/monitor/backup/face_recognition/ /root/monitor/").Output()
|
|
if err1 != nil {
|
|
//log.Fatal(err1)
|
|
} else {
|
|
_, err2 := exec.Command("sh", "-c", "sudo chmod +x /root/monitor/face_recognition/build/FaceRecognition/FaceRecognition").Output()
|
|
if err2 != nil {
|
|
//log.Fatal(err2)
|
|
} else {
|
|
//Start_engine()
|
|
}
|
|
}
|
|
}
|
|
//fmt.Printf("Done Backup_engine \n")
|
|
}
|
|
func Download_engine() {
|
|
if debug == 1 {
|
|
fmt.Printf("Download_engine()\n")
|
|
}
|
|
|
|
}
|
|
func Upgrade_engine() {
|
|
if debug == 1 {
|
|
fmt.Printf("Upgrade_engine()\n")
|
|
}
|
|
Stop_check_engine()
|
|
Kill_engine()
|
|
Tranfer_engine()
|
|
//Start_engine()
|
|
}
|