feat(M06-A): 建立MQTT连接与Broker基础
This commit is contained in:
@@ -5,6 +5,52 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=lib.sh
|
||||
. "${SCRIPT_DIR}/lib.sh"
|
||||
|
||||
qipai_emqx_install_or_update() {
|
||||
qipai_require_root_for_write
|
||||
qipai_check_arch
|
||||
|
||||
if command -v mqttx >/dev/null 2>&1; then
|
||||
qipai_fail "MQTTX must not be installed on the production server"
|
||||
return 1
|
||||
fi
|
||||
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
apt-get update
|
||||
apt-get install -y curl ca-certificates gnupg lsb-release
|
||||
|
||||
if ! command -v emqx >/dev/null 2>&1; then
|
||||
local installer
|
||||
installer="/tmp/install-emqx-deb.sh"
|
||||
curl -fsSL https://assets.emqx.com/scripts/install-emqx-deb.sh -o "$installer"
|
||||
bash -n "$installer"
|
||||
bash "$installer"
|
||||
fi
|
||||
|
||||
apt-get update
|
||||
apt-get install -y emqx
|
||||
systemctl enable --now emqx
|
||||
qipai_pass "EMQX package installed/updated and service enabled"
|
||||
qipai_emqx_status
|
||||
qipai_info "Authentication users and secrets must be created from /etc/qipai/qipai.secrets; they are never printed here."
|
||||
qipai_info "Apply deploy/emqx/acl.conf.template only after creating qipai_backend_prod and device credentials."
|
||||
}
|
||||
|
||||
qipai_emqx_manage() {
|
||||
qipai_emqx_status
|
||||
if command -v emqx >/dev/null 2>&1; then
|
||||
printf "输入 U 更新 EMQX,直接回车仅查看状态: "
|
||||
else
|
||||
printf "输入 I 安装 EMQX,直接回车仅查看状态: "
|
||||
fi
|
||||
local choice
|
||||
read -r choice || true
|
||||
case "${choice}" in
|
||||
I|i|U|u) qipai_emqx_install_or_update ;;
|
||||
"") qipai_info "EMQX status check complete; no package changes requested" ;;
|
||||
*) qipai_warn "unknown choice; no package changes made" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
qipai_emqx_status() {
|
||||
local acl_template authz_template
|
||||
acl_template="${SCRIPT_DIR}/../../deploy/emqx/acl.conf.template"
|
||||
@@ -20,6 +66,9 @@ qipai_emqx_status() {
|
||||
if command -v emqx >/dev/null 2>&1; then
|
||||
qipai_pass "emqx command exists: $(command -v emqx)"
|
||||
emqx version 2>/dev/null || true
|
||||
if command -v dpkg-query >/dev/null 2>&1; then
|
||||
dpkg-query -W -f='${Package} ${Version} ${Architecture}\n' emqx 2>/dev/null || true
|
||||
fi
|
||||
else
|
||||
qipai_warn "emqx command not found"
|
||||
fi
|
||||
@@ -45,6 +94,12 @@ qipai_emqx_status() {
|
||||
fi
|
||||
done
|
||||
|
||||
if command -v mqttx >/dev/null 2>&1; then
|
||||
qipai_fail "MQTTX is installed on the server; production policy forbids it"
|
||||
else
|
||||
qipai_pass "MQTTX is not installed on the server"
|
||||
fi
|
||||
|
||||
[ -f "$acl_template" ] && qipai_pass "ACL template exists" || qipai_warn "ACL template not found"
|
||||
[ -f "$authz_template" ] && qipai_pass "authorization template exists" || qipai_warn "authorization template not found"
|
||||
|
||||
@@ -54,4 +109,6 @@ qipai_emqx_status() {
|
||||
|
||||
if [ "${1:-}" = "--run" ]; then
|
||||
qipai_emqx_status
|
||||
elif [ "${1:-}" = "--install" ]; then
|
||||
qipai_emqx_install_or_update
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user