Skip to content

Commit

Permalink
add ansible
Browse files Browse the repository at this point in the history
  • Loading branch information
warycat committed Dec 13, 2020
1 parent 0c9d927 commit 4473325
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 0 deletions.
3 changes: 3 additions & 0 deletions infra/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[defaults]
inventory = hosts

3 changes: 3 additions & 0 deletions infra/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
echo "starting to deploy";
ansible-playbook vm.yml
6 changes: 6 additions & 0 deletions infra/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cloud:
hosts:
i1.rustgym.com:
vars:
ansible_user: rustgym

8 changes: 8 additions & 0 deletions infra/rustgym-nginx.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
location / {
proxy_pass http://127.0.0.1:8080;
}
}
71 changes: 71 additions & 0 deletions infra/vm.yml
Original file line number Diff line number Diff line change
@@ -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 &'

1 change: 1 addition & 0 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 4473325

Please sign in to comment.