71 lines
1.4 KiB
Go
71 lines
1.4 KiB
Go
|
// OSGOS reg client
|
||
|
// =======================================================================================================
|
||
|
// Author: LLC Texnico <main@texnico.ru>
|
||
|
// All rights reserved
|
||
|
// Russia, Chelyabinsk, 2022-2024
|
||
|
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"github.com/shirou/gopsutil/host"
|
||
|
log "github.com/sirupsen/logrus"
|
||
|
"os"
|
||
|
"os/exec"
|
||
|
"os/signal"
|
||
|
"reg-client/components/regs"
|
||
|
"reg-client/services"
|
||
|
"reg-client/services/web"
|
||
|
"syscall"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
interrupt := make(chan os.Signal, 1)
|
||
|
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
|
||
|
|
||
|
var p *exec.Cmd
|
||
|
if len(os.Args) > 1 {
|
||
|
if os.Args[1] == "reg" {
|
||
|
if _, err := regs.GetReg(); err != nil {
|
||
|
os.Exit(123)
|
||
|
}
|
||
|
os.Exit(0)
|
||
|
}
|
||
|
|
||
|
log.Infof("starting %s", os.Args[1:])
|
||
|
p = exec.Command(os.Args[1], append(os.Args[2:], fmt.Sprintf("%d", time.Now().Unix()))...)
|
||
|
if err := p.Start(); err != nil {
|
||
|
log.Fatalln(err.Error())
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if _, err := regs.GetReg(); err != nil {
|
||
|
log.Error(err.Error())
|
||
|
uptime, _ := host.Uptime()
|
||
|
if uptime > 600 {
|
||
|
services.Shutdown()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
go web.Thread()
|
||
|
go services.HelperService()
|
||
|
|
||
|
if p != nil {
|
||
|
_ = p.Wait()
|
||
|
} else {
|
||
|
switch <-interrupt {
|
||
|
case os.Interrupt:
|
||
|
log.Info("got SIGINT...")
|
||
|
case os.Kill:
|
||
|
log.Info("got SIGKILL...")
|
||
|
case syscall.SIGTERM:
|
||
|
log.Info("got SIGTERM...")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
services.Stop()
|
||
|
log.Info("закончили работу")
|
||
|
}
|