Prepare string localization options

This commit is contained in:
Rudi 2022-07-31 11:16:42 -04:00
parent 5793efeade
commit 5f41341e1a
Signed by: rudi
GPG Key ID: EF64F3CBD1A1EBDD
2 changed files with 31 additions and 15 deletions

30
main.go
View File

@ -23,12 +23,12 @@ var (
func main() {
flag.Parse()
if flag.NArg() == 0 {
log.Println("Starting headless9")
log.Println(DAEMON_START)
daemon = true
runDaemon()
}
if flag.NArg() != 2 {
fmt.Println("Command structure: \"headless9 $verb $service\"")
fmt.Println(CMD_SYNTAX)
return
}
verb := flag.Args()[1]
@ -37,7 +37,7 @@ func main() {
f := getCtl()
_, err := fmt.Fprintf(f, "%+v %+v", verb, service)
if err != nil {
fmt.Printf("Unable to write to Control Socket. Please check the file %+v and that it's permissions are 700", controlSocket)
fmt.Printf(CTL_UNABLE_WRITE, controlSocket)
}
f.Close()
err = watchFile(controlSocket)
@ -52,25 +52,25 @@ func getCtl() *os.File {
f, err := os.OpenFile(controlSocket, os.O_TRUNC, 0700)
if err != nil {
if daemon {
log.Printf("Unable to open Control Socket. Please check the file %+v and that it's permissions are 700", controlSocket)
log.Printf(CTL_NOT_OPEN, controlSocket)
} else {
fmt.Printf("Unable to open Control Socket. Please check the file %+v and that it's permissions are 700", controlSocket)
fmt.Printf(CTL_NOT_OPEN, controlSocket)
}
}
err = f.Truncate(0)
if err != nil {
if daemon {
log.Printf("Unable to clear Control Socket. Please check the file %+v and that it's permissions are 700", controlSocket)
log.Printf(CTL_NOT_CLEAR, controlSocket)
} else {
fmt.Printf("Unable to clear Control Socket. Please check the file %+v and that it's permissions are 700", controlSocket)
fmt.Printf(CTL_NOT_CLEAR, controlSocket)
}
}
_, err = f.Seek(0, 0)
if err != nil {
if daemon {
log.Printf("Unable to rewind Control Socket. Please check the file %+v and that it's permissions are 700", controlSocket)
log.Printf(CTL_NOT_REWOUND, controlSocket)
} else {
fmt.Printf("Unable to rewind Control Socket. Please check the file %+v and that it's permissions are 700", controlSocket)
fmt.Printf(CTL_NOT_REWOUND, controlSocket)
}
}
return f
@ -79,7 +79,7 @@ func getCtl() *os.File {
func runDaemon() {
go headlessControls()
for {
log.Printf("Refreshing controlFile %+v", serviceFile)
log.Printf(DAEMON_FILE_REFRESH, serviceFile)
startup, err := readLines(serviceFile)
if err != nil {
log.Fatalln(err)
@ -90,11 +90,11 @@ func runDaemon() {
for runningProc := range services {
if svcArgs[0] == runningProc {
running = true
log.Printf("%+v exists as PID %+v", svcArgs[0], services[svcArgs[0]])
log.Printf(DAEMON_SVC_EXISTS, svcArgs[0], services[svcArgs[0]])
}
}
if !running {
log.Printf("Svc not detected, starting: %+v", svcArgs[0])
log.Printf(DAEMON_SVC_MISSING, svcArgs[0])
go execCommand(svcArgs[0], svcArgs[1:]...)
}
}
@ -116,7 +116,7 @@ func headlessControls() {
log.Println(err)
} else {
for _, cmd := range pendingCommands {
log.Printf("Processing command: %+v", cmd)
log.Printf(DAEMON_PROCESSING_CTL, cmd)
}
}
@ -128,7 +128,7 @@ func headlessControls() {
func execCommand(cmd string, arg ...string) {
defer PanicSafe()
if len(cmd) < 2 {
log.Printf("Invalid command `%v`, skipping. Args: { %+v }", cmd, arg)
log.Printf(DAEMON_CMD_INVALID, cmd, arg)
return
}
proc := exec.Command(cmd, arg...)
@ -148,7 +148,7 @@ func execCommand(cmd string, arg ...string) {
proc.Stdin = infile
err = proc.Start()
if err != nil {
log.Printf("Error starting service %+v, see log for more info.", cmd)
log.Printf(DAEMON_SVC_FAIL, cmd)
return
}
services[cmd] = fmt.Sprint(proc.Process.Pid)

16
strings.go Normal file
View File

@ -0,0 +1,16 @@
package main
var (
DAEMON_START = "Starting headless9"
CMD_SYNTAX = "Command structure: \"headless9 $verb $service\""
CTL_UNABLE_WRITE = "Unable to write to Control Socket. Please check the file %+v and that it's permissions are 700"
CTL_NOT_OPEN = "Unable to open Control Socket. Please check the file %+v and that it's permissions are 700"
CTL_NOT_CLEAR = "Unable to clear Control Socket. Please check the file %+v and that it's permissions are 700"
CTL_NOT_REWOUND = "Unable to rewind Control Socket. Please check the file %+v and that it's permissions are 700"
DAEMON_FILE_REFRESH = "Refreshing controlFile %+v"
DAEMON_SVC_EXISTS = "%+v exists as PID %+v"
DAEMON_SVC_MISSING = "Svc not detected, starting: %+v"
DAEMON_PROCESSING_CTL = "Processing command: %+v"
DAEMON_CMD_INVALID = "Invalid command `%v`, skipping. Args: { %+v }"
DAEMON_SVC_FAIL = "Error starting service %+v, see log for more info."
)