Colour logs, check server jar exists

This commit is contained in:
Jimmy 2021-09-20 21:40:29 +12:00
parent 17dd869ff3
commit 082084dd13
1 changed files with 13 additions and 4 deletions

View File

@ -16,7 +16,7 @@ import (
) )
func main() { func main() {
log.Println("Starting Server") log.Println("\033[32mStarting Server")
sigs := make(chan os.Signal, 1) sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGTERM) signal.Notify(sigs, syscall.SIGTERM)
@ -37,13 +37,21 @@ func main() {
} }
} }
log.Printf("Ram: Min: %s Max: %s Stop: %s Jar: %s\n\rArgs: %s", minram, maxram, stop, jar, args) log.Printf("Ram: Min: %s Max: %s Stop: %s Jar: %s\n\r", minram, maxram, stop, jar)
if _, err := os.Stat("/server/"+jar); os.IsNotExist(err) {
log.Println("\033[31mJar \"" + jar + "\" not found")
os.Exit(1)
}
var cmd *exec.Cmd var cmd *exec.Cmd
if args == "" { if args == "" {
cmd = exec.Command("java", minram, maxram, "-jar", jar) cmd = exec.Command("java", minram, maxram, "-jar", jar)
} else { } else {
cmd = exec.Command("java", minram, maxram, args, "-jar", jar) cmd = exec.Command("java", minram, maxram, args, "-jar", jar)
log.Printf("Args: %s \n\r", args)
} }
cmd.Dir = "/server" cmd.Dir = "/server"
@ -53,6 +61,7 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
defer func() { defer func() {
@ -65,7 +74,7 @@ func main() {
go func() { go func() {
sig := <-sigs sig := <-sigs
if sig == syscall.SIGTERM { if sig == syscall.SIGTERM {
fmt.Println("Stopping server") fmt.Println("\033[31mStopping server")
tty.WriteString(stop + "\n\r") tty.WriteString(stop + "\n\r")
} }
}() }()
@ -86,7 +95,7 @@ func main() {
}() }()
cmd.Wait() cmd.Wait()
tty.Write([]byte("Server Stopped")) tty.Write([]byte("\033[31mServer Stopped"))
os.Exit(0) os.Exit(0)
} }