consul.spec 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. ##
  2. ## consul.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_consul_opkg 1.9.1
  25. %define V_consul_base 1.9.1
  26. %define V_consul_snap 20201219
  27. # package information
  28. Name: consul
  29. Summary: Service Discovery, Monitoring, Configuration and Connectivity
  30. URL: http://www.consul.io/
  31. Vendor: Armon Dadgar, Mitchell Hashimoto
  32. Packager: OpenPKG Project
  33. Distribution: OpenPKG Community
  34. Class: EVAL
  35. Group: Networking
  36. License: MPL
  37. Version: %{V_consul_opkg}.%{V_consul_snap}
  38. Release: 20201219
  39. # list of sources
  40. Source0: http://download.openpkg.org/components/versioned/consul/consul-%{V_consul_snap}.tar.xz
  41. Source1: rc.consul
  42. Source2: consul.hcl
  43. Source3: consul-openpkg-service.sh
  44. Source4: consul-openpkg-service.c
  45. Source5: consul-acl-update.sh
  46. Source6: consul-acl.txt
  47. # build information
  48. BuildPreReq: OpenPKG, openpkg >= 20160101, uuid, go
  49. PreReq: OpenPKG, openpkg >= 20160101, uuid, jq, curl, sed
  50. %description
  51. Consul is a tool for service discovery, monitoring, configuration
  52. and connectivity in a cluster of machines. Consul is distributed,
  53. highly available, and extremely scalable. Consul provides several
  54. key features: Service Discovery (via REST or DNS interfaces), Health
  55. Checking, Key/Value Storage and Multi-Datacenter Support. It is
  56. internally based on the excellent RAFT consensus protocol and the
  57. SWIM gossip/membership protocol.
  58. %track
  59. prog consul:release = {
  60. version = %{V_consul_base}
  61. url = https://github.com/hashicorp/consul/releases
  62. regex = v(\d+\.\d+\.\d+)\.tar\.gz
  63. }
  64. prog consul:snapshot = {
  65. version = %{V_consul_snap}
  66. url = http://download.openpkg.org/components/versioned/consul/
  67. regex = consul-(__VER__)\.tar\.xz
  68. }
  69. %prep
  70. %setup -q -n consul
  71. %build
  72. # build program
  73. export GOPATH=`pwd`
  74. ( cd src/github.com/hashicorp/consul
  75. go build \
  76. -v \
  77. -tags="consul" \
  78. -ldflags "-X github.com/hashicorp/consul/version.GitCommit='%{V_consul_snap}'" \
  79. -o bin/consul
  80. ) || exit $?
  81. # build helper program
  82. %{l_shtool} install -c %{l_value -s -a} \
  83. %{SOURCE consul-openpkg-service.c} .
  84. %{l_cc} %{l_cflags -O} %{l_ldflags} \
  85. -o consul-openpkg-service \
  86. consul-openpkg-service.c
  87. %install
  88. # create directory hierarchy
  89. %{l_shtool} mkdir -f -p -m 755 \
  90. $RPM_BUILD_ROOT%{l_prefix}/sbin \
  91. $RPM_BUILD_ROOT%{l_prefix}/libexec/consul \
  92. $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
  93. $RPM_BUILD_ROOT%{l_prefix}/etc/consul/acl.d \
  94. $RPM_BUILD_ROOT%{l_prefix}/var/consul/log \
  95. $RPM_BUILD_ROOT%{l_prefix}/var/consul/run \
  96. $RPM_BUILD_ROOT%{l_prefix}/var/consul/data
  97. # install program
  98. %{l_shtool} install -c -s -m 755 \
  99. src/github.com/hashicorp/consul/bin/consul \
  100. $RPM_BUILD_ROOT%{l_prefix}/sbin/consul
  101. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  102. %{SOURCE consul-acl-update.sh} \
  103. $RPM_BUILD_ROOT%{l_prefix}/sbin/consul-acl-update
  104. # install configuration files
  105. key=`src/github.com/hashicorp/consul/bin/consul keygen`
  106. token=`uuid -v4`
  107. %{l_shtool} install -c -m 644 %{l_value -s -a} \
  108. -e "s;@key@;$key;g" \
  109. -e "s;@token@;$token;g" \
  110. %{SOURCE consul.hcl} \
  111. $RPM_BUILD_ROOT%{l_prefix}/etc/consul/
  112. # install client ACL management
  113. for name in `grep "^<file" %{SOURCE consul-acl.txt} | sed -e 's;^.*name=";;' -e 's;".*$;;'`; do
  114. name_escaped=`echo "$name" | sed -e 's;/;\\\\/;g'`
  115. (echo ""; cat %{SOURCE consul-acl.txt}; echo "") |\
  116. sed -e "1,/^<file name=\"$name_escaped\">/d" -e "/<\/file>/,\$d" >tmp.txt
  117. %{l_shtool} install -c -m 644 %{l_value -s -a} \
  118. tmp.txt $RPM_BUILD_ROOT%{l_prefix}/etc/consul/acl.d/$name
  119. done
  120. # install utility script
  121. %{l_shtool} install -c -m 755 \
  122. consul-openpkg-service \
  123. $RPM_BUILD_ROOT%{l_prefix}/sbin/
  124. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  125. %{SOURCE consul-openpkg-service.sh} \
  126. $RPM_BUILD_ROOT%{l_prefix}/libexec/consul/
  127. # install run-command script
  128. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  129. %{SOURCE rc.consul} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
  130. # determine installation files
  131. %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
  132. %{l_files_std} \
  133. '%config %{l_prefix}/etc/consul/*' \
  134. '%config %{l_prefix}/etc/consul/*/*' \
  135. '%attr(4755,%{l_susr},%{l_mgrp}) %{l_prefix}/sbin/consul-openpkg-service' \
  136. '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/consul/*'
  137. %files -f files
  138. %clean
  139. %post
  140. # after upgrade, restart service
  141. [ $1 -eq 2 ] || exit 0
  142. eval `%{l_rc} consul status 2>/dev/null`
  143. [ ".$consul_active" = .yes ] && %{l_rc} consul restart
  144. exit 0
  145. %preun
  146. # before erase, stop service and remove log files
  147. [ $1 -eq 0 ] || exit 0
  148. %{l_rc} consul stop 2>/dev/null
  149. rm -rf $RPM_INSTALL_PREFIX/var/consul/log/* >/dev/null 2>&1 || true
  150. rm -rf $RPM_INSTALL_PREFIX/var/consul/run/* >/dev/null 2>&1 || true
  151. rm -rf $RPM_INSTALL_PREFIX/var/consul/data/* >/dev/null 2>&1 || true
  152. exit 0