-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
62 lines (52 loc) · 1.31 KB
/
main.go
File metadata and controls
62 lines (52 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
)
func main() {
// Integrity checks
if os.Getenv("API_SECRET") == "" {
fmt.Fprintf(os.Stderr, "API_SECRET environment variable not defined\n")
return
}
// Get watchdog enabled state (defaults to 'disabled')
watchdogEnabled := false
if os.Getenv("WATCHDOG") != "" {
watchdogEnabled = true
}
// Open config for patching
fmt.Println("Patching config...")
patcher, err := NewMTAConfigPatcher("/var/lib/mtasa/mods/deathmatch/mtaserver.conf")
if err != nil {
panic(err)
}
// Patch some entries
patcher.Patch("serverport", os.Getenv("MTA_GAME_PORT"))
patcher.Patch("httpport", os.Getenv("MTA_HTTP_PORT"))
patcher.Patch("servername", os.Getenv("MTA_SERVER_NAME"))
patcher.Save()
// Create MTA server instance
fmt.Println("Creating MTAServer...")
server := NewMTAServer("/var/lib/mtasa/mta-server64", watchdogEnabled)
// Should we start the server immediately
if os.Getenv("START_MTA") != "" {
server.Start()
}
// Create api
fmt.Println("Creating API...")
api := NewApi(server)
// Handle SIGTERM
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGTERM)
go func() {
for _ = range c {
server.Stop(true)
os.Exit(0)
}
}()
// Listen for requests on the main goroutine
fmt.Println("Waiting for commands...")
api.Listen()
}