loader 수정

main
JungJun 3 years ago
parent 3124c0bab9
commit fabfc28358

@ -44,7 +44,7 @@ func Deamonize() (int, error) {
conf := icsconf.GetIcsConfig() conf := icsconf.GetIcsConfig()
homeDir := conf.GetHomeDir() homeDir := conf.GetHomeDir()
cmdline := fmt.Sprintf("%s/bin/voicegateway", homeDir) cmdline := fmt.Sprintf("%s/bin/voiceStatistics", homeDir)
attr := &os.ProcAttr{Env: os.Environ()} attr := &os.ProcAttr{Env: os.Environ()}
p, perr := os.StartProcess(cmdline, []string{""}, attr) p, perr := os.StartProcess(cmdline, []string{""}, attr)
if perr != nil { if perr != nil {
@ -102,7 +102,7 @@ func CheckPID() bool {
} }
if isStop { if isStop {
pidFilename := fmt.Sprintf("%s/voicegateway.pid", homeDir) pidFilename := fmt.Sprintf("%s/voiceStatistics.pid", homeDir)
fd, err := os.Open(pidFilename) fd, err := os.Open(pidFilename)
if err != nil { if err != nil {
fd.Close() fd.Close()
@ -137,7 +137,7 @@ func CheckPID() bool {
//fmt.Println(pname) //fmt.Println(pname)
if strings.Contains(pname, "voicegateway") { if strings.Contains(pname, "voiceStatistics") {
return true return true
} }
} }

Binary file not shown.

@ -1,120 +0,0 @@
package main
import (
"fmt"
"os"
"os/signal"
"strings"
"sync"
"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"
)
var wg sync.WaitGroup
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,
)
if lerr != nil {
lerr.PrintWithCaller(0)
}
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() {
// icsLog.Print(icslog.LOG_LEVEL_INFO, -1, "Voice Agent HealthCheck")
} else {
ProcessLoad(icsLog)
ListenDieSignal()
// icsLog.Print(icslog.LOG_LEVEL_INFO, -1, "Voice Gateway Death - reloading...")
// icsLog.Print(icslog.LOG_LEVEL_INFO, -1, "Started Voice Gateway Loader")
// //deamonize
// pid, derr := icsutil.Deamonize()
// if derr != nil {
// icserror.ICSERRDeamonize.SetError(derr)
// icsLog.Printf(icslog.LOG_LEVEL_ERROR, -1, "voicegateway: %s", icserror.ICSERRDeamonize.GetError())
// os.Exit(0)
// }
// icsLog.Printf(icslog.LOG_LEVEL_INFO, -1, "Loaded Voice Gateway[%d]", pid)
}
}
}
func ListenDieSignal() {
stop := make(chan os.Signal)
signal.Notify(stop, os.Interrupt)
fmt.Println("Listen Dying signal started")
<-stop
fmt.Println("stopped")
wg.Done()
}
func ProcessLoad(l *icslog.IcsLog) (int, error) {
pid, derr := icsutil.Deamonize()
if derr != nil {
icserror.ICSERRDeamonize.SetError(derr)
l.Printf(icslog.LOG_LEVEL_ERROR, -1, "voicegateway: %s", icserror.ICSERRDeamonize.GetError())
return 0, derr
}
l.Printf(icslog.LOG_LEVEL_INFO, -1, "Loaded Voice Gateway[%d]", pid)
return pid, nil
}
Loading…
Cancel
Save