From 8642b771d5b689261ee9bf4b107f05c9a1b297de Mon Sep 17 00:00:00 2001 From: majormjr Date: Tue, 3 May 2016 11:56:06 -0400 Subject: [PATCH] Added flag for config file --- Makefile | 4 ++-- docker/Dockerfile | 2 -- docker/init.sh | 2 +- handlers.go | 3 ++- main.go | 7 ++++++- server.go | 2 +- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 441f198..4bc7b05 100644 --- a/Makefile +++ b/Makefile @@ -2,5 +2,5 @@ # build: - go build -o $(HOME)/factorio-server-manager/factorio-server-manager - cp -r app/ $(HOME)/factorio-server-manager/ + go build -o $(HOME)/factorio-server/factorio-server-manager + cp -r app/ $(HOME)/factorio-server/ diff --git a/docker/Dockerfile b/docker/Dockerfile index a9b3fa0..817356d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -25,8 +25,6 @@ RUN curl -s -L -S -k https://www.factorio.com/get-download/$FACTORIO_VERSION/hea mkdir -p /var/lib/nginx/tmp && \ chown nginx:root /var/lib/nginx -ADD "conf.json" "/opt/factorio-server/conf.json" - EXPOSE 80/tcp 443/tcp 34190-34200/udp ENTRYPOINT ["/opt/init.sh"] diff --git a/docker/init.sh b/docker/init.sh index 3de6f99..dde1467 100755 --- a/docker/init.sh +++ b/docker/init.sh @@ -27,6 +27,6 @@ if [ ! -f /security/passwords.conf ]; then echo -n "admin:" >> /security/passwords.conf openssl passwd -apr1 $ADMIN_PASSWORD >> /security/passwords.conf fi -ls -R /opt/factorio-server + nohup nginx & /opt/factorio-server/factorio-server-manager -dir '/opt/factorio' -conf '/opt/factorio-server/conf.json' diff --git a/handlers.go b/handlers.go index 36d3a56..b6b4271 100644 --- a/handlers.go +++ b/handlers.go @@ -462,6 +462,7 @@ func StartServer(w http.ResponseWriter, r *http.Request) { // Check if savefile was submitted with request to start server. if FactorioServ.Savefile == "" { log.Printf("Error starting Factorio server: %s", err) + resp.Success = false resp.Data = fmt.Sprintf("Error starting Factorio server: %s", err) if err := json.NewEncoder(w).Encode(resp); err != nil { log.Printf("Error encoding config file JSON reponse: ", err) @@ -475,7 +476,7 @@ func StartServer(w http.ResponseWriter, r *http.Request) { log.Printf("Error starting Factorio server: %s", err) resp.Data = fmt.Sprintf("Error starting Factorio server: %s", err) if err := json.NewEncoder(w).Encode(resp); err != nil { - log.Printf("Error encoding config file JSON reponse: ", err) + log.Printf("Error encoding start server JSON reponse: ", err) } return } diff --git a/main.go b/main.go index c286780..03ba027 100644 --- a/main.go +++ b/main.go @@ -22,6 +22,7 @@ type Config struct { Username string `json:"username"` Password string `json:"password"` DatabaseFile string `json:"database_file"` + ConfFile string } var ( @@ -72,10 +73,14 @@ func parseFlags() { } func main() { - loadServerConfig("./conf.json") + confFile := flag.String("conf", "./conf.json", "Specify location of Factorio Server Manager config file.") + config.ConfFile = *confFile + loadServerConfig(config.ConfFile) + // Initialize Factorio Server struct FactorioServ = initFactorio() + // Initialize authentication system Auth = initAuth() Auth.createAuthDb(config.DatabaseFile) Auth.createRoles() diff --git a/server.go b/server.go index b9bdff9..80ef087 100644 --- a/server.go +++ b/server.go @@ -17,7 +17,7 @@ type FactorioServer struct { AutosaveSlots int `json:"autosave_slots"` Port int `json:"port"` DisallowCmd bool `json:"disallow_cmd"` - Running bool `json:"bool"` + Running bool `json:"running"` PeerToPeer bool `json:"peer2peer"` AutoPause bool `json:"auto_pause"` StdOut io.ReadCloser