3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Read configuration variable file if it is present
19 [ -r /etc/default/koha-common ] && . /etc/default/koha-common
21 # include helper functions
22 if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
23 . "/usr/share/koha/bin/koha-functions.sh"
25 echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
33 Manage Elasticsearch-related tasks for Koha instances
35 Usage: $scriptname [actions] [options] instancename1 instancename2...
38 --rebuild Trigger a rebuild process
41 --delete|-d Delete elasticsearch index before reindexing.
42 --reset|-r Reset elasticsearch mappings from file.
43 --authorities|-a Only run process for authorities.
44 --biblios|-b Only run process for biblios.
45 -c|--commit n Specify how many records will be batched up before
46 they're added to Elasticsearch (default: 5000).
47 -p|--processes n Specify the number of parallel processes to use
49 --verbose|-v Be verbose.
50 --help|-h Print this help.
59 if [ "${authorities_only}" != "yes" ]; then
64 toggle_authorities_only()
66 authorities_only="yes"
68 if [ "${biblios_only}" != "yes" ]; then
75 if [ "${op}" = "" ]; then
78 die "Error: only one action can be specified."
82 run_rebuild_elasticsearch()
84 # read instance name and eliminate instance name from params
87 if [ "$DEV_INSTALL" = "" ]; then
88 KOHA_BINDIR=${KOHA_HOME}/bin
90 KOHA_BINDIR=${KOHA_HOME}/misc
93 if [ "${clo_commit_size}" > 0 ]; then
94 commit_size=${clo_commit_size}
96 rebuild_opts="--commit ${commit_size}"
98 if [ "${clo_processes}" > 0 ]; then
99 processes=${clo_processes}
101 rebuild_opts="${rebuild_opts} --processes ${processes}"
103 if [ "${delete}" = "yes" ]; then
104 rebuild_opts="${rebuild_opts} -d"
107 if [ "${reset}" = "yes" ]; then
108 rebuild_opts="${rebuild_opts} -r"
111 if [ "${biblios}" = "yes" ]; then
112 rebuild_opts="${rebuild_opts} -b"
115 if [ "${authorities}" = "yes" ]; then
116 rebuild_opts="${rebuild_opts} -a"
119 if [ "${verbose}" = "yes" ]; then
120 rebuild_opts="${rebuild_opts} -v"
124 -c "${KOHA_BINDIR}/search_tools/rebuild_elasticsearch.pl ${rebuild_opts}" \
136 authorities_only="no"
143 while [ -n "$*" ]; do
158 toggle_authorities_only
161 clo_commit_size="$2" ; shift
164 clo_processes="$2" ; shift
180 # Optionally use alternative paths for a dev install
181 adjust_paths_dev_install $1
183 # Parse command line.
184 if [ $# -lt 1 ]; then
186 die "Missing instance name."
189 # Loop over instance names
192 if is_instance $name; then
193 if [ "${op}" = "rebuild" ]; then
194 if ! run_rebuild_elasticsearch $name; then
195 warn "Something went wrong rebuilding indexes for ${name}"
198 # TODO: Add other actions, status? etc
200 die "Error: no action passed"
203 warn "Unknown instance ${name}"