forked from ec-europa/joinup-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.solr.xml
244 lines (229 loc) · 11.5 KB
/
build.solr.xml
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?xml version="1.0" encoding="UTF-8" ?>
<project name="Solr" default="help">
<taskdef name="solr-backup" classname="\DrupalProject\Phing\SolrBackup" />
<target name="download-apache-solr">
<if>
<available file="${solr.dir}" type="dir" property="solr.dir.available" />
<then>
<echo message="Apache Solr installation directory exists (${solr.dir}), skipping download." />
</then>
<else>
<if>
<available file="${tmp.dir}/${solr.tarball.filename}" type="file" property="solr.tarball.available" />
<then>
<echo message="Apache Solr tarball already downloaded to ${tmp.dir}/${solr.tarball.filename}, skipping download." />
</then>
<else>
<mkdir dir="${tmp.dir}" />
<!-- Temporarily increase the memory limit so the download doesn't run out of memory. -->
<php expression="ini_get('memory_limit');" returnproperty="memory_limit.original" />
<php expression="ini_set('memory_limit', '1G');" />
<httpget url="${solr.download.url}" dir="${tmp.dir}" />
<!-- Restore the original memory limit. -->
<php expression="ini_set('memory_limit', '${memory_limit.original}');" />
</else>
</if>
<!-- Use the faster native untar on UNIX systems. -->
<if>
<os family="unix" />
<then>
<mkdir dir="${solr.vendor.dir}" />
<exec
command='tar xzf "${tmp.dir}/${solr.tarball.filename}" -C "${solr.vendor.dir}"'
dir="${project.basedir}"
passthru="true"
checkreturn="true" />
</then>
<else>
<untar file="${tmp.dir}/${solr.tarball.filename}" todir="${solr.vendor.dir}" />
</else>
</if>
</else>
</if>
<!-- Create a symlink of the Solr executable in the vendor/bin directory. -->
<if>
<available file="${solr.bin}" type="file" property="file.exists" />
<then>
<echo message="Symlink to Solr binary already exists in ${solr.bin}. Deleting symlink." />
<delete file="${solr.bin}" failonerror="false" />
</then>
</if>
<echo message="Creating symlink to Solr binary." />
<symlink
target="${solr.dir}/bin/solr"
link="${solr.bin}"
/>
</target>
<target
name="start-apache-solr"
description="Start the Apache Solr server.">
<!-- Check if Solr is already running before attempting to start it. -->
<exec dir="${solr.dir}"
command="./bin/solr status"
returnProperty="solr.status"
passthru="true" />
<if>
<equals arg1="${solr.status}" arg2="0" />
<then>
<echo message="Apache Solr is already running." />
</then>
<else>
<exec dir="${solr.dir}"
command="./bin/solr start"
checkreturn="true"
passthru="true" />
</else>
</if>
</target>
<target
name="restart-apache-solr"
description="Restart the Apache Solr server.">
<exec dir="${solr.dir}"
command="./bin/solr restart"
checkreturn="true"
passthru="true" />
</target>
<target
name="stop-apache-solr"
description="Stop the Apache Solr server.">
<exec dir="${solr.dir}"
command="./bin/solr stop"
checkreturn="true"
passthru="true" />
</target>
<target name="configure-apache-solr">
<if>
<not>
<available file="${solr.config.dir}" type="dir" property="solr.config.dir.available" />
</not>
<then>
<fail message="Search API Solr is not installed. Did you run `composer install`?" />
</then>
</if>
<if>
<available file="${solr.core.published.dir}" type="dir" property="solr.core.published.dir.available" />
<then>
<echo message="A Solr core has already been configured at ${solr.core.published.dir}. Skipping." />
</then>
<else>
<!-- Create the Solr core. -->
<exec dir="${solr.dir}"
command="./bin/solr create_core -c ${solr.core.published.name}"
checkreturn="true"
passthru="true"/>
<!-- Copy the configuration. -->
<copy todir="${solr.core.published.dir}/conf" overwrite="true">
<fileset dir="${solr.config.dir}" />
</copy>
</else>
</if>
<if>
<available file="${solr.core.unpublished.dir}" type="dir" property="solr.core.unpublished.dir.available" />
<then>
<echo message="A Solr core has already been configured at ${solr.core.unpublished.dir}. Skipping." />
</then>
<else>
<!-- Create the Solr core. -->
<exec dir="${solr.dir}"
command="./bin/solr create_core -c ${solr.core.unpublished.name}"
checkreturn="true"
passthru="true"/>
<!-- Copy the configuration. -->
<copy todir="${solr.core.unpublished.dir}/conf" overwrite="true">
<fileset dir="${solr.config.dir}" />
</copy>
</else>
</if>
<!-- Restart Solr so our configuration changes are picked up. -->
<phingcall target="restart-apache-solr" />
</target>
<!-- Override Solr server connection information in the settings.local.php file. -->
<target name="configure-apache-solr-drupal">
<phingcall target="include-local-settings" />
<phingcall target="create-local-settings" />
<reflexive>
<fileset dir="${website.settings.dir}">
<include pattern="settings.local.php"/>
</fileset>
<filterchain>
<replaceregexp>
<regexp
pattern="^\$config\['search_api.server.solr_(un)?published'\]\['backend_config'\]\['connector_config'\]\['(scheme|host|port|path|core)'] = '.*';\s*"
replace=""
modifiers="m"/>
</replaceregexp>
</filterchain>
</reflexive>
<append
destFile="${website.settings.local.php}"
text="${line.separator}$config['search_api.server.solr_published']['backend_config']['connector_config']['scheme'] = '${solr.core.published.scheme}';
${line.separator}$config['search_api.server.solr_published']['backend_config']['connector_config']['host'] = '${solr.core.published.host}';
${line.separator}$config['search_api.server.solr_published']['backend_config']['connector_config']['port'] = '${solr.core.published.port}';
${line.separator}$config['search_api.server.solr_published']['backend_config']['connector_config']['path'] = '${solr.core.published.path}';
${line.separator}$config['search_api.server.solr_published']['backend_config']['connector_config']['core'] = '${solr.core.published.name}';
${line.separator}$config['search_api.server.solr_unpublished']['backend_config']['connector_config']['scheme'] = '${solr.core.unpublished.scheme}';
${line.separator}$config['search_api.server.solr_unpublished']['backend_config']['connector_config']['host'] = '${solr.core.unpublished.host}';
${line.separator}$config['search_api.server.solr_unpublished']['backend_config']['connector_config']['port'] = '${solr.core.unpublished.port}';
${line.separator}$config['search_api.server.solr_unpublished']['backend_config']['connector_config']['path'] = '${solr.core.unpublished.path}';
${line.separator}$config['search_api.server.solr_unpublished']['backend_config']['connector_config']['core'] = '${solr.core.unpublished.name}';${line.separator}"/>
</target>
<target
name="setup-apache-solr"
description="Set up Apache Solr."
depends="download-apache-solr, start-apache-solr, configure-apache-solr" />
<target
name="reindex-apache-solr"
description="Re-indexes the two solr cores.">
<drush
command="sapi-c"
assume="yes"
root="${website.drupal.dir}"
bin="${drush.bin}">
</drush>
<drush
command="sapi-i"
assume="yes"
root="${website.drupal.dir}"
bin="${drush.bin}">
<option name="batch-size" value="250" />
</drush>
</target>
<target name="purge-solr-backend" description="Empty Solr cores">
<exec command="curl --verbose '${solr.core.published.url}/${solr.core.published.name}/update?stream.body=<delete><query>*:*</query></delete>&commit=true'"
passthru="true"/>
<exec command="curl --verbose '${solr.core.unpublished.url}/${solr.core.unpublished.name}/update?stream.body=<delete><query>*:*</query></delete>&commit=true'"
passthru="true"/>
</target>
<target name="backup-apache-solr">
<echo message="Backing-up the Solr server."/>
<delete dir="${exports.solr.destination.folder}/snapshot.published"/>
<delete dir="${exports.solr.destination.folder}/snapshot.unpublished"/>
<solr-backup core="published" operation="backup"/>
<solr-backup core="unpublished" operation="backup"/>
</target>
<target name="restore-apache-solr" depends="purge-solr-backend">
<echo message="Restoring Solr server from backup."/>
<solr-backup core="published" operation="restore"/>
<solr-backup core="unpublished" operation="restore"/>
</target>
<target name="download-apache-solr-snapshot">
<delete dir="${exports.solr.destination.folder}" includeemptydirs="true" failonerror="false" />
<mkdir dir="${exports.solr.destination.folder}"/>
<!-- Temporarily increase the memory limit so the download doesn't run out of memory. -->
<php expression="ini_get('memory_limit');" returnproperty="memory_limit.original" />
<php expression="ini_set('memory_limit', '1G');" />
<httpget
url="${exports.solr.source}"
authUser="${asda.username}"
authPassword="${asda.password}"
authScheme="basic"
dir="${exports.solr.destination.folder}"
/>
<!-- Restore the original memory limit. -->
<php expression="ini_set('memory_limit', '${memory_limit.original}');" />
<untar file="${exports.solr.destination.folder}/${exports.solr.filename}" todir="${exports.solr.destination.folder}" />
<delete file="${exports.solr.destination.folder}/${exports.solr.filename}" />
<move file="${exports.solr.destination.folder}/snapshot.joinup" tofile="${exports.solr.destination.folder}/snapshot.published" />
<move file="${exports.solr.destination.folder}/snapshot.joinup-unpublished" tofile="${exports.solr.destination.folder}/snapshot.unpublished" />
</target>
</project>