elasticsearch.spec 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. ##
  2. ## elasticsearch.spec -- OpenPKG RPM Package Specification
  3. ## Copyright (c) 2000-2020 OpenPKG Project <http://openpkg.org/>
  4. ##
  5. ## Permission to use, copy, modify, and distribute this software for
  6. ## any purpose with or without fee is hereby granted, provided that
  7. ## the above copyright notice and this permission notice appear in all
  8. ## copies.
  9. ##
  10. ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  11. ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  12. ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  13. ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
  14. ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  15. ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  16. ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  17. ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  18. ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  19. ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  20. ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  21. ## SUCH DAMAGE.
  22. ##
  23. # package version
  24. %define V_opkg 7.9.3
  25. %define V_dist 7.9.3
  26. # package information
  27. Name: elasticsearch
  28. Summary: Enterprise Indexing and Search Server
  29. URL: http://www.elasticsearch.org/
  30. Vendor: Shay Banon
  31. Packager: OpenPKG Project
  32. Distribution: OpenPKG Community
  33. Class: PLUS
  34. Group: Database
  35. License: Apache
  36. Version: %{V_opkg}
  37. Release: 20201024
  38. # list of sources
  39. Source0: https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-%{V_dist}-no-jdk-linux-x86_64.tar.gz
  40. Source1: rc.elasticsearch
  41. Source2: elasticsearch.yml
  42. Patch0: elasticsearch.patch
  43. # build information
  44. BuildPreReq: OpenPKG, openpkg >= 20160101, infozip
  45. PreReq: OpenPKG, openpkg >= 20160101, java, JAVA-JDK, apg, curl, jna
  46. %description
  47. ElasticSearch is a powerful distributed RESTful Indexing and Search
  48. Server, built in top of the Apache Lucense search engine.
  49. %track
  50. prog elasticsearch = {
  51. version = %{V_dist}
  52. url = https://www.elastic.co/downloads/elasticsearch-no-jdk
  53. regex = elasticsearch-(\d+\.\d+\.\d+)-no-jdk-linux-x86_64\.tar\.gz
  54. }
  55. %prep
  56. %setup -q -n elasticsearch-%{V_dist}
  57. %patch -p0
  58. %build
  59. # patch files
  60. %{l_shtool} subst \
  61. -e 's;/bin/bash;%{l_bash};g' \
  62. bin/elasticsearch \
  63. bin/elasticsearch-certgen \
  64. bin/elasticsearch-certutil \
  65. bin/elasticsearch-cli \
  66. bin/elasticsearch-croneval \
  67. bin/elasticsearch-env \
  68. bin/elasticsearch-keystore \
  69. bin/elasticsearch-migrate \
  70. bin/elasticsearch-plugin \
  71. bin/elasticsearch-saml-metadata \
  72. bin/elasticsearch-setup-passwords \
  73. bin/elasticsearch-sql-cli \
  74. bin/elasticsearch-syskeygen \
  75. bin/elasticsearch-translog \
  76. bin/elasticsearch-users \
  77. bin/x-pack-env \
  78. bin/x-pack-security-env \
  79. bin/x-pack-watcher-env \
  80. bin/x-pack/certgen \
  81. bin/x-pack/certutil \
  82. bin/x-pack/croneval \
  83. bin/x-pack/migrate \
  84. bin/x-pack/saml-metadata \
  85. bin/x-pack/setup-passwords \
  86. bin/x-pack/sql-cli \
  87. bin/x-pack/syskeygen \
  88. bin/x-pack/users
  89. # strip down distribution
  90. rm -f [A-Z]*
  91. find . -name "*.orig" -print | xargs rm -f
  92. %install
  93. # create installation hierarchy
  94. %{l_shtool} mkdir -f -p -m 755 \
  95. $RPM_BUILD_ROOT%{l_prefix}/bin \
  96. $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
  97. $RPM_BUILD_ROOT%{l_prefix}/etc/elasticsearch \
  98. $RPM_BUILD_ROOT%{l_prefix}/lib/elasticsearch \
  99. $RPM_BUILD_ROOT%{l_prefix}/libexec/elasticsearch/plugins \
  100. $RPM_BUILD_ROOT%{l_prefix}/libexec/elasticsearch/scripts \
  101. $RPM_BUILD_ROOT%{l_prefix}/var/elasticsearch/run \
  102. $RPM_BUILD_ROOT%{l_prefix}/var/elasticsearch/log \
  103. $RPM_BUILD_ROOT%{l_prefix}/var/elasticsearch/tmp \
  104. $RPM_BUILD_ROOT%{l_prefix}/var/elasticsearch/db
  105. # install program components
  106. rm -f bin/*.bat bin/*.exe
  107. cp -r * \
  108. $RPM_BUILD_ROOT%{l_prefix}/lib/elasticsearch/
  109. # replace JNA library
  110. rm -f $RPM_BUILD_ROOT%{l_prefix}/lib/elasticsearch/lib/jna-*.jar
  111. ln -s ../../jna.jar \
  112. $RPM_BUILD_ROOT%{l_prefix}/lib/elasticsearch/lib/jna.jar
  113. # install link to configuration files
  114. rm -rf $RPM_BUILD_ROOT%{l_prefix}/lib/elasticsearch/config >/dev/null 2>&1 || true
  115. ln -s ../../etc/elasticsearch \
  116. $RPM_BUILD_ROOT%{l_prefix}/lib/elasticsearch/config
  117. # install link to plugins directory
  118. rmdir $RPM_BUILD_ROOT%{l_prefix}/lib/elasticsearch/plugins >/dev/null 2>&1 || true
  119. ln -s ../../libexec/elasticsearch/plugins \
  120. $RPM_BUILD_ROOT%{l_prefix}/lib/elasticsearch/plugins
  121. # install link to scripts directory
  122. rmdir $RPM_BUILD_ROOT%{l_prefix}/lib/elasticsearch/scripts >/dev/null 2>&1 || true
  123. ln -s ../../libexec/elasticsearch/scripts \
  124. $RPM_BUILD_ROOT%{l_prefix}/lib/elasticsearch/scripts
  125. # install link to log directory
  126. rmdir $RPM_BUILD_ROOT%{l_prefix}/lib/elasticsearch/logs >/dev/null 2>&1 || true
  127. ln -s ../../var/elasticsearch/log \
  128. $RPM_BUILD_ROOT%{l_prefix}/lib/elasticsearch/logs
  129. # install wrapper commands
  130. for prog in elasticsearch elasticsearch-plugin elasticsearch-keystore elasticsearch-translog; do
  131. ( echo "#!/bin/sh"
  132. echo "eval \`JAVA_PLATFORM=\"sun-jdk\" %{l_prefix}/bin/java-toolkit -e\`"
  133. echo "export ES_HOME=\"%{l_prefix}/lib/elasticsearch\""
  134. echo "export ES_PATH_CONF=\"%{l_prefix}/etc/elasticsearch\""
  135. echo "export ES_TMPDIR=\"%{l_prefix}/var/elasticsearch/tmp\""
  136. echo "exec %{l_prefix}/lib/elasticsearch/bin/$prog \${1+\"\$@\"}"
  137. ) >$prog
  138. %{l_shtool} install -c -m 755 \
  139. $prog $RPM_BUILD_ROOT%{l_prefix}/bin/$prog
  140. done
  141. # install default configuration
  142. %{l_shtool} install -c -m 644 %{l_value -s -a} \
  143. %{SOURCE elasticsearch.yml} $RPM_BUILD_ROOT%{l_prefix}/etc/elasticsearch/
  144. %{l_shtool} install -c -m 644 \
  145. config/jvm.options config/log4j2.properties \
  146. $RPM_BUILD_ROOT%{l_prefix}/etc/elasticsearch/
  147. # install run-command script
  148. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  149. %{SOURCE rc.elasticsearch} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
  150. # determine installation files
  151. %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
  152. %{l_files_std} \
  153. '%config %{l_prefix}/etc/elasticsearch/*' \
  154. '%dir %attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/etc/elasticsearch' \
  155. '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/elasticsearch' \
  156. '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/elasticsearch/*'
  157. %files -f files
  158. %clean
  159. %post
  160. if [ $1 -eq 1 ]; then
  161. # Create initial ElasticSearch keystore
  162. echo "Create initial ElasticSearch keystore" | \
  163. %{l_rpmtool} msg -b -t notice
  164. su - %{l_rusr} -c \
  165. "LC_CTYPE=C; export LC_CTYPE; umask 077; \
  166. $RPM_INSTALL_PREFIX/bin/elasticsearch-keystore create"
  167. # display final hints on initial installation
  168. ( echo "By default, ElasticSearch runs its server process on IPv4 address"
  169. echo "127.0.0.1, TCP port 9200. Start the ElasticSearch server by running:"
  170. echo " \$ $RPM_INSTALL_PREFIX/bin/openpkg rc elasticsearch start"
  171. echo "Connect to ElasticSearch via REST through the URL:"
  172. echo " http://localhost:9200/"
  173. ) | %{l_rpmtool} msg -b -t notice
  174. fi
  175. if [ $1 -eq 2 ]; then
  176. # after upgrade, restart service
  177. eval `%{l_rc} elasticsearch status 2>/dev/null`
  178. [ ".$elasticsearch_active" = .yes ] && %{l_rc} elasticsearch restart
  179. fi
  180. exit 0
  181. %preun
  182. if [ $1 -eq 0 ]; then
  183. # before erase, stop service and remove runtime files
  184. %{l_rc} elasticsearch stop 2>/dev/null
  185. rm -f $RPM_INSTALL_PREFIX/etc/elasticsearch/*.keystore >/dev/null 2>&1 || true
  186. rm -rf $RPM_INSTALL_PREFIX/var/elasticsearch/run/* >/dev/null 2>&1 || true
  187. rm -rf $RPM_INSTALL_PREFIX/var/elasticsearch/log/* >/dev/null 2>&1 || true
  188. rm -rf $RPM_INSTALL_PREFIX/var/elasticsearch/tmp/* >/dev/null 2>&1 || true
  189. rm -rf $RPM_INSTALL_PREFIX/var/elasticsearch/db/* >/dev/null 2>&1 || true
  190. fi
  191. exit 0