fix: emqx can't start with systemctl

This commit is contained in:
Zhongwen Deng 2022-05-15 11:23:42 +08:00
parent 382d9079e1
commit ec625363cf
3 changed files with 13 additions and 5 deletions

View File

@ -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

View File

@ -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}/*

View File

@ -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