Added Toggle for Start
This commit is contained in:
@@ -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
|
||||||
45
handlers.go
45
handlers.go
@@ -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"
|
}
|
||||||
} else {
|
|
||||||
ret = "false"
|
func startServer(c *gin.Context) {
|
||||||
}
|
if !server_started {
|
||||||
c.String(http.StatusOK, ret, nil)
|
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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
7
main.go
7
main.go
@@ -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{
|
||||||
|
|||||||
Reference in New Issue
Block a user