From 3124c0bab9bde312a026814e3f91e39fcc69fa74 Mon Sep 17 00:00:00 2001 From: JungJun Date: Tue, 14 Jun 2022 13:16:36 +0900 Subject: [PATCH] =?UTF-8?q?loader=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- icsutil/daemon.go | 4 +- loader/loader.go | 6 +-- voicestatCheck/voicestatCheck.go | 92 ++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 voicestatCheck/voicestatCheck.go diff --git a/icsutil/daemon.go b/icsutil/daemon.go index 725d701..a85da5b 100644 --- a/icsutil/daemon.go +++ b/icsutil/daemon.go @@ -78,7 +78,7 @@ func WritePID(pid int) *icserror.IcsError { } if isStop { - pidFilename := fmt.Sprintf("%s/voiceStastics.pid", homeDir) + pidFilename := fmt.Sprintf("%s/voiceStatistics.pid", homeDir) spid := fmt.Sprintf("%d", pid) ioutil.WriteFile(pidFilename, []byte(spid), 0666) } else { @@ -146,7 +146,7 @@ func CheckPID() bool { } // Process Check -const PNAMEC = "voicegatewayCheck" +const PNAMEC = "voicestatCheck" func DeamonizeProcessCheck() (int, error) { pid, _, sysErr := syscall.RawSyscall(syscall.SYS_FORK, 0, 0, 0) diff --git a/loader/loader.go b/loader/loader.go index 649a0a0..4c8c008 100644 --- a/loader/loader.go +++ b/loader/loader.go @@ -54,15 +54,15 @@ func main() { lerr.PrintWithCaller(0) } - icsLog.Print(icslog.LOG_LEVEL_INFO, -1, "Started VoiceGateway Loader") + icsLog.Print(icslog.LOG_LEVEL_INFO, -1, "Started Voice Statistic Loader") //deamonize pid, derr := icsutil.DeamonizeProcessCheck() if derr != nil { icserror.ICSERRDeamonize.SetError(derr) - icsLog.Printf(icslog.LOG_LEVEL_ERROR, -1, "VoiceGateway : %s", icserror.ICSERRDeamonize.GetError()) + icsLog.Printf(icslog.LOG_LEVEL_ERROR, -1, "VoiceStatistic : %s", icserror.ICSERRDeamonize.GetError()) os.Exit(0) } - icsLog.Printf(icslog.LOG_LEVEL_INFO, -1, "Loaded VoiceGateway[%d]", pid) + icsLog.Printf(icslog.LOG_LEVEL_INFO, -1, "Loaded VoiceStatistic[%d]", pid) } diff --git a/voicestatCheck/voicestatCheck.go b/voicestatCheck/voicestatCheck.go new file mode 100644 index 0000000..160f4ad --- /dev/null +++ b/voicestatCheck/voicestatCheck.go @@ -0,0 +1,92 @@ +package main + +import ( + "fmt" + "os" + "strings" + "time" + + "gitlab.com/ics_cinnamon/voiceStatistics/icsconf" + "gitlab.com/ics_cinnamon/voiceStatistics/icserror" + "gitlab.com/ics_cinnamon/voiceStatistics/icslog" + "gitlab.com/ics_cinnamon/voiceStatistics/icsutil" +) + +func main() { + var homeDir string + + //get Voice Agent home dir + isStop := false + + for _, e := range os.Environ() { + s := strings.SplitN(e, "=", 2) + if strings.Compare(s[0], "ICSVS_ROOT") == 0 { + homeDir = s[1] + //service.SetHomeDir(s[1]) + isStop = true + break + } + } + if !isStop { + icserror.ICSERRNotFoundHome.PrintWithCaller(1) + return + } + + //configuration + configFile := fmt.Sprintf("%s/config/icsvs.xml", homeDir) + //configFile := fmt.Sprintf("%s/config/icsvc.xml", service.GetHomeDir()) + //fmt.Println("Config file:", configFile) + conf, confErr := icsconf.OpenConfig(configFile, homeDir) + if confErr != nil { + confErr.PrintWithCaller(0) + return + } + + icsLog, lerr := icslog.NewIcsLog( + &conf.LogConfig, + icslog.GetLogLevelID(conf.LogConfig.Level), + icslog.GetLogOutputID(conf.LogConfig.Output), + conf.LogConfig.Path, + conf.LogConfig.Disklimit, + ) + + for { + // log file name change + y1, m1, d1 := icsLog.CurrentDate.Date() + y2, m2, d2 := time.Now().Date() + + if d1 != d2 || y1 != y2 || m1 != m2 { + icsLog.M.Lock() + icsLog.LogFileName = fmt.Sprintf("%s/icsvs.log-%d%02d%02d", icsLog.Path, y2, m2, d2) // file name change + var oerr error + icsLog.LogFile, oerr = os.OpenFile(icsLog.LogFileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) + if oerr != nil { + icserror.ICSERRFileOpen.SetError(oerr) + icsLog.M.Unlock() + } + icsLog.M.Unlock() + } + + if icsutil.CheckPID() { + } else { + icsLog.Print(icslog.LOG_LEVEL_INFO, -1, "Voice Statistic Death - reloading...") + + if lerr != nil { + lerr.PrintWithCaller(0) + } + + icsLog.Print(icslog.LOG_LEVEL_INFO, -1, "Started Voice Statistic Loader") + + //deamonize + pid, derr := icsutil.Deamonize() + if derr != nil { + icserror.ICSERRDeamonize.SetError(derr) + icsLog.Printf(icslog.LOG_LEVEL_ERROR, -1, "VoiceStatistic: %s", icserror.ICSERRDeamonize.GetError()) + os.Exit(0) + } + + icsLog.Printf(icslog.LOG_LEVEL_INFO, -1, "Loaded VoiceStatistic[%d]", pid) + } + time.Sleep(time.Second * 15) + } +}