diff --git a/infra/ansible.cfg b/infra/ansible.cfg new file mode 100644 index 00000000..77428ed3 --- /dev/null +++ b/infra/ansible.cfg @@ -0,0 +1,3 @@ +[defaults] +inventory = hosts + diff --git a/infra/deploy.sh b/infra/deploy.sh new file mode 100755 index 00000000..1c08ef9f --- /dev/null +++ b/infra/deploy.sh @@ -0,0 +1,3 @@ +#!/bin/bash +echo "starting to deploy"; +ansible-playbook vm.yml \ No newline at end of file diff --git a/infra/hosts b/infra/hosts new file mode 100644 index 00000000..897aee07 --- /dev/null +++ b/infra/hosts @@ -0,0 +1,6 @@ +cloud: + hosts: + i1.rustgym.com: + vars: + ansible_user: rustgym + diff --git a/infra/rustgym-nginx.cfg b/infra/rustgym-nginx.cfg new file mode 100644 index 00000000..88cef3e9 --- /dev/null +++ b/infra/rustgym-nginx.cfg @@ -0,0 +1,8 @@ +server { + listen 80 default_server; + listen [::]:80 default_server; + server_name _; + location / { + proxy_pass http://127.0.0.1:8080; + } +} \ No newline at end of file diff --git a/infra/vm.yml b/infra/vm.yml new file mode 100644 index 00000000..a103478f --- /dev/null +++ b/infra/vm.yml @@ -0,0 +1,71 @@ +--- +- hosts: all + vars: + version: v0.0.9 + tasks: + - name: install sqlite + apt: + name: sqlite + state: present + become: yes + - name: install nginx + apt: + name: nginx + state: latest + become: yes + - name: stop nginx + service: + name: nginx + state: stopped + become: yes + - name: copy nginx config + copy: + src: rustgym-nginx.cfg + dest: /etc/nginx/sites-available/rustgym-nginx.cfg + become: yes + - name: symlink nginx config + file: + src: /etc/nginx/sites-available/rustgym-nginx.cfg + dest: /etc/nginx/sites-enabled/default + state: link + become: yes + - name: start nginx + service: + name: nginx + state: started + become: yes + - name: create version dir + file: + path: '/home/rustgym/{{version}}' + state: directory + mode: '0755' + - name: download rustgym + get_url: + url: 'https://github.com/warycat/rustgym/releases/download/{{version}}/rustgym.tar.gz' + dest: /home/rustgym/rustgym.tar.gz + - name: unarchive rustgym + unarchive: + src: /home/rustgym/rustgym.tar.gz + dest: '/home/rustgym/{{version}}' + remote_src: yes + - name: Get running processes list from remote host + ignore_errors: yes + shell: "ps -few | grep rustgym-server | awk '{print $2}'" + register: running_processes + - name: Kill running processes + ignore_errors: yes + shell: "kill {{ item }}" + with_items: "{{ running_processes.stdout_lines }}" + - wait_for: + path: "/proc/{{ item }}/status" + state: absent + with_items: "{{ running_processes.stdout_lines }}" + ignore_errors: yes + register: rustgym_processes + - name: Force kill stuck processes + ignore_errors: yes + shell: "kill -9 {{ item }}" + with_items: "{{ rustgym_processes.results | select('failed') | map(attribute='item') | list }}" + - name: start rustgym + shell: '/home/rustgym/{{version}}/target/release/rustgym-server >> /home/rustgym/rusgym.log &>> /home/rustgym/rusgym.error.log &' + diff --git a/server/src/main.rs b/server/src/main.rs index 07d2f9f4..e326898c 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -7,6 +7,7 @@ async fn greet(req: HttpRequest) -> impl Responder { #[actix_web::main] async fn main() -> std::io::Result<()> { + println!("rustgym server v0.0.1"); HttpServer::new(|| { App::new() .route("/", web::get().to(greet))