emqx.spec 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. %define debug_package %{nil}
  2. %define _user %{_name}
  3. %define _group %{_name}
  4. %define _conf_dir %{_sysconfdir}/%{_name}
  5. %define _log_dir %{_var}/log/%{_name}
  6. %define _lib_home /usr/lib/%{_name}
  7. %define _var_home %{_sharedstatedir}/%{_name}
  8. %define _build_name_fmt %{_arch}/%{_name}-%{_version}.%{_arch}.rpm
  9. %define _build_id_links none
  10. Name: %{_package_name}
  11. Version: %{_version}
  12. Release: 1%{?dist}
  13. Summary: emqx
  14. Group: System Environment/Daemons
  15. License: Apache License Version 2.0
  16. URL: https://www.emqx.com
  17. BuildRoot: %{_tmppath}/%{_name}-%{_version}-root
  18. Provides: %{_name}
  19. AutoReq: 0
  20. # package name openssl11 is from epel-release, and only applicable for rhel 7
  21. %if "%{_arch} %{?rhel}" == "x86_64 7"
  22. Requires: openssl11 libatomic procps which findutils
  23. %else
  24. %if "%{?dist}" == ".amzn2023"
  25. Requires: libatomic procps which findutils ncurses util-linux shadow-utils
  26. %else
  27. Requires: libatomic procps which findutils
  28. %endif
  29. %endif
  30. %description
  31. EMQX, a distributed, massively scalable, highly extensible MQTT message broker.
  32. %prep
  33. %build
  34. %install
  35. mkdir -p %{buildroot}%{_lib_home}
  36. mkdir -p %{buildroot}%{_lib_home}/plugins
  37. mkdir -p %{buildroot}%{_log_dir}
  38. mkdir -p %{buildroot}%{_unitdir}
  39. mkdir -p %{buildroot}%{_conf_dir}
  40. mkdir -p %{buildroot}%{_bindir}
  41. mkdir -p %{buildroot}%{_var_home}
  42. cp -R %{_reldir}/lib %{buildroot}%{_lib_home}/
  43. touch %{buildroot}%{_lib_home}/plugins/.keep
  44. cp -R %{_reldir}/erts-* %{buildroot}%{_lib_home}/
  45. cp -R %{_reldir}/releases %{buildroot}%{_lib_home}/
  46. cp -R %{_reldir}/bin %{buildroot}%{_lib_home}/
  47. cp -R %{_reldir}/etc/* %{buildroot}%{_conf_dir}/
  48. cp -R %{_reldir}/data/* %{buildroot}%{_var_home}/
  49. install -m644 %{_service_src} %{buildroot}%{_service_dst}
  50. %pre
  51. if [ $1 = 1 ]; then
  52. # Initial installation
  53. /usr/bin/getent group %{_group} >/dev/null || /usr/sbin/groupadd -r %{_group}
  54. if ! /usr/bin/getent passwd %{_user} >/dev/null ; then
  55. /usr/sbin/useradd -r -g %{_group} -m -d %{_sharedstatedir}/%{_name} -c "%{_name}" %{_user}
  56. fi
  57. fi
  58. %post
  59. if [ $1 = 1 ]; then
  60. ln -s %{_lib_home}/bin/emqx %{_bindir}/emqx
  61. ln -s %{_lib_home}/bin/emqx_ctl %{_bindir}/emqx_ctl
  62. fi
  63. %{_post_addition}
  64. systemctl enable %{_name}.service
  65. chown -R %{_user}:%{_group} %{_lib_home}
  66. %preun
  67. %{_preun_addition}
  68. # Only on uninstall, not upgrades
  69. if [ $1 = 0 ]; then
  70. systemctl disable %{_name}.service
  71. rm -f %{_bindir}/emqx
  72. rm -f %{_bindir}/emqx_ctl
  73. fi
  74. exit 0
  75. %postun
  76. if [ $1 = 0 ]; then
  77. rm -rf %{_lib_home}
  78. fi
  79. exit 0
  80. %files
  81. %defattr(-,root,root)
  82. %{_service_dst}
  83. %attr(-,%{_user},%{_group}) %{_lib_home}/*
  84. %attr(750,%{_user},%{_group}) %dir %{_var_home}
  85. %attr(-,%{_user},%{_group}) %config(noreplace) %{_var_home}/*
  86. %attr(-,%{_user},%{_group}) %dir %{_log_dir}
  87. %attr(-,%{_user},%{_group}) %config(noreplace) %{_conf_dir}/*
  88. %clean
  89. rm -rf %{buildroot}
  90. %changelog