From ec625363cf592c6e10d57abf80d87772aee85128 Mon Sep 17 00:00:00 2001 From: Zhongwen Deng Date: Sun, 15 May 2022 11:23:42 +0800 Subject: [PATCH] fix: emqx can't start with systemctl --- deploy/packages/rpm/Makefile | 9 ++++++--- deploy/packages/rpm/emqx.spec | 2 ++ scripts/pkg-tests.sh | 7 +++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/deploy/packages/rpm/Makefile b/deploy/packages/rpm/Makefile index 15de40627..67ae7c907 100644 --- a/deploy/packages/rpm/Makefile +++ b/deploy/packages/rpm/Makefile @@ -16,12 +16,13 @@ TAR_PKG := $(EMQX_REL)/$(TAR_PKG_DIR)/emqx-$(PKG_VSN).tar.gz SOURCE_PKG := emqx-$(RPM_VSN)-$(RPM_REL).$(shell uname -m) TARGET_PKG := $(EMQX_NAME)-$(shell $(EMQX_REL)/pkg-vsn.sh $(EMQX_NAME) --long) -SYSTEMD := $(shell if command -v systemctl >/dev/null 2>&1; then echo yes; fi) # Not $(PWD) as it does not work for make -C CURDIR := $(shell pwd) -POST_ADDITION := $(if $(SYSTEMD),%systemd_post %{_name}.service,echo post) -PREUN_ADDITION := $(if $(SYSTEMD),%systemd_preun %{_name}.service,echo preun) +POST_ADDITION := %systemd_post %{_name}.service +PREUN_ADDITION := %systemd_preun %{_name}.service +SERVICE_SRC := $(CURDIR)/emqx.service +SERVICE_DST := %{_unitdir}/emqx.service .PHONY: all all: | $(BUILT) @@ -36,6 +37,8 @@ all: | $(BUILT) --define "_post_addition $(POST_ADDITION)" \ --define "_preun_addition $(PREUN_ADDITION)" \ --define "_sharedstatedir /var/lib" \ + --define "_service_src $(SERVICE_SRC)" \ + --define "_service_dst $(SERVICE_DST)" \ emqx.spec mkdir -p $(EMQX_REL)/_packages/$(EMQX_NAME) cp $(TOPDIR)/RPMS/$(shell uname -m)/$(SOURCE_PKG).rpm $(EMQX_REL)/_packages/$(EMQX_NAME)/$(TARGET_PKG).rpm diff --git a/deploy/packages/rpm/emqx.spec b/deploy/packages/rpm/emqx.spec index 26a223b88..1c14f24c0 100644 --- a/deploy/packages/rpm/emqx.spec +++ b/deploy/packages/rpm/emqx.spec @@ -47,6 +47,7 @@ cp -R %{_reldir}/releases %{buildroot}%{_lib_home}/ cp -R %{_reldir}/bin %{buildroot}%{_lib_home}/ cp -R %{_reldir}/etc/* %{buildroot}%{_conf_dir}/ cp -R %{_reldir}/data/* %{buildroot}%{_var_home}/ +install -m644 %{_service_src} %{buildroot}%{_service_dst} %pre if [ $1 = 1 ]; then @@ -84,6 +85,7 @@ exit 0 %files %defattr(-,root,root) +%{_service_dst} %attr(-,%{_user},%{_group}) %{_lib_home}/* %attr(-,%{_user},%{_group}) %dir %{_var_home} %attr(-,%{_user},%{_group}) %config(noreplace) %{_var_home}/* diff --git a/scripts/pkg-tests.sh b/scripts/pkg-tests.sh index 6254584a5..81800427c 100755 --- a/scripts/pkg-tests.sh +++ b/scripts/pkg-tests.sh @@ -150,7 +150,11 @@ emqx_test(){ fi ;; "rpm") - yum install -y "${PACKAGE_PATH}/${packagename}" + YUM_RES=$(yum install -y "${PACKAGE_PATH}/${packagename}"| tee /dev/null) + if [[ $YUM_RES =~ "Failed" ]]; then + echo "yum install failed" + exit 1 + fi if ! rpm -q "${EMQX_NAME}" | grep -q "${EMQX_NAME}"; then echo "package install error" exit 1 @@ -189,7 +193,6 @@ EOF echo "Error: cannot locate emqx_vars" exit 1 fi - if ! emqx 'start'; then cat /var/log/emqx/erlang.log.1 || true cat /var/log/emqx/emqx.log.1 || true