Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deploy/ansible/group_vars/all
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
server_user: pronto
exe_name: rr-server
matty_name: matty
7 changes: 7 additions & 0 deletions deploy/ansible/inv.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 9 additions & 3 deletions deploy/ansible/play-configure.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 9 additions & 3 deletions deploy/ansible/play-deploy.yml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions deploy/ansible/roles/configure-matchmaker/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# Configuration Handlers
-

- name: reload systemctl daemon
command: systemctl daemon-reload

- name: restart matty
service:
name: matty
state: restarted
13 changes: 13 additions & 0 deletions deploy/ansible/roles/configure-matchmaker/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions deploy/ansible/roles/configure-matchmaker/templates/matty.service
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions deploy/ansible/roles/deploy-matchmaker/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# Configuration Handlers
-

- name: reload systemctl daemon
command: systemctl daemon-reload

- name: restart matty
service:
name: matty
state: restarted
14 changes: 14 additions & 0 deletions deploy/ansible/roles/deploy-matchmaker/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions matchmaker/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
all: build

build:
env GOOS=linux GOARCH=amd64 go build -o ../Build/matty
12 changes: 12 additions & 0 deletions matchmaker/go.mod
Original file line number Diff line number Diff line change
@@ -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
)
48 changes: 48 additions & 0 deletions matchmaker/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
}