forgot to commit

This commit is contained in:
Rudi 2022-10-23 10:57:01 -04:00
parent 7d8ef637b5
commit b06284f841
Signed by: rudi
GPG Key ID: EF64F3CBD1A1EBDD

17
main.go
View File

@ -17,6 +17,8 @@ var (
services = make(map[string]Service) services = make(map[string]Service)
controlSocket = "/adm/headless9/ctl/headless9.ctl" controlSocket = "/adm/headless9/ctl/headless9.ctl"
logPath = "/adm/headless9/log/" logPath = "/adm/headless9/log/"
execWait = false
headless9Start = time.Now()
) )
func main() { func main() {
@ -133,6 +135,7 @@ func headlessControls() {
} }
func processCommand(cmd string) error { func processCommand(cmd string) error {
defer PanicSafe()
parts := strings.Split(cmd, " ") parts := strings.Split(cmd, " ")
verb := parts[0] verb := parts[0]
svc := parts[1] svc := parts[1]
@ -169,17 +172,24 @@ func processCommand(cmd string) error {
log.Printf(DAEMON_SVC_MISSING, svcArgs[0]) log.Printf(DAEMON_SVC_MISSING, svcArgs[0])
messages++ messages++
execWait = true
go execCommand(svcArgs[0], svcArgs[1:]...) go execCommand(svcArgs[0], svcArgs[1:]...)
} }
} }
for execWait {
time.Sleep(5 * time.Millisecond)
}
ctlOut := "" ctlOut := ""
if verb == "status" { if verb == "status" {
ctlOut = strings.Join(sysTail(10, fmt.Sprintf("%+v/%+v.log", logPath, svc)), "\n") ctlOut += fmt.Sprintf("%+v up %+v PID %+v\n", svc, time.Since(services[svc].StartTime), services[svc].ProcessHandle.Pid)
ctlOut += strings.Join(sysTail(5, fmt.Sprintf("%+v/%+v.log", logPath, svc)), "\n")
} else { } else {
ctlOut = strings.Join(sysTail(messages, fmt.Sprintf("%+v/%+v.log", logPath, "headless9")), "\n")
ctlOut += fmt.Sprintf("%+v up %+v\n", "headless9", time.Since(headless9Start))
ctlOut += strings.Join(sysTail(messages, fmt.Sprintf("%+v/%+v.log", logPath, "headless9")), "\n")
} }
f := getCtl() f := getCtl()
_, err := fmt.Fprintf(f, "%+v", ctlOut) _, err := fmt.Fprintf(f, "%s", ctlOut)
if err != nil { if err != nil {
log.Printf(CTL_UNABLE_WRITE, controlSocket) log.Printf(CTL_UNABLE_WRITE, controlSocket)
} }
@ -222,6 +232,7 @@ func execCommand(cmd string, arg ...string) {
StartupArgs: arg, StartupArgs: arg,
StartTime: time.Now(), StartTime: time.Now(),
} }
execWait = false
proc.Wait() proc.Wait()
} }