Skip to content

Latest commit

 

History

History
221 lines (162 loc) · 3.83 KB

INSTALL.md

File metadata and controls

221 lines (162 loc) · 3.83 KB

Prepare environment

Update packages

apt update
apt upgrade

Install required packages

apt install build-essential cmake postgresql git libpq-dev libavahi-compat-libdnssd-dev libbz2-dev libexpat1-dev libpq-dev

Install rustup

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source ~/.bashrc

Get code

git clone --recursive https://github.com/w3champions/flo.git

Prepare database

install diesel_cli

cd flo
export PQ_LIB_DIR=/usr/lib/x86_64-linux-gnu/
cargo install diesel_cli --no-default-features --features postgres

enable password auth instead of peer by editing /etc/postgresql/11/main/pg_hba.conf

should be local all postgres md5

restart postgres

systemctl restart postgresql

set password for pgsql user

su postgres
pgsql
postgres=# \password
Enter new password: 
Enter it again: 
postgres=# exit
exit

create .env file in flo code root

RUST_LOG=debug
DATABASE_URL=postgres://postgres:postgres@localhost/flo
JWT_SECRET_BASE64=dGVzdHRlc3R0ZXN0dGVzdHRlc3R0ZXN0dGVzdHRlc3R0ZXN0dGVzdHRlc3Q=

as pgsql user create database and fill it using diesel (use your password)

export PGPASSWORD=postgres
psql -U postgres -c "create database flo"
diesel setup

add api_client and node rows to postgres (NOTE: use server ip and not 127.0.0.1)

psql -U postgres -d flo -c "insert into api_client (name, secret_key) VALUES ('mawa', 'mawa')"
psql -U postgres -d flo -c "insert into node (name, location, secret, ip_addr) VALUES ('mawa', 'US 6', 'mawa', '127.0.0.1')"

Building

build controller and node services

cargo build -p flo-controller-service --release
cargo build -p flo-node-service --release

Running

export secret key

export FLO_NODE_SECRET='mawa'

run node first

./target/release/flo-node-service
./target/release/flo-controller-service

Running as sercice

Create following service files for systemd:

  • /usr/lib/systemd/system/flo-node.service
[Unit]
Description=Flo Node Service
After=network.target
After=postgresql.target

[Service]
Type=simple
WorkingDirectory=/root/flo
ExecStart=/bin/bash -l -c "FLO_NODE_SECRET='mawa' ./target/release/flo-node-service"
Restart=on-failure

[Install]
WantedBy=multi-user.target
  • /usr/lib/systemd/system/flo-controller.service
[Unit]
Description=Flo Controller Service
After=network.target
After=postgresql.target

[Service]
Type=simple
WorkingDirectory=/root/flo
ExecStart=/bin/bash -l -c "FLO_NODE_SECRET='mawa' ./target/release/flo-controller-service"
Restart=on-failure

[Install]
WantedBy=multi-user.target

Make those visible with running:

systemctl daemon-reload

Run with

systemctl start flo-node
systemctl start flo-controller

Trace logs:

journalctl -f -u flo-node

Run automatically with system start:

systemctl enable postgresql
systemctl enable flo-node
systemctl enable flo-controller

TESTING

build flo-cli

apt install libavahi-compat-libdnssd-dev zlib1g-dev libbz2-dev
cargo build -p flo-cli --release

run

./target/release/flo-cli server --help
./target/release/flo-cli server list-nodes
./target/release/flo-cli server upsert-player 1

copy token from the last command and use it to run flo-worker locally

flo-worker.exe --controller-host="45.33.104.208" --token="eyJ0...."

if you get no errors you can create test game

./target/release/flo-cli server run-game 2

Tips

to update ip addres you may use:

psql -U postgres -d flo -c "update node set ip_addr = '45.33.104.208' WHERE id = 1"
psql -U postgres -d flo -c "select * from node"
systemctl restart flo-node
systemctl restart flo-controller