diff --git a/deploy/ansible/group_vars/all b/deploy/ansible/group_vars/all index 71b9468d..abbf28d3 100644 --- a/deploy/ansible/group_vars/all +++ b/deploy/ansible/group_vars/all @@ -1,3 +1,4 @@ --- server_user: pronto exe_name: rr-server +matty_name: matty diff --git a/deploy/ansible/inv.yml b/deploy/ansible/inv.yml index 66526354..601eb611 100644 --- a/deploy/ansible/inv.yml +++ b/deploy/ansible/inv.yml @@ -1,6 +1,13 @@ all: hosts: 138.197.142.37: + children: + game: + hosts: + 138.197.142.37: + matchmaker: + hosts: + 138.197.142.37: vars: ansible_connection: ssh ansible_user: root diff --git a/deploy/ansible/play-configure.yml b/deploy/ansible/play-configure.yml index 88b08772..88f1cfd1 100644 --- a/deploy/ansible/play-configure.yml +++ b/deploy/ansible/play-configure.yml @@ -1,7 +1,13 @@ --- -- name: Configure all hosts +- name: Configure game servers gather_facts: false - hosts: all + hosts: game roles: - - configure + - configure-game + +- name: Configure matchmaking servers + gather_facts: false + hosts: matchmaker + roles: + - configure-matchmaker diff --git a/deploy/ansible/play-deploy.yml b/deploy/ansible/play-deploy.yml index aaf73dec..79d705de 100644 --- a/deploy/ansible/play-deploy.yml +++ b/deploy/ansible/play-deploy.yml @@ -1,7 +1,13 @@ --- -- name: Deploy all hosts +- name: Deploy game servers gather_facts: false - hosts: all + hosts: game roles: - - deploy + - deploy-game + +- name: Deploy matchmaking servers + gather_facts: false + hosts: matchmaker + roles: + - deploy-matchmaker diff --git a/deploy/ansible/roles/configure/handlers/main.yml b/deploy/ansible/roles/configure-game/handlers/main.yml similarity index 100% rename from deploy/ansible/roles/configure/handlers/main.yml rename to deploy/ansible/roles/configure-game/handlers/main.yml diff --git a/deploy/ansible/roles/configure/tasks/main.yml b/deploy/ansible/roles/configure-game/tasks/main.yml similarity index 100% rename from deploy/ansible/roles/configure/tasks/main.yml rename to deploy/ansible/roles/configure-game/tasks/main.yml diff --git a/deploy/ansible/roles/configure/templates/harvard.service b/deploy/ansible/roles/configure-game/templates/harvard.service similarity index 100% rename from deploy/ansible/roles/configure/templates/harvard.service rename to deploy/ansible/roles/configure-game/templates/harvard.service diff --git a/deploy/ansible/roles/configure-matchmaker/handlers/main.yml b/deploy/ansible/roles/configure-matchmaker/handlers/main.yml new file mode 100644 index 00000000..e91e89f8 --- /dev/null +++ b/deploy/ansible/roles/configure-matchmaker/handlers/main.yml @@ -0,0 +1,11 @@ +--- +# Configuration Handlers +- + +- name: reload systemctl daemon + command: systemctl daemon-reload + +- name: restart matty + service: + name: matty + state: restarted diff --git a/deploy/ansible/roles/configure-matchmaker/tasks/main.yml b/deploy/ansible/roles/configure-matchmaker/tasks/main.yml new file mode 100644 index 00000000..daebcbce --- /dev/null +++ b/deploy/ansible/roles/configure-matchmaker/tasks/main.yml @@ -0,0 +1,13 @@ +--- +# Server Configuration +- + +- name: copy matty service + template: + src: matty.service + dest: /lib/systemd/system/matty.service + owner: "{{ server_user }}" + group: "{{ server_user }}" + notify: + - reload systemctl daemon + - restart matty diff --git a/deploy/ansible/roles/configure-matchmaker/templates/matty.service b/deploy/ansible/roles/configure-matchmaker/templates/matty.service new file mode 100644 index 00000000..569eec52 --- /dev/null +++ b/deploy/ansible/roles/configure-matchmaker/templates/matty.service @@ -0,0 +1,27 @@ +[Unit] +Description=pronto harvard server +ConditionPathExists=/home/{{ server_user }}/{{ matty_name }} +After=network.target + +[Service] +Type=simple +User={{ server_user }} +Group={{ server_user }} + +Restart=on-failure +RestartSec=10 +startLimitIntervalSec=60 + +WorkingDirectory=/home/{{ server_user }} +ExecStart=/home/{{ server_user }}/{{ matty_name }} + +PermissionsStartOnly=true +ExecStartPre=/bin/mkdir -p /var/log/{{ matty_name }} +ExecStartPre=/bin/chown syslog:adm /var/log/{{ matty_name }} +ExecStartPre=/bin/chmod 755 /var/log/{{ matty_name }} +StandardOutput=syslog +StandardError=syslog +SyslogIdentifier={{ matty_name }} + +[Install] +WantedBy=multi-user.target diff --git a/deploy/ansible/roles/deploy/handlers/main.yml b/deploy/ansible/roles/deploy-game/handlers/main.yml similarity index 100% rename from deploy/ansible/roles/deploy/handlers/main.yml rename to deploy/ansible/roles/deploy-game/handlers/main.yml diff --git a/deploy/ansible/roles/deploy/tasks/main.yml b/deploy/ansible/roles/deploy-game/tasks/main.yml similarity index 100% rename from deploy/ansible/roles/deploy/tasks/main.yml rename to deploy/ansible/roles/deploy-game/tasks/main.yml diff --git a/deploy/ansible/roles/deploy-matchmaker/handlers/main.yml b/deploy/ansible/roles/deploy-matchmaker/handlers/main.yml new file mode 100644 index 00000000..e91e89f8 --- /dev/null +++ b/deploy/ansible/roles/deploy-matchmaker/handlers/main.yml @@ -0,0 +1,11 @@ +--- +# Configuration Handlers +- + +- name: reload systemctl daemon + command: systemctl daemon-reload + +- name: restart matty + service: + name: matty + state: restarted diff --git a/deploy/ansible/roles/deploy-matchmaker/tasks/main.yml b/deploy/ansible/roles/deploy-matchmaker/tasks/main.yml new file mode 100644 index 00000000..2d12b7b0 --- /dev/null +++ b/deploy/ansible/roles/deploy-matchmaker/tasks/main.yml @@ -0,0 +1,14 @@ +--- +# Server Deployment +- + +- name: copy server executable + copy: + src: ../../Build/{{ matty_name }} + dest: /home/{{ server_user }}/{{ matty_name }} + owner: "{{ server_user }}" + group: "{{ server_user }}" + mode: '0700' + notify: + - reload systemctl daemon + - restart matty diff --git a/matchmaker/Makefile b/matchmaker/Makefile new file mode 100644 index 00000000..e1aed5d1 --- /dev/null +++ b/matchmaker/Makefile @@ -0,0 +1,4 @@ +all: build + +build: + env GOOS=linux GOARCH=amd64 go build -o ../Build/matty diff --git a/matchmaker/go.mod b/matchmaker/go.mod new file mode 100644 index 00000000..ed4a1f6d --- /dev/null +++ b/matchmaker/go.mod @@ -0,0 +1,12 @@ +module matty + +go 1.12 + +require ( + github.com/google/logger v1.0.1 + github.com/gorilla/mux v1.7.3 + github.com/mitchellh/go-homedir v1.1.0 + github.com/spf13/cobra v0.0.5 + github.com/spf13/viper v1.5.0 + github.com/urfave/negroni v1.0.0 +) diff --git a/matchmaker/main.go b/matchmaker/main.go new file mode 100644 index 00000000..dc742c9c --- /dev/null +++ b/matchmaker/main.go @@ -0,0 +1,48 @@ +package main + +import ( + "github.com/google/logger" + "github.com/gorilla/mux" + "github.com/urfave/negroni" + "io/ioutil" + "net/http" +) + +const addr = "localhost:4444" + +func main() { + log := logger.Init("Logger", true, true, ioutil.Discard) + defer log.Close() + + startServer() +} + +func startServer() { + router := mux.NewRouter() + + router.Handle("/list", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + //json.NewEncoder(w).Encode(map[string]bool{"ok": true}) + })).Methods("GET") + + router.Handle("/start", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + //json.NewEncoder(w).Encode(map[string]bool{"ok": true}) + })).Methods("PUT") + + router.Handle("/join/{id}", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + //json.NewEncoder(w).Encode(map[string]bool{"ok": true}) + })).Methods("POST") + + negroniServer := negroni.Classic() + negroniServer.UseHandler(router) + + logger.Infof("Starting server on %s", addr) + + server := &http.Server{ + Addr: addr, + Handler: negroniServer, + } + + if err := server.ListenAndServe(); err != nil { + logger.Fatalf("Failed to start server: %v", err) + } +}