consul.spec 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. ##
  2. ## consul.spec -- OpenPKG RPM Package Specification
  3. ## Copyright (c) 2000-2017 OpenPKG Foundation e.V. <http://openpkg.net/>
  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 0.8.3
  25. %define V_consul_base 0.8.3
  26. %define V_consul_snap 20170519
  27. # package information
  28. Name: consul
  29. Summary: Service Discovery, Monitoring and Configuration
  30. URL: http://www.consul.io/
  31. Vendor: Armon Dadgar, Mitchell Hashimoto
  32. Packager: OpenPKG Foundation e.V.
  33. Distribution: OpenPKG Community
  34. Class: EVAL
  35. Group: Networking
  36. License: MPL
  37. Version: %{V_consul_opkg}.%{V_consul_snap}
  38. Release: 20170519
  39. # list of sources
  40. Source0: http://download.openpkg.org/components/versioned/consul/consul-%{V_consul_snap}.tar.xz
  41. Source1: rc.consul
  42. Source3: consul.json
  43. # build information
  44. BuildPreReq: OpenPKG, openpkg >= 20160101, go
  45. PreReq: OpenPKG, openpkg >= 20160101
  46. %description
  47. Consul is a tool for service discovery and configuration. Consul
  48. is distributed, highly available, and extremely scalable. Consul
  49. provides several key features: Service Discovery, Health Checking,
  50. Key/Value Storage and Multi-Datacenter Support. It is internally
  51. based on the excellent RAFT consensus protocol and the SWIM
  52. gossip/membership protocol.
  53. %track
  54. prog consul:release = {
  55. version = %{V_consul_base}
  56. url = https://github.com/hashicorp/consul/releases
  57. regex = v(\d+\.\d+\.\d+)\.tar\.gz
  58. }
  59. prog consul:snapshot = {
  60. version = %{V_consul_snap}
  61. url = http://download.openpkg.org/components/versioned/consul/
  62. regex = consul-(__VER__)\.tar\.xz
  63. }
  64. %prep
  65. %setup -q -n consul
  66. %build
  67. # build program
  68. export GOPATH=`pwd`
  69. cd src/github.com/hashicorp/consul
  70. go build \
  71. -x \
  72. -tags="consul" \
  73. -ldflags "-X github.com/hashicorp/consul/version.GitCommit='0000' \
  74. -X github.com/hashicorp/consul/version.GitDescribe='consul'" \
  75. -o bin/consul
  76. %install
  77. # create directory hierarchy
  78. %{l_shtool} mkdir -f -p -m 755 \
  79. $RPM_BUILD_ROOT%{l_prefix}/sbin \
  80. $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
  81. $RPM_BUILD_ROOT%{l_prefix}/etc/consul \
  82. $RPM_BUILD_ROOT%{l_prefix}/var/consul/log \
  83. $RPM_BUILD_ROOT%{l_prefix}/var/consul/run \
  84. $RPM_BUILD_ROOT%{l_prefix}/var/consul/data
  85. # install program
  86. %{l_shtool} install -c -s -m 755 \
  87. src/github.com/hashicorp/consul/bin/consul \
  88. $RPM_BUILD_ROOT%{l_prefix}/sbin/consul
  89. # install configuration files
  90. %{l_shtool} install -c -m 644 %{l_value -s -a} \
  91. %{SOURCE consul.json} \
  92. $RPM_BUILD_ROOT%{l_prefix}/etc/consul/
  93. # install run-command script
  94. %{l_shtool} install -c -m 755 %{l_value -s -a} \
  95. %{SOURCE rc.consul} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
  96. # determine installation files
  97. %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
  98. %{l_files_std} \
  99. '%config %{l_prefix}/etc/consul/*' \
  100. '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/consul/*'
  101. %files -f files
  102. %clean
  103. %post
  104. # after upgrade, restart service
  105. [ $1 -eq 2 ] || exit 0
  106. eval `%{l_rc} consul status 2>/dev/null`
  107. [ ".$consul_active" = .yes ] && %{l_rc} consul restart
  108. exit 0
  109. %preun
  110. # before erase, stop service and remove log files
  111. [ $1 -eq 0 ] || exit 0
  112. %{l_rc} consul stop 2>/dev/null
  113. rm -rf $RPM_INSTALL_PREFIX/var/consul/log/* >/dev/null 2>&1 || true
  114. rm -rf $RPM_INSTALL_PREFIX/var/consul/run/* >/dev/null 2>&1 || true
  115. rm -rf $RPM_INSTALL_PREFIX/var/consul/data/* >/dev/null 2>&1 || true
  116. exit 0