From 5d10071319cccd2346eb2bedd9387b741d47a6e3 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Tue, 19 Apr 2022 21:24:58 +0200 Subject: [PATCH 1/5] chore(rpm/deb): delete init.d stuff --- deploy/packages/deb/debian/rules | 7 -- deploy/packages/rpm/Makefile | 5 -- deploy/packages/rpm/emqx.spec | 17 +--- deploy/packages/rpm/init.script | 149 ------------------------------- 4 files changed, 2 insertions(+), 176 deletions(-) delete mode 100755 deploy/packages/rpm/init.script diff --git a/deploy/packages/deb/debian/rules b/deploy/packages/deb/debian/rules index 9ca6c8e17..7d28be282 100755 --- a/deploy/packages/deb/debian/rules +++ b/deploy/packages/deb/debian/rules @@ -33,23 +33,16 @@ install: build mkdir -p debian/emqx/var/lib/emqx mkdir -p debian/emqx/var/run/emqx mkdir -p debian/emqx/var/log/emqx - mkdir -p debian/emqx/usr/lib/emqx/bin - mkdir -p debian/emqx/etc/emqx - mkdir -p debian/emqx/etc/init.d - cp bin/* debian/emqx/usr/lib/emqx/bin - cp -R lib debian/emqx/usr/lib/emqx cp -R erts* debian/emqx/usr/lib/emqx cp -R releases debian/emqx/usr/lib/emqx cp -R etc/* debian/emqx/etc/emqx cp -R data/* debian/emqx/var/lib/emqx - install -d debian/emqx/lib/systemd/system install -p -m0644 debian/emqx.service debian/emqx/lib/systemd/system/emqx.service - dh_shlibdeps # We have nothing to do by default. diff --git a/deploy/packages/rpm/Makefile b/deploy/packages/rpm/Makefile index 72170dc4a..15de40627 100644 --- a/deploy/packages/rpm/Makefile +++ b/deploy/packages/rpm/Makefile @@ -20,9 +20,6 @@ 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) -SERVICE_SRC := $(if $(SYSTEMD),$(CURDIR)/emqx.service,$(CURDIR)/init.script) -SERVICE_DST := $(if $(SYSTEMD),%{_unitdir}/emqx.service,%{_initddir}/emqx) - POST_ADDITION := $(if $(SYSTEMD),%systemd_post %{_name}.service,echo post) PREUN_ADDITION := $(if $(SYSTEMD),%systemd_preun %{_name}.service,echo preun) @@ -36,8 +33,6 @@ all: | $(BUILT) --define "_version $(RPM_VSN)" \ --define "_reldir $(SRCDIR)" \ --define "_release $(RPM_REL)" \ - --define "_service_src $(SERVICE_SRC)" \ - --define "_service_dst $(SERVICE_DST)" \ --define "_post_addition $(POST_ADDITION)" \ --define "_preun_addition $(PREUN_ADDITION)" \ --define "_sharedstatedir /var/lib" \ diff --git a/deploy/packages/rpm/emqx.spec b/deploy/packages/rpm/emqx.spec index 461c3024c..99d236736 100644 --- a/deploy/packages/rpm/emqx.spec +++ b/deploy/packages/rpm/emqx.spec @@ -39,7 +39,6 @@ mkdir -p %{buildroot}%{_unitdir} mkdir -p %{buildroot}%{_conf_dir} mkdir -p %{buildroot}%{_bindir} mkdir -p %{buildroot}%{_var_home} -mkdir -p %{buildroot}%{_initddir} cp -R %{_reldir}/lib %{buildroot}%{_lib_home}/ cp -R %{_reldir}/erts-* %{buildroot}%{_lib_home}/ @@ -47,7 +46,6 @@ 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 @@ -64,23 +62,14 @@ if [ $1 = 1 ]; then ln -s %{_lib_home}/bin/emqx_ctl %{_bindir}/emqx_ctl fi %{_post_addition} -if [ -e %{_initddir}/%{_name} ] ; then - /sbin/chkconfig --add %{_name} -else - systemctl enable %{_name}.service -fi +systemctl enable %{_name}.service chown -R %{_user}:%{_group} %{_lib_home} %preun %{_preun_addition} # Only on uninstall, not upgrades if [ $1 = 0 ]; then - if [ -e %{_initddir}/%{_name} ] ; then - /sbin/service %{_name} stop > /dev/null 2>&1 - /sbin/chkconfig --del %{_name} - else - systemctl disable %{_name}.service - fi + systemctl disable %{_name}.service rm -f %{_bindir}/emqx rm -f %{_bindir}/emqx_ctl fi @@ -94,7 +83,6 @@ 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}/* @@ -105,4 +93,3 @@ exit 0 rm -rf %{buildroot} %changelog - diff --git a/deploy/packages/rpm/init.script b/deploy/packages/rpm/init.script deleted file mode 100755 index a2656be82..000000000 --- a/deploy/packages/rpm/init.script +++ /dev/null @@ -1,149 +0,0 @@ -#!/usr/bin/env bash -# -# emqx -# -# chkconfig: 2345 80 30 -# description: EMQX, a distributed, massively scalable, highly extensible MQTT message broker written in Erlang/OTP -# processname: beam -# - -# Source function library. -# shellcheck disable=SC1091 -. /etc/rc.d/init.d/functions - -RETVAL=0 -PATH=/sbin:/usr/sbin:/bin:/usr/bin -NAME=emqx -DAEMON=/usr/bin/$NAME -lockfile=/var/lock/subsys/$NAME -mkdir -p /var/run/$NAME -pidfile=/var/run/$NAME/$NAME.pid - -# Check for script, config and data dirs -[ -x /usr/bin/$NAME ] || exit 0 -[ -d /etc/$NAME ] || exit 0 -[ -d /var/lib/$NAME ] || exit 0 - -# Read configuration variable file if it is present and readable -# shellcheck disable=SC1090 -[ -r /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME - -# `service` strips all environmental VARS so -# if no HOME was set in /etc/sysconfig/$NAME then set one here -# to the data directory for erlexec's sake -if [ -z "$HOME" ]; then - export HOME= -fi - -status -p $pidfile -l "$(basename $lockfile)" $NAME >/dev/null 2>&1 -running=$? - -find_pid() { - # shellcheck disable=SC2009 # pgrep does not support Extended Regular Expressions - ps ax | grep -E "\-progname\s+$NAME\s" | awk '{print $1}' -} - -check_pid_status() { - local pid - pid="$(find_pid)" - if [ "$pid" = "" ]; then - # prog not running? - return 1 - else - # running - return 0 - fi -} - -start() { - # Start daemons. - echo -n $"Starting emqx: " - $DAEMON start - RETVAL=$? - if [ $RETVAL -eq 0 ]; then - touch $lockfile - find_pid > $pidfile - success - else - failure $"$NAME start" - fi - echo - return $RETVAL -} - -stop() { - # Stop daemon. - echo -n $"Shutting down emqx: " - $DAEMON stop 2>/dev/null - for _ in $(seq 1 10); do - sleep 1 - check_pid_status - RETVAL=$? - if [ $RETVAL -eq 1 ]; then - break - fi - done - if [ $RETVAL -eq 1 ]; then - rm -f $lockfile $pidfile - success - echo && return 0 - else - failure $"$NAME stop" - echo && return 1 - fi -} - -hardstop() { - echo -n $"Shutting down $NAME: " - su - emqx -c "ps -ef | grep -E '\-progname\s+$NAME\s' | awk '{print \$2}' | xargs kill -9" - for _ in $(seq 1 10); do - sleep 1 - check_pid_status - RETVAL=$? - if [ $RETVAL -eq 1 ]; then - break - fi - done - if [ $RETVAL -eq 1 ]; then - rm -f $lockfile $pidfile - success - echo && return 0 - else - failure $"$NAME hardstop" - echo && return 1 - fi -} - -# See how we were called. -case "$1" in - start) - [ $running -eq 0 ] && exit 0 - start - ;; - stop) - stop - ;; - restart|force-reload) - [ $running -eq 0 ] && stop - start - ;; - hardstop) - [ $running -eq 0 ] || exit 0 - hardstop - ;; - condrestart|try-restart) - [ $running -eq 0 ] || exit 0 - restart - ;; - status) - status -p $pidfile -l "$(basename $lockfile)" $NAME - ;; - ping) - $DAEMON ping || exit $? - ;; - *) - echo $"Usage: $0 {start|stop|restart|force-reload|hardstop|condrestart|try-restart|status|ping}" - exit 1 -esac - -exit $? From e7033558f3e735fd9f83d2dd66ef457f34781867 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Tue, 19 Apr 2022 21:24:47 +0200 Subject: [PATCH 2/5] fix(emqx.spec): bad dependency list for el7 and el8 --- deploy/packages/rpm/emqx.spec | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/deploy/packages/rpm/emqx.spec b/deploy/packages/rpm/emqx.spec index 99d236736..26a223b88 100644 --- a/deploy/packages/rpm/emqx.spec +++ b/deploy/packages/rpm/emqx.spec @@ -19,10 +19,11 @@ BuildRoot: %{_tmppath}/%{_name}-%{_version}-root Provides: %{_name} AutoReq: 0 -%if "%{_arch} %{?rhel}" == "amd64 7" -Requires: openssl11 libatomic +# package name openssl11 is from epel-release, and only applicable for rhel 7 +%if "%{_arch} %{?rhel}" == "x86_64 7" +Requires: openssl11 libatomic procps which findutils %else -Requires: libatomic +Requires: libatomic procps which findutils %endif %description From a0145f46929d00df4c9e2c9e91d570dc2510298f Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Tue, 19 Apr 2022 20:41:04 +0200 Subject: [PATCH 3/5] chore(buildx.sh): no need to parameterise otp version and system --- scripts/buildx.sh | 68 +++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/scripts/buildx.sh b/scripts/buildx.sh index 127d316e8..358c72fee 100755 --- a/scripts/buildx.sh +++ b/scripts/buildx.sh @@ -25,9 +25,6 @@ help() { echo "--src_dir : EMQX source ode in this dir, default to PWD" echo "--builder : Builder image to pull" echo " E.g. ghcr.io/emqx/emqx-builder/5.0-10:1.13.3-24.2.1-1-debian10" - echo "--otp : OTP version being used in the builder" - echo "--elixir-vsn : Elixir version being used in the builder" - echo "--system : OS used in the builder image" } while [ "$#" -gt 0 ]; do @@ -56,14 +53,6 @@ while [ "$#" -gt 0 ]; do ARCH="$2" shift 2 ;; - --otp) - OTP_VSN="$2" - shift 2 - ;; - --elixir-vsn) - ELIXIR_VSN="$2" - shift 2 - ;; --elixir) shift 1 case ${1:-novalue} in @@ -84,10 +73,6 @@ while [ "$#" -gt 0 ]; do ;; esac ;; - --system) - SYSTEM="$2" - shift 2 - ;; *) echo "WARN: Unknown arg (ignored): $1" shift @@ -99,10 +84,7 @@ done if [ -z "${PROFILE:-}" ] || [ -z "${PKGTYPE:-}" ] || [ -z "${BUILDER:-}" ] || - [ -z "${ARCH:-}" ] || - [ -z "${OTP_VSN:-}" ] || - [ -z "${ELIXIR_VSN:-}" ] || - [ -z "${SYSTEM:-}" ]; then + [ -z "${ARCH:-}" ]; then help exit 1 fi @@ -135,25 +117,41 @@ else MAKE_TARGET="${PROFILE}-${PKGTYPE}" fi +HOST_SYSTEM="$(./scripts/get-distro.sh)" +BUILDER_SYSTEM="$(docker run --rm -v "$(pwd)":/emqx "$BUILDER" /emqx/scripts/get-distro.sh)" + CMD_RUN="make ${MAKE_TARGET} && ./scripts/pkg-tests.sh ${MAKE_TARGET}" -if [[ $(uname -m) = "x86_64" && "$ARCH" = "amd64" ]]; then - eval "$CMD_RUN" -elif [[ $(uname -m) = "aarch64" && "$ARCH" = "arm64" ]]; then - eval "$CMD_RUN" -elif [[ $(uname -m) = "arm64" && "$ARCH" = "arm64" ]]; then - eval "$CMD_RUN" -elif [[ $(uname -m) = "armv7l" && "$ARCH" = "arm64" ]]; then +IS_NATIVE_SYSTEM='no' +if [[ "$HOST_SYSTEM" = "$BUILDER_SYSTEM" ]]; then + IS_NATIVE_SYSTEM='yes' +fi + +IS_NATIVE_ARCH='no' +if [[ $(uname -m) == "x86_64" && "$ARCH" == "amd64" ]]; then + IS_NATIVE_ARCH='yes' +elif [[ $(uname -m) == "aarch64" && "$ARCH" == "arm64" ]]; then + IS_NATIVE_ARCH='yes' +elif [[ $(uname -m) == "arm64" && "$ARCH" == "arm64" ]]; then + IS_NATIVE_ARCH='yes' +elif [[ $(uname -m) == "armv7l" && "$ARCH" == "arm64" ]]; then + IS_NATIVE_ARCH='yes' +fi + + +if [[ "${IS_NATIVE_SYSTEM}" == 'yes' && "${IS_NATIVE_ARCH}" == 'yes' ]]; then eval "$CMD_RUN" elif docker info; then - docker run --rm --privileged tonistiigi/binfmt:latest --install "${ARCH}" - docker run -i --rm \ - -v "$(pwd)":/emqx \ - --workdir /emqx \ - --platform="linux/$ARCH" \ - "$BUILDER" \ - bash -euc "$CMD_RUN" + if [[ "${IS_NATIVE_ARCH}" == 'no' ]]; then + docker run --rm --privileged tonistiigi/binfmt:latest --install "${ARCH}" + fi + docker run -i --rm \ + -v "$(pwd)":/emqx \ + --workdir /emqx \ + --platform="linux/$ARCH" \ + "$BUILDER" \ + bash -euc "$CMD_RUN" else - echo "Error: Docker not available on unsupported platform" - exit 1; + echo "Error: Docker not available on unsupported platform" + exit 1; fi From 628f0bf57909f26208d45a02e33a7fbae8443249 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Tue, 19 Apr 2022 22:26:44 +0200 Subject: [PATCH 4/5] style: reformat some modules in emqx_management app --- .../emqx_management/src/emqx_mgmt_api_sys.erl | 46 ++++++++++--------- .../test/emqx_mgmt_api_sys_SUITE.erl | 35 ++++++++------ 2 files changed, 45 insertions(+), 36 deletions(-) diff --git a/apps/emqx_management/src/emqx_mgmt_api_sys.erl b/apps/emqx_management/src/emqx_mgmt_api_sys.erl index 220ce2563..0209e2d0e 100644 --- a/apps/emqx_management/src/emqx_mgmt_api_sys.erl +++ b/apps/emqx_management/src/emqx_mgmt_api_sys.erl @@ -22,14 +22,14 @@ -include_lib("typerefl/include/types.hrl"). %% API --export([ api_spec/0 - , paths/0 - , schema/1 - , namespace/0 - ]). +-export([ + api_spec/0, + paths/0, + schema/1, + namespace/0 +]). --export([ sys/2 - ]). +-export([sys/2]). -define(TAGS, [<<"sys">>]). @@ -61,8 +61,8 @@ schema("/mqtt/sys_topics") -> responses => #{ 200 => schema_sys_topics() - } - }, + } + }, put => #{ tags => ?TAGS, @@ -71,20 +71,24 @@ schema("/mqtt/sys_topics") -> responses => #{ 200 => schema_sys_topics() - } - } - }. + } + } + }. schema_sys_topics() -> emqx_dashboard_swagger:schema_with_example( - hoconsc:ref(emqx_schema, "sys_topics"), example_sys_topics()). + hoconsc:ref(emqx_schema, "sys_topics"), example_sys_topics() + ). example_sys_topics() -> - #{<<"sys_event_messages">> => - #{<<"client_connected">> => true, - <<"client_disconnected">> => true, - <<"client_subscribed">> => false, - <<"client_unsubscribed">> => false}, - <<"sys_heartbeat_interval">> => <<"30s">>, - <<"sys_msg_interval">> => <<"1m">> - }. + #{ + <<"sys_event_messages">> => + #{ + <<"client_connected">> => true, + <<"client_disconnected">> => true, + <<"client_subscribed">> => false, + <<"client_unsubscribed">> => false + }, + <<"sys_heartbeat_interval">> => <<"30s">>, + <<"sys_msg_interval">> => <<"1m">> + }. diff --git a/apps/emqx_management/test/emqx_mgmt_api_sys_SUITE.erl b/apps/emqx_management/test/emqx_mgmt_api_sys_SUITE.erl index 725eacb34..d577798ce 100644 --- a/apps/emqx_management/test/emqx_mgmt_api_sys_SUITE.erl +++ b/apps/emqx_management/test/emqx_mgmt_api_sys_SUITE.erl @@ -33,22 +33,27 @@ end_per_suite(_) -> t_get_put(_) -> {ok, Default} = get_sys_topics_config(), ?assertEqual( - #{<<"sys_event_messages">> => - #{<<"client_connected">> => true, - <<"client_disconnected">> => true, - <<"client_subscribed">> => false, - <<"client_unsubscribed">> => false - }, - <<"sys_heartbeat_interval">> => <<"30s">>, - <<"sys_msg_interval">> => <<"1m">>}, Default), + #{ + <<"sys_event_messages">> => + #{ + <<"client_connected">> => true, + <<"client_disconnected">> => true, + <<"client_subscribed">> => false, + <<"client_unsubscribed">> => false + }, + <<"sys_heartbeat_interval">> => <<"30s">>, + <<"sys_msg_interval">> => <<"1m">> + }, + Default + ), - NConfig = Default#{ - <<"sys_msg_interval">> => <<"4m">>, - <<"sys_event_messages">> => #{<<"client_subscribed">> => false} - }, - {ok, ConfigResp} = put_sys_topics_config(NConfig), - ?assertEqual(NConfig, ConfigResp), - {ok, Default} = put_sys_topics_config(Default). + NConfig = Default#{ + <<"sys_msg_interval">> => <<"4m">>, + <<"sys_event_messages">> => #{<<"client_subscribed">> => false} + }, + {ok, ConfigResp} = put_sys_topics_config(NConfig), + ?assertEqual(NConfig, ConfigResp), + {ok, Default} = put_sys_topics_config(Default). get_sys_topics_config() -> Path = emqx_mgmt_api_test_util:api_path(["mqtt", "sys_topics"]), From 5bfa3e585aaccfe6ec9d764bba50b2ffeb355192 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Tue, 19 Apr 2022 22:27:32 +0200 Subject: [PATCH 5/5] chore: add new code format commit to git-blame-ignore-revs --- git-blame-ignore-revs | 1 + 1 file changed, 1 insertion(+) diff --git a/git-blame-ignore-revs b/git-blame-ignore-revs index aa78ef23b..ddc77e18e 100644 --- a/git-blame-ignore-revs +++ b/git-blame-ignore-revs @@ -24,5 +24,6 @@ f1acfece6b79ed69b491da03783a7adaa7627b96 # reformat apps/emqx_management aa7807baebfa5d8678025e43f386bcd9b3259d6a bf54f571fb8b27e76ada4ca75137d96ce4211d60 +628f0bf57909f26208d45a02e33a7fbae8443249 # reformat apps/emqx_slow_subs 83511f8a4c1570a2c89d9c6c5b6f462520199ed8