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] Backup Saves
- [x] Update - [x] Update
- [x] Upload Config Files - [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" "github.com/gin-gonic/gin"
) )
var server_sig = make(chan int, 1)
var server_started = false
func check(err error) { func check(err error) {
if err != nil { if err != nil {
panic(err) panic(err)
@@ -121,20 +124,36 @@ func configure(c *gin.Context) {
c.Data(http.StatusOK, "text/html", updated_page) c.Data(http.StatusOK, "text/html", updated_page)
} }
func isRunning(c *gin.Context) { func doIt() {
cmd := exec.Command("ps", "aux") server_process := exec.Command("pwd")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run() var out bytes.Buffer
server_process.Stdout = &out
err := server_process.Run()
check(err) check(err)
haystack := out.String() print(out.String())
var ret string <-server_sig
if strings.Contains(haystack, "VRisingServer.exe") { server_process.Process.Signal(os.Kill)
ret = "true" }
func startServer(c *gin.Context) {
if !server_started {
go doIt()
server_started = true
c.String(http.StatusOK, "Process Started")
} else { } else {
ret = "false" 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")
} }
c.String(http.StatusOK, ret, nil)
} }

View File

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

View File

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