-
Notifications
You must be signed in to change notification settings - Fork 2
/
push_data.yml
154 lines (140 loc) · 4.1 KB
/
push_data.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
---
# This forcibly wipes and loads data from files/cnxarchive_dump.tar.gz.
- name: get database details
hosts: database
vars_prompt:
- name: "db_name"
prompt: "What database are we pushing to?"
default: cnxarchive
- name: "db_user"
prompt: "What database user should we use?"
default: cnxarchive
- name: "db_password"
prompt: "What password should we use for the database user?"
tasks:
- set_fact:
db_name: "{{ db_name }}"
db_user: "{{ db_user }}"
db_password: "{{ db_password }}"
- name: transfer database dump
hosts: database
tasks:
- name: create directory for database dump
file:
path: /tmp/cnxarchive_dump
state: directory
- unarchive:
src: "cnxarchive_dump.tar"
dest: "/tmp/cnxarchive_dump"
- name: stop archive
hosts: archive
tasks:
- become: yes
supervisorctl:
name: "archive:"
state: stopped
- name: stop publishing
hosts: publishing
become: yes
tasks:
- supervisorctl:
name: "publishing:"
state: stopped
- supervisorctl:
name: "publishing_worker:"
state: stopped
- supervisorctl:
name: "channel_processing"
state: stopped
- name: stop zclients
hosts:
- zclient
- pdf_gen
tasks:
- become: yes
supervisorctl:
name: "{{ item }}"
state: stopped
with_items: "[{% for i in range(0, hostvars[inventory_hostname].zclient_count|default(1), 1) %}'{{ 'zclient_instance{}'.format(i) }}',{% endfor %}]"
- name: stop pdf_gen applications
hosts: pdf_gen
tasks:
- become: yes
supervisorctl:
name: pdf_gen
state: stopped
- name: forcibly push data
hosts: database
tasks:
- import_tasks: tasks/create_db_user.yml
vars:
role_attr_flags: 'SUPERUSER'
- name: drop database
become: yes
become_user: postgres
shell: "dropdb {{ db_name }}"
ignore_errors: yes
- name: create database
become: yes
become_user: postgres
shell: "createdb -O {{ db_user }} {{ db_name }}"
- name: load database without files
become: yes
become_user: postgres
shell: "zcat /tmp/cnxarchive_dump/cnxarchive_dump_without_files.sql.gz | psql -U {{ db_user }} {{ db_name }} -f -"
- name: load files table
become: yes
become_user: postgres
shell: zcat '/tmp/cnxarchive_dump/cnxarchive_index_files.txt.gz' '/tmp/cnxarchive_dump/cnxarchive_other_files.txt.gz' | psql -U {{ db_user }} {{ db_name }} -c "ALTER TABLE files DISABLE TRIGGER USER; COPY files (fileid, md5, sha1, file, media_type) FROM STDIN; ALTER TABLE files ENABLE TRIGGER USER;"
- name: load module files table
become: yes
become_user: postgres
shell: zcat '/tmp/cnxarchive_dump/cnxarchive_index_module_files.txt' | psql -U {{ db_user }} {{ db_name }} -c "ALTER TABLE module_files DISABLE TRIGGER USER; COPY module_files (module_ident, fileid, filename) FROM STDIN; ALTER TABLE module_files ENABLE TRIGGER USER;"
- name: remove dump files
file:
path: /tmp/cnxarchive_dump
state: absent
- name: start archive
hosts: archive
tasks:
- become: yes
supervisorctl:
name: "archive:"
state: started
- name: start publishing
hosts: publishing
become: yes
tasks:
- supervisorctl:
name: "publishing:"
state: started
- supervisorctl:
name: "publishing_worker:"
state: started
- supervisorctl:
name: "channel_processing"
state: started
- name: start zclients
hosts:
- zclient
- pdf_gen
tasks:
- become: yes
supervisorctl:
name: "{{ item }}"
state: started
with_items: "[{% for i in range(0, hostvars[inventory_hostname].zclient_count|default(1), 1) %}'{{ 'zclient_instance{}'.format(i) }}',{% endfor %}]"
- name: start pdf_gen applications
hosts: pdf_gen
tasks:
- become: yes
supervisorctl:
name: pdf_gen
state: started
- name: restart varnish
hosts: frontend
tasks:
- service:
name: varnish
state: restarted
become: yes