diff --git a/README.md b/README.md index 60f3ef4..45e9b56 100644 --- a/README.md +++ b/README.md @@ -60,11 +60,25 @@ Usage of ./factorio-server-manager: Maximum filesize for uploaded files (default 20MB). (default 20971520) -port string Specify a port for the server. (default "8080") - + -glibc-custom string + Specify if custom glibc is used (default false) [true/false] + -glibc-loc string + 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 +Custom glibc example: + +./factorio-server-manager --dir /home/user/.factorio --host 10.0.0.1 --glibc-custom true --glibc-loc /opt/glibc-2.18/lib/ld-2.18.so --glibc-lib-loc /opt/glibc-2.18/lib + ``` ## Manage Factorio Server diff --git a/src/factorio_server.go b/src/factorio_server.go index e228b9b..67cbffc 100644 --- a/src/factorio_server.go +++ b/src/factorio_server.go @@ -96,8 +96,14 @@ func initFactorio() (f *FactorioServer, err error) { log.Printf("Loaded Factorio settings from %s\n", settingsPath) + out := []byte{} //Load factorio version - out, err := exec.Command(config.FactorioBinary, "--version").Output() + if config.glibcCustom == "true" { + out, err = exec.Command(config.glibcLocation, "--library-path", config.glibcLibLoc, config.FactorioBinary, "--version").Output() + } else { + out, err = exec.Command(config.FactorioBinary, "--version").Output() + } + if err != nil { log.Printf("error on loading factorio version: %s", err) return @@ -163,13 +169,21 @@ func (f *FactorioServer) Run() error { ioutil.WriteFile(filepath.Join(config.FactorioConfigDir, config.SettingsFile), data, 0644) } - args := []string{ + 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 = 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, config.SettingsFile), "--rcon-port", strconv.Itoa(config.FactorioRconPort), - "--rcon-password", config.FactorioRconPass, - } + "--rcon-password", config.FactorioRconPass) if(f.Version.Greater(Version{0,17,0})) { args = append(args, "--server-adminlist", filepath.Join(config.FactorioConfigDir, config.FactorioAdminFile)) @@ -181,9 +195,13 @@ func (f *FactorioServer) Run() error { args = append(args, "--start-server", filepath.Join(config.FactorioSavesDir, f.Savefile)) } - log.Println("Starting server with command: ", config.FactorioBinary, args) - - f.Cmd = exec.Command(config.FactorioBinary, args...) + if config.glibcCustom == "true" { + log.Println("Starting server with command: ", config.glibcLocation, args) + f.Cmd = exec.Command(config.glibcLocation, args...) + } else { + log.Println("Starting server with command: ", config.FactorioBinary, args) + f.Cmd = exec.Command(config.FactorioBinary, args...) + } f.StdOut, err = f.Cmd.StdoutPipe() if err != nil { diff --git a/src/main.go b/src/main.go index 7983366..874af05 100644 --- a/src/main.go +++ b/src/main.go @@ -35,6 +35,9 @@ type Config struct { SettingsFile string `json:"settings_file"` LogFile string `json:"log_file"` ConfFile string + glibcCustom string + glibcLocation string + glibcLibLoc string } var ( @@ -73,9 +76,14 @@ func parseFlags() { factorioConfigFile := flag.String("config", "config/config.ini", "Specify location of Factorio config.ini file") factorioMaxUpload := flag.Int64("max-upload", 1024*1024*20, "Maximum filesize for uploaded files (default 20MB).") factorioBinary := flag.String("bin", "bin/x64/factorio", "Location of Factorio Server binary file") + 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)") flag.Parse() - + config.glibcCustom = *glibcCustom + config.glibcLocation = *glibcLocation + config.glibcLibLoc = *glibcLibLoc config.ConfFile = *confFile config.FactorioDir = *factorioDir config.ServerIP = *serverIP @@ -123,7 +131,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)) + }