OSGOS_D1/custom/reg-client/services/helper.go

76 lines
1.2 KiB
Go

// OSGOS reg client
// =======================================================================================================
// Author: LLC Texnico <main@texnico.ru>
// All rights reserved
// Russia, Chelyabinsk, 2022-2024
package services
import (
"fmt"
log "github.com/sirupsen/logrus"
"os"
"reg-client/common"
"reg-client/components/regs"
"runtime/debug"
"time"
)
var (
stop chan bool
counter = 0
)
func HelperService() {
stop = make(chan bool, 1)
go func() {
fd, err := os.OpenFile("/dev/watchdog", os.O_WRONLY, 0)
if err != nil {
log.Error(err.Error())
Shutdown()
}
defer func() {
_ = fd.Close()
}()
for {
if _, err := fmt.Fprintf(fd, time.Now().String()); err != nil {
log.Error(err.Error())
Shutdown()
}
time.Sleep(time.Second * 25)
}
}()
for {
select {
case <-stop:
return
case <-time.After(time.Minute):
counter++
handleCommon()
if counter%10 == 0 {
log.Info("проверка лицензии")
handleUnReg()
}
}
}
}
func handleCommon() {
common.SaveOptions()
debug.FreeOSMemory()
}
func handleUnReg() {
if _, err := regs.GetReg(); err != nil {
Shutdown()
} else {
log.Infof("регистрация ок")
}
}
func Stop() {
stop <- true
handleCommon()
}