From ba90497f078dade8558ef5a7070f3a987f484d33 Mon Sep 17 00:00:00 2001 From: YAMASAKI Masahide Date: Fri, 11 Oct 2013 23:05:54 +0900 Subject: [PATCH] first commit --- .gitignore | 6 +++ create_torrent.yml | 16 ++++++++ deploy.yml | 8 ++++ distribute_files.yml | 10 +++++ group_vars/all | 30 +++++++++++++++ production | 19 ++++++++++ roles/admin/clone_murder_files/tasks/main.yml | 11 ++++++ roles/admin/distribute_files/tasks/main.yml | 29 ++++++++++++++ roles/admin/start_tracker/tasks/main.yml | 5 +++ roles/admin/stop_all_peering/tasks/main.yml | 5 +++ roles/admin/stop_all_seeding/tasks/main.yml | 5 +++ roles/admin/stop_tracker/tasks/main.yml | 5 +++ roles/murder/clean_temp_files/meta/main.yml | 4 ++ roles/murder/clean_temp_files/tasks/main.yml | 4 ++ roles/murder/common/tasks/main.yml | 7 ++++ roles/murder/create_torrent/meta/main.yml | 3 ++ roles/murder/create_torrent/tasks/main.yml | 21 ++++++++++ roles/murder/peer/meta/main.yml | 3 ++ roles/murder/peer/tasks/main.yml | 38 +++++++++++++++++++ roles/murder/start_seeding/meta/main.yml | 3 ++ roles/murder/start_seeding/tasks/main.yml | 4 ++ roles/murder/stop_peering/meta/main.yml | 4 ++ roles/murder/stop_peering/tasks/main.yml | 4 ++ roles/murder/stop_seeding/meta/main.yml | 4 ++ roles/murder/stop_seeding/tasks/main.yml | 4 ++ site.yml | 6 +++ start_tracker.yml | 7 ++++ stop_all.yml | 7 ++++ stop_seeder_and_tracker.yml | 13 +++++++ 29 files changed, 285 insertions(+) create mode 100644 create_torrent.yml create mode 100644 deploy.yml create mode 100644 distribute_files.yml create mode 100644 group_vars/all create mode 100644 production create mode 100644 roles/admin/clone_murder_files/tasks/main.yml create mode 100644 roles/admin/distribute_files/tasks/main.yml create mode 100644 roles/admin/start_tracker/tasks/main.yml create mode 100644 roles/admin/stop_all_peering/tasks/main.yml create mode 100644 roles/admin/stop_all_seeding/tasks/main.yml create mode 100644 roles/admin/stop_tracker/tasks/main.yml create mode 100644 roles/murder/clean_temp_files/meta/main.yml create mode 100644 roles/murder/clean_temp_files/tasks/main.yml create mode 100644 roles/murder/common/tasks/main.yml create mode 100644 roles/murder/create_torrent/meta/main.yml create mode 100644 roles/murder/create_torrent/tasks/main.yml create mode 100644 roles/murder/peer/meta/main.yml create mode 100644 roles/murder/peer/tasks/main.yml create mode 100644 roles/murder/start_seeding/meta/main.yml create mode 100644 roles/murder/start_seeding/tasks/main.yml create mode 100644 roles/murder/stop_peering/meta/main.yml create mode 100644 roles/murder/stop_peering/tasks/main.yml create mode 100644 roles/murder/stop_seeding/meta/main.yml create mode 100644 roles/murder/stop_seeding/tasks/main.yml create mode 100644 site.yml create mode 100644 start_tracker.yml create mode 100644 stop_all.yml create mode 100644 stop_seeder_and_tracker.yml diff --git a/.gitignore b/.gitignore index ded6067..aef0213 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,9 @@ nosetests.xml .mr.developer.cfg .project .pydevproject + +ansible.cfg +*.pem +*.torrent +stage +murder/ diff --git a/create_torrent.yml b/create_torrent.yml new file mode 100644 index 0000000..30fe4bf --- /dev/null +++ b/create_torrent.yml @@ -0,0 +1,16 @@ + + +- name: Create a torrent + hosts: + - seeder + - tracker + sudo: yes + roles: + - murder/create_torrent + +- name: Start seeding + hosts: seeder + sudo: yes + roles: + - murder/start_seeding + diff --git a/deploy.yml b/deploy.yml new file mode 100644 index 0000000..f243551 --- /dev/null +++ b/deploy.yml @@ -0,0 +1,8 @@ + + +- name: Deploy + hosts: peer + sudo: yes + roles: + - murder/peer + diff --git a/distribute_files.yml b/distribute_files.yml new file mode 100644 index 0000000..446e45b --- /dev/null +++ b/distribute_files.yml @@ -0,0 +1,10 @@ + +- name: Upload the support files + hosts: + - tracker + - seeder + - peer + #sudo: yes + roles: + - admin/distribute_files + diff --git a/group_vars/all b/group_vars/all new file mode 100644 index 0000000..e60a85a --- /dev/null +++ b/group_vars/all @@ -0,0 +1,30 @@ +# The global variable file + +# deploy tag +tag: deploy_test1 + +# path +seeder_files_path: ~/roles +destination_path: /tmp + +# path permission +destination_owner: root +destination_group: root +destination_mod: 755 + +# default tracker port +tracker_port: 8998 + +# tar options +tar_options: --exclude ".git*" --exclude ".svn*" + +# options +no_tag_directory: false +unsafe_please_delete: false + +# system path +torrent_path: . +remote_murder_path: /usr/local/murder +ansible_cache_path: /var/cache/ansible +default_temp_path: /tmp +murder_dist_tgz_file: /tmp/murder_dist_upload.tar.gz diff --git a/production b/production new file mode 100644 index 0000000..89a22b4 --- /dev/null +++ b/production @@ -0,0 +1,19 @@ +[tracker] +10.0.0.1 + +[seeder] +10.0.0.1 + +[peer:children] +seeder +web-servers + + +[web-servers] +10.1.1.1 +10.1.1.2 +10.1.1.3 +10.1.1.4 +10.1.1.[5:19] +10.2.1.[100:109] ansible_connection=ssh ansible_ssh_private_key_file=private.pem ansible_ssh_user=root + diff --git a/roles/admin/clone_murder_files/tasks/main.yml b/roles/admin/clone_murder_files/tasks/main.yml new file mode 100644 index 0000000..3c96e4d --- /dev/null +++ b/roles/admin/clone_murder_files/tasks/main.yml @@ -0,0 +1,11 @@ + +- name: clone murder + git: repo=https://github.com/lg/murder.git dest=./murder + register: clone_status + tags: clone_murder_files + +- name: tar -czf + shell: tar -czf ./murder_dist.tar.gz -C ./murder/dist/ + when: clone_status.changed + tags: clone_murder_files + diff --git a/roles/admin/distribute_files/tasks/main.yml b/roles/admin/distribute_files/tasks/main.yml new file mode 100644 index 0000000..295cbb2 --- /dev/null +++ b/roles/admin/distribute_files/tasks/main.yml @@ -0,0 +1,29 @@ + +- name: mkdir destination_path + file: path={{ destination_path }} state=directory owner=root group=root mode=0755 + tags: distribute_files + +- name: mkdir ansible_cache_path + file: path={{ ansible_cache_path }} state=directory owner=root group=root mode=0755 + tags: distribute_files + + +- name: upload + copy: src={{ murder_dist_tgz_file }} dest={{ ansible_cache_path }}/murder_dist.tar.gz + tags: distribute_files + register: copy_status + +- name: clean up remote_murder_path + shell: | + [ $(find {{ remote_murder_path }}/* | wc -l ) -lt 1000 ] && + rm -rf {{ remote_murder_path }}/* || + ( echo 'Cowardly refusing to remove files! Check the remote_murder_path.' ; exit 1 ) + when: copy_status.changed + tags: distribute_files + +- name: tar xzf + shell: tar xzf {{ ansible_cache_path }}/murder_dist.tar.gz -C "{{ remote_murder_path }}" + when: copy_status.changed + tags: distribute_files + + diff --git a/roles/admin/start_tracker/tasks/main.yml b/roles/admin/start_tracker/tasks/main.yml new file mode 100644 index 0000000..ced4d44 --- /dev/null +++ b/roles/admin/start_tracker/tasks/main.yml @@ -0,0 +1,5 @@ + +- name: start tracker + shell: SCREENRC=/dev/null SYSSCREENRC=/dev/null screen -dmS murder_tracker python {{ remote_murder_path }}/murder_tracker.py && sleep 0.2 + tags: start_tracker + diff --git a/roles/admin/stop_all_peering/tasks/main.yml b/roles/admin/stop_all_peering/tasks/main.yml new file mode 100644 index 0000000..16ae081 --- /dev/null +++ b/roles/admin/stop_all_peering/tasks/main.yml @@ -0,0 +1,5 @@ + +- name: stop all peering + shell: pkill -f "murder_client.py peer" + tags: stop_all_peering + diff --git a/roles/admin/stop_all_seeding/tasks/main.yml b/roles/admin/stop_all_seeding/tasks/main.yml new file mode 100644 index 0000000..2a8a483 --- /dev/null +++ b/roles/admin/stop_all_seeding/tasks/main.yml @@ -0,0 +1,5 @@ + +- name: stop all seeding + shell: pkill -f "SCREEN.*seeder-" + tags: stop_all_seeding + diff --git a/roles/admin/stop_tracker/tasks/main.yml b/roles/admin/stop_tracker/tasks/main.yml new file mode 100644 index 0000000..323ff14 --- /dev/null +++ b/roles/admin/stop_tracker/tasks/main.yml @@ -0,0 +1,5 @@ + +- name: stop tracker + shell: pkill -f 'SCREEN.*murder_tracker.py' + tags: stop_tracker + diff --git a/roles/murder/clean_temp_files/meta/main.yml b/roles/murder/clean_temp_files/meta/main.yml new file mode 100644 index 0000000..aa246a7 --- /dev/null +++ b/roles/murder/clean_temp_files/meta/main.yml @@ -0,0 +1,4 @@ +--- +dependencies: + - { role: murder/common } + diff --git a/roles/murder/clean_temp_files/tasks/main.yml b/roles/murder/clean_temp_files/tasks/main.yml new file mode 100644 index 0000000..5249df7 --- /dev/null +++ b/roles/murder/clean_temp_files/tasks/main.yml @@ -0,0 +1,4 @@ + +- name: clean temp files + shell: rm -rf "{{ filename }}" "{{ filename }}.torrent" + tags: clean_temp_files diff --git a/roles/murder/common/tasks/main.yml b/roles/murder/common/tasks/main.yml new file mode 100644 index 0000000..44c28a3 --- /dev/null +++ b/roles/murder/common/tasks/main.yml @@ -0,0 +1,7 @@ + +- name: set tagname to filename + set_fact: filename={{ default_temp_path }}/{{ tag }}.tar.gz + tags: common + + + diff --git a/roles/murder/create_torrent/meta/main.yml b/roles/murder/create_torrent/meta/main.yml new file mode 100644 index 0000000..280b002 --- /dev/null +++ b/roles/murder/create_torrent/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - { role: murder/common } diff --git a/roles/murder/create_torrent/tasks/main.yml b/roles/murder/create_torrent/tasks/main.yml new file mode 100644 index 0000000..69d350c --- /dev/null +++ b/roles/murder/create_torrent/tasks/main.yml @@ -0,0 +1,21 @@ + +- name: create tar.gz + shell: tar -c -z -C {{ seeder_files_path }}/ -f {{ filename }} {{ tar_options }} . + when: node_type == "seeder" + tags: create_tgz + +- name: set tracker ip + set_fact: tracker_host={{ hostvars[groups['tracker'][0]]['ansible_default_ipv4']['address'] }} + when: node_type == "seeder" + tags: create_torrent + +- name: create torrent + shell: python {{ remote_murder_path }}/murder_make_torrent.py '{{ filename }}' {{ tracker_host }}:{{ tracker_port }} '{{ filename }}.torrent' + when: node_type == "seeder" + tags: create_torrent + +- name: fetch torrent + fetch: src={{ filename }}.torrent dest={{ torrent_path }}/ flat=yes fail_on_missing=yes + when: node_type == "seeder" + tags: fetch_torrent + diff --git a/roles/murder/peer/meta/main.yml b/roles/murder/peer/meta/main.yml new file mode 100644 index 0000000..280b002 --- /dev/null +++ b/roles/murder/peer/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - { role: murder/common } diff --git a/roles/murder/peer/tasks/main.yml b/roles/murder/peer/tasks/main.yml new file mode 100644 index 0000000..7fe01bf --- /dev/null +++ b/roles/murder/peer/tasks/main.yml @@ -0,0 +1,38 @@ + +- name: set destination_path + set_fact: destination_path={{ destination_path }}/{{ tag }} + when: not no_tag_directory + tags: peer + +- name: mkdir destination_path + file: path={{ destination_path }} state=directory owner={{ destination_owner }} group={{ destination_group }} mode={{ destination_mod }} + tags: peer + +- name: delete destination_path/* + shell: rm -rf '{{ destination_path }}a/*' + when: unsafe_please_delete + tags: peer + +- name: check destination_path/* + shell: | + ( + find {{ destination_path }}/* >/dev/null 2>&1 && + echo "destination_path {{ destination_path }} on $HOSTNAME is not empty" && + exit 1 + ) || + exit 0 + when: not no_tag_directory + tags: peer + +- name: upload torrent file + copy: src={{ torrent_path }}/{{ filename|basename }}.torrent dest={{ filename }}.torrent + tags: peer + +- name: run murder_client.py + shell: python {{ remote_murder_path }}/murder_client.py peer '{{ filename }}.torrent' '{{filename}}' {{ ansible_default_ipv4['address'] }} + tags: peer + +- name: tar xf + shell: tar xf {{ filename }} -C "{{ destination_path }}" + tags: peer + diff --git a/roles/murder/start_seeding/meta/main.yml b/roles/murder/start_seeding/meta/main.yml new file mode 100644 index 0000000..280b002 --- /dev/null +++ b/roles/murder/start_seeding/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - { role: murder/common } diff --git a/roles/murder/start_seeding/tasks/main.yml b/roles/murder/start_seeding/tasks/main.yml new file mode 100644 index 0000000..0de460a --- /dev/null +++ b/roles/murder/start_seeding/tasks/main.yml @@ -0,0 +1,4 @@ + +- name: start seeding + shell: SCREENRC=/dev/null SYSSCREENRC=/dev/null screen -dmS 'seeder-{{ tag }}' python {{ remote_murder_path }}/murder_client.py seeder '{{ filename }}.torrent' '{{ filename }}' {{ ansible_default_ipv4['address'] }} + tags: start_seeding diff --git a/roles/murder/stop_peering/meta/main.yml b/roles/murder/stop_peering/meta/main.yml new file mode 100644 index 0000000..aa246a7 --- /dev/null +++ b/roles/murder/stop_peering/meta/main.yml @@ -0,0 +1,4 @@ +--- +dependencies: + - { role: murder/common } + diff --git a/roles/murder/stop_peering/tasks/main.yml b/roles/murder/stop_peering/tasks/main.yml new file mode 100644 index 0000000..a9f8294 --- /dev/null +++ b/roles/murder/stop_peering/tasks/main.yml @@ -0,0 +1,4 @@ + +- name: stop peering + shell: pkill -f "murder_client.py peer.*{{ filename }}" + tags: stop_peering diff --git a/roles/murder/stop_seeding/meta/main.yml b/roles/murder/stop_seeding/meta/main.yml new file mode 100644 index 0000000..aa246a7 --- /dev/null +++ b/roles/murder/stop_seeding/meta/main.yml @@ -0,0 +1,4 @@ +--- +dependencies: + - { role: murder/common } + diff --git a/roles/murder/stop_seeding/tasks/main.yml b/roles/murder/stop_seeding/tasks/main.yml new file mode 100644 index 0000000..ff73066 --- /dev/null +++ b/roles/murder/stop_seeding/tasks/main.yml @@ -0,0 +1,4 @@ + +- name: stop seeding + shell: pkill -f "SCREEN.*seeder-{{ tag }}" + tags: stop_seeding diff --git a/site.yml b/site.yml new file mode 100644 index 0000000..f7f30c8 --- /dev/null +++ b/site.yml @@ -0,0 +1,6 @@ +--- +- distribute_files.yml +- create_torrent.yml +- deploy.yml +- stop_seeder_and_tracker.yml + diff --git a/start_tracker.yml b/start_tracker.yml new file mode 100644 index 0000000..7fecee6 --- /dev/null +++ b/start_tracker.yml @@ -0,0 +1,7 @@ + +- name: start tracker + hosts: tracker + sudo: yes + roles: + - admin/start_tracker + diff --git a/stop_all.yml b/stop_all.yml new file mode 100644 index 0000000..675d4c7 --- /dev/null +++ b/stop_all.yml @@ -0,0 +1,7 @@ + +- name: Stop all peering + hosts: peer + sudo: yes + roles: + - admin/stop_all_peering + diff --git a/stop_seeder_and_tracker.yml b/stop_seeder_and_tracker.yml new file mode 100644 index 0000000..3e2483f --- /dev/null +++ b/stop_seeder_and_tracker.yml @@ -0,0 +1,13 @@ + +- name: Stop seeding + hosts: seeder + sudo: yes + roles: + - murder/stop_seeding + +- name: Stop tracker + hosts: tracker + sudo: yes + roles: + - admin/stop_tracker +