mirror of
https://github.com/OpenFactorioServerManager/factorio-server-manager.git
synced 2025-01-06 03:54:06 +02:00
Optimised GLIBC fix, added autostart feature
This commit is contained in:
parent
02ce64ddbb
commit
759aae40e5
@ -65,6 +65,11 @@ Usage of ./factorio-server-manager:
|
||||
Path to the glibc ld.so file (default "/opt/glibc-2.18/lib/ld-2.18.so")
|
||||
-glibc-lib-loc
|
||||
Path to the glibc lib folder (default "/opt/glibc-2.18/lib")
|
||||
-autostart
|
||||
Autostarts Factorio Server when FSM is starting. Default false [true/false]
|
||||
(If no IP and/or port provided at startup, it will bind the factorio server to all interfaces
|
||||
and set the server port to the default 34197, always loads latest save)
|
||||
|
||||
Example:
|
||||
|
||||
./factorio-server-manager --dir /home/user/.factorio --host 10.0.0.1
|
||||
|
@ -42,6 +42,26 @@ func randomPort() int {
|
||||
// Returns random port to use for rcon connection
|
||||
return rand.Intn(45000-40000) + 40000
|
||||
}
|
||||
func autostart() {
|
||||
|
||||
var err error
|
||||
if FactorioServ.BindIP == "" {
|
||||
FactorioServ.BindIP = "0.0.0.0"
|
||||
|
||||
}
|
||||
if FactorioServ.Port == 0 {
|
||||
FactorioServ.Port = 34197
|
||||
}
|
||||
FactorioServ.Savefile = "Load Latest"
|
||||
|
||||
err = FactorioServ.Run()
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Error starting Factorio server: %+v", err)
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func initFactorio() (f *FactorioServer, err error) {
|
||||
f = new(FactorioServer)
|
||||
@ -133,6 +153,10 @@ func initFactorio() (f *FactorioServer, err error) {
|
||||
|
||||
f.BaseModVersion = modInfo.Version
|
||||
|
||||
if config.autostart == "true" {
|
||||
go autostart()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@ -147,28 +171,21 @@ func (f *FactorioServer) Run() error {
|
||||
}
|
||||
|
||||
args := []string{}
|
||||
|
||||
//The factorio server refenences its executable-path, since we execute the ld.so file and pass the factorio binary as a parameter
|
||||
//the game would use the path to the ld.so file as it's executable path and crash, to prevent this the parameter "--executable-path" is added
|
||||
if config.glibcCustom == "true" {
|
||||
log.Println("Custom glibc selected, glibc.so location:", config.glibcLocation, " lib location:", config.glibcLibLoc)
|
||||
args = []string{
|
||||
"--library-path", config.glibcLibLoc,
|
||||
config.FactorioBinary,
|
||||
"--bind", (f.BindIP),
|
||||
"--port", strconv.Itoa(f.Port),
|
||||
"--server-settings", filepath.Join(config.FactorioConfigDir, "server-settings.json"),
|
||||
"--rcon-port", strconv.Itoa(config.FactorioRconPort),
|
||||
"--rcon-password", config.FactorioRconPass,
|
||||
"--executable-path", config.FactorioBinary,
|
||||
}
|
||||
} else {
|
||||
args = []string{
|
||||
"--bind", (f.BindIP),
|
||||
"--port", strconv.Itoa(f.Port),
|
||||
"--server-settings", filepath.Join(config.FactorioConfigDir, "server-settings.json"),
|
||||
"--rcon-port", strconv.Itoa(config.FactorioRconPort),
|
||||
"--rcon-password", config.FactorioRconPass,
|
||||
}
|
||||
args = append(args, "--library-path", config.glibcLibLoc, config.FactorioBinary, "--executable-path", config.FactorioBinary)
|
||||
}
|
||||
|
||||
args = append(args,
|
||||
"--bind", (f.BindIP),
|
||||
"--port", strconv.Itoa(f.Port),
|
||||
"--server-settings", filepath.Join(config.FactorioConfigDir, "server-settings.json"),
|
||||
"--rcon-port", strconv.Itoa(config.FactorioRconPort),
|
||||
"--rcon-password", config.FactorioRconPass)
|
||||
|
||||
if f.Savefile == "Load Latest" {
|
||||
args = append(args, "--start-server-load-latest")
|
||||
} else {
|
||||
|
@ -37,6 +37,7 @@ type Config struct {
|
||||
glibcCustom string
|
||||
glibcLocation string
|
||||
glibcLibLoc string
|
||||
autostart string
|
||||
}
|
||||
|
||||
var (
|
||||
@ -78,8 +79,10 @@ func parseFlags() {
|
||||
glibcCustom := flag.String("glibc-custom", "false", "By default false, if custom glibc is required set this to true and add glibc-loc and glibc-lib-loc parameters")
|
||||
glibcLocation := flag.String("glibc-loc", "/opt/glibc-2.18/lib/ld-2.18.so", "Location glibc ld.so file if needed (ex. /opt/glibc-2.18/lib/ld-2.18.so)")
|
||||
glibcLibLoc := flag.String("glibc-lib-loc", "/opt/glibc-2.18/lib", "Location of glibc lib folder (ex. /opt/glibc-2.18/lib)")
|
||||
autostart := flag.String("autostart", "false", "Autostart factorio server on bootup of FSM, default false [true/false]")
|
||||
|
||||
flag.Parse()
|
||||
config.autostart = *autostart
|
||||
config.glibcCustom = *glibcCustom
|
||||
config.glibcLocation = *glibcLocation
|
||||
config.glibcLibLoc = *glibcLibLoc
|
||||
@ -129,7 +132,7 @@ func main() {
|
||||
|
||||
// Initialize HTTP router
|
||||
router := NewRouter()
|
||||
|
||||
log.Printf("Starting server on: %s:%s", config.ServerIP, config.ServerPort)
|
||||
log.Fatal(http.ListenAndServe(config.ServerIP+":"+config.ServerPort, router))
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user