Skip to content

Commit fad1021

Browse files
authored
Merge pull request #155 from Psychomantis71/master
Fix for the glibc issue on RHEL/Centos
2 parents b967f1c + 7c05665 commit fad1021

File tree

3 files changed

+50
-10
lines changed

3 files changed

+50
-10
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,25 @@ Usage of ./factorio-server-manager:
6060
Maximum filesize for uploaded files (default 20MB). (default 20971520)
6161
-port string
6262
Specify a port for the server. (default "8080")
63-
63+
-glibc-custom string
64+
Specify if custom glibc is used (default false) [true/false]
65+
-glibc-loc string
66+
Path to the glibc ld.so file (default "/opt/glibc-2.18/lib/ld-2.18.so")
67+
-glibc-lib-loc
68+
Path to the glibc lib folder (default "/opt/glibc-2.18/lib")
69+
-autostart
70+
Autostarts Factorio Server when FSM is starting. Default false [true/false]
71+
(If no IP and/or port provided at startup, it will bind the factorio server to all interfaces
72+
and set the server port to the default 34197, always loads latest save)
73+
6474
Example:
6575
6676
./factorio-server-manager --dir /home/user/.factorio --host 10.0.0.1
6777
78+
Custom glibc example:
79+
80+
./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
81+
6882
```
6983

7084
## Manage Factorio Server

src/factorio_server.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,14 @@ func initFactorio() (f *FactorioServer, err error) {
9696

9797
log.Printf("Loaded Factorio settings from %s\n", settingsPath)
9898

99+
out := []byte{}
99100
//Load factorio version
100-
out, err := exec.Command(config.FactorioBinary, "--version").Output()
101+
if config.glibcCustom == "true" {
102+
out, err = exec.Command(config.glibcLocation, "--library-path", config.glibcLibLoc, config.FactorioBinary, "--version").Output()
103+
} else {
104+
out, err = exec.Command(config.FactorioBinary, "--version").Output()
105+
}
106+
101107
if err != nil {
102108
log.Printf("error on loading factorio version: %s", err)
103109
return
@@ -163,13 +169,21 @@ func (f *FactorioServer) Run() error {
163169
ioutil.WriteFile(filepath.Join(config.FactorioConfigDir, config.SettingsFile), data, 0644)
164170
}
165171

166-
args := []string{
172+
args := []string{}
173+
174+
//The factorio server refenences its executable-path, since we execute the ld.so file and pass the factorio binary as a parameter
175+
//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
176+
if config.glibcCustom == "true" {
177+
log.Println("Custom glibc selected, glibc.so location:", config.glibcLocation, " lib location:", config.glibcLibLoc)
178+
args = append(args, "--library-path", config.glibcLibLoc, config.FactorioBinary, "--executable-path", config.FactorioBinary)
179+
}
180+
181+
args = append(args,
167182
"--bind", (f.BindIP),
168183
"--port", strconv.Itoa(f.Port),
169184
"--server-settings", filepath.Join(config.FactorioConfigDir, config.SettingsFile),
170185
"--rcon-port", strconv.Itoa(config.FactorioRconPort),
171-
"--rcon-password", config.FactorioRconPass,
172-
}
186+
"--rcon-password", config.FactorioRconPass)
173187

174188
if(f.Version.Greater(Version{0,17,0})) {
175189
args = append(args, "--server-adminlist", filepath.Join(config.FactorioConfigDir, config.FactorioAdminFile))
@@ -181,9 +195,13 @@ func (f *FactorioServer) Run() error {
181195
args = append(args, "--start-server", filepath.Join(config.FactorioSavesDir, f.Savefile))
182196
}
183197

184-
log.Println("Starting server with command: ", config.FactorioBinary, args)
185-
186-
f.Cmd = exec.Command(config.FactorioBinary, args...)
198+
if config.glibcCustom == "true" {
199+
log.Println("Starting server with command: ", config.glibcLocation, args)
200+
f.Cmd = exec.Command(config.glibcLocation, args...)
201+
} else {
202+
log.Println("Starting server with command: ", config.FactorioBinary, args)
203+
f.Cmd = exec.Command(config.FactorioBinary, args...)
204+
}
187205

188206
f.StdOut, err = f.Cmd.StdoutPipe()
189207
if err != nil {

src/main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ type Config struct {
3535
SettingsFile string `json:"settings_file"`
3636
LogFile string `json:"log_file"`
3737
ConfFile string
38+
glibcCustom string
39+
glibcLocation string
40+
glibcLibLoc string
3841
}
3942

4043
var (
@@ -73,9 +76,14 @@ func parseFlags() {
7376
factorioConfigFile := flag.String("config", "config/config.ini", "Specify location of Factorio config.ini file")
7477
factorioMaxUpload := flag.Int64("max-upload", 1024*1024*20, "Maximum filesize for uploaded files (default 20MB).")
7578
factorioBinary := flag.String("bin", "bin/x64/factorio", "Location of Factorio Server binary file")
79+
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")
80+
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)")
81+
glibcLibLoc := flag.String("glibc-lib-loc", "/opt/glibc-2.18/lib", "Location of glibc lib folder (ex. /opt/glibc-2.18/lib)")
7682

7783
flag.Parse()
78-
84+
config.glibcCustom = *glibcCustom
85+
config.glibcLocation = *glibcLocation
86+
config.glibcLibLoc = *glibcLibLoc
7987
config.ConfFile = *confFile
8088
config.FactorioDir = *factorioDir
8189
config.ServerIP = *serverIP
@@ -123,7 +131,7 @@ func main() {
123131

124132
// Initialize HTTP router
125133
router := NewRouter()
126-
127134
log.Printf("Starting server on: %s:%s", config.ServerIP, config.ServerPort)
128135
log.Fatal(http.ListenAndServe(config.ServerIP+":"+config.ServerPort, router))
136+
129137
}

0 commit comments

Comments
 (0)