Added Toggle for Start

This commit is contained in:
2022-05-24 21:44:42 -05:00
parent 14a042ce8c
commit 2ac4037965
4 changed files with 41 additions and 17 deletions

View File

@@ -13,6 +13,9 @@ import (
"github.com/gin-gonic/gin"
)
var server_sig = make(chan int, 1)
var server_started = false
func check(err error) {
if err != nil {
panic(err)
@@ -121,20 +124,36 @@ func configure(c *gin.Context) {
c.Data(http.StatusOK, "text/html", updated_page)
}
func isRunning(c *gin.Context) {
cmd := exec.Command("ps", "aux")
var out bytes.Buffer
cmd.Stdout = &out
func doIt() {
server_process := exec.Command("pwd")
err := cmd.Run()
var out bytes.Buffer
server_process.Stdout = &out
err := server_process.Run()
check(err)
haystack := out.String()
var ret string
if strings.Contains(haystack, "VRisingServer.exe") {
ret = "true"
} else {
ret = "false"
}
c.String(http.StatusOK, ret, nil)
print(out.String())
<-server_sig
server_process.Process.Signal(os.Kill)
}
func startServer(c *gin.Context) {
if !server_started {
go doIt()
server_started = true
c.String(http.StatusOK, "Process Started")
} else {
c.String(http.StatusOK, "Already Started")
}
}
func stopServer(c *gin.Context) {
if server_started {
server_sig <- 1
server_started = false
c.String(http.StatusOK, "Process Stopped")
} else {
c.String(http.StatusOK, "Already Stopped")
}
}