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

@@ -4,4 +4,6 @@ This tool allows for the simple configuration, backup, and starting of a V Risin
- [x] Backup Saves
- [x] Update
- [x] Upload Config Files
- [x] Check if Server Runnning
- [] Check if Server Runnning
- [] Start Server
- [] Stop Server

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")
}
}

View File

@@ -520,7 +520,7 @@
async function update() {
update_button.disabled = true
console.innerText = "Updating"
let resp = await fetch("/api/update")
let resp = await fetch("/update")
let body = await resp.text()
console.innerText = body
update_button.disabled = false

View File

@@ -21,9 +21,12 @@ func main() {
r := gin.Default()
r.GET("/", index)
r.GET("/api/update", update)
r.GET("/api/status", isRunning)
r.GET("/update", update)
r.GET("/start", startServer)
r.GET("/stop", stopServer)
r.GET("/backup.zip", backup)
r.POST("/configure", configure)
srv := &http.Server{