add shellcheck to ci (#4126)

* chore(shell): disable some shellcheck

* refactor(shell): fix shellcheck

* test(ci): add shellcheck
This commit is contained in:
Yudai Kiyofuji 2021-02-04 16:51:48 +09:00 committed by GitHub
parent 045bc02ec9
commit aadd1ba11a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 181 additions and 129 deletions

View File

@ -7,7 +7,7 @@ export RELUP_PACKAGE_PATH="/emqx/relup_packages/${EMQX_NAME}"
# export EMQX_NODE_COOKIE=$(date +%s%N) # export EMQX_NODE_COOKIE=$(date +%s%N)
emqx_prepare(){ emqx_prepare(){
mkdir -p ${PACKAGE_PATH} mkdir -p "${PACKAGE_PATH}"
if [ ! -d "/paho-mqtt-testing" ]; then if [ ! -d "/paho-mqtt-testing" ]; then
git clone -b develop-4.0 https://github.com/emqx/paho.mqtt.testing.git /paho-mqtt-testing git clone -b develop-4.0 https://github.com/emqx/paho.mqtt.testing.git /paho-mqtt-testing
@ -16,28 +16,28 @@ emqx_prepare(){
} }
emqx_test(){ emqx_test(){
cd ${PACKAGE_PATH} cd "${PACKAGE_PATH}"
for var in $(ls $PACKAGE_PATH/${EMQX_NAME}-*);do for var in "$PACKAGE_PATH"/"${EMQX_NAME}"-*;do
case ${var##*.} in case ${var##*.} in
"zip") "zip")
packagename=`basename ${PACKAGE_PATH}/${EMQX_NAME}-*.zip` packagename=$(basename "${PACKAGE_PATH}/${EMQX_NAME}"-*.zip)
unzip -q ${PACKAGE_PATH}/$packagename unzip -q "${PACKAGE_PATH}/${packagename}"
sed -i "/zone.external.server_keepalive/c zone.external.server_keepalive = 60" ${PACKAGE_PATH}/emqx/etc/emqx.conf sed -i "/zone.external.server_keepalive/c zone.external.server_keepalive = 60" "${PACKAGE_PATH}"/emqx/etc/emqx.conf
sed -i "/mqtt.max_topic_alias/c mqtt.max_topic_alias = 10" ${PACKAGE_PATH}/emqx/etc/emqx.conf sed -i "/mqtt.max_topic_alias/c mqtt.max_topic_alias = 10" "${PACKAGE_PATH}"/emqx/etc/emqx.conf
sed -i '/emqx_telemetry/d' ${PACKAGE_PATH}/emqx/data/loaded_plugins sed -i '/emqx_telemetry/d' "${PACKAGE_PATH}"/emqx/data/loaded_plugins
if [ ! -z $(echo ${EMQX_DEPS_DEFAULT_VSN#v} | grep -oE "[0-9]+\.[0-9]+(\.[0-9]+)?-(alpha|beta|rc)\.[0-9]") ]; then if echo "${EMQX_DEPS_DEFAULT_VSN#v}" | grep -qE "[0-9]+\.[0-9]+(\.[0-9]+)?-(alpha|beta|rc)\.[0-9]"; then
if [ ! -d ${PACKAGE_PATH}/emqx/lib/emqx-${EMQX_DEPS_DEFAULT_VSN#v} ] || [ ! -d ${PACKAGE_PATH}/emqx/releases/${EMQX_DEPS_DEFAULT_VSN#v} ] ;then if [ ! -d "${PACKAGE_PATH}/emqx/lib/emqx-${EMQX_DEPS_DEFAULT_VSN#v}" ] || [ ! -d "${PACKAGE_PATH}/emqx/releases/${EMQX_DEPS_DEFAULT_VSN#v}" ] ;then
echo "emqx zip version error" echo "emqx zip version error"
exit 1 exit 1
fi fi
fi fi
echo "running ${packagename} start" echo "running ${packagename} start"
${PACKAGE_PATH}/emqx/bin/emqx start || tail ${PACKAGE_PATH}/emqx/log/erlang.log.1 "${PACKAGE_PATH}"/emqx/bin/emqx start || tail "${PACKAGE_PATH}"/emqx/log/erlang.log.1
IDLE_TIME=0 IDLE_TIME=0
while [ -z "$(${PACKAGE_PATH}/emqx/bin/emqx_ctl status |grep 'is running'|awk '{print $1}')" ] while [ -z "$("${PACKAGE_PATH}"/emqx/bin/emqx_ctl status |grep 'is running'|awk '{print $1}')" ]
do do
if [ $IDLE_TIME -gt 10 ] if [ $IDLE_TIME -gt 10 ]
then then
@ -48,54 +48,54 @@ emqx_test(){
IDLE_TIME=$((IDLE_TIME+1)) IDLE_TIME=$((IDLE_TIME+1))
done done
pytest -v /paho-mqtt-testing/interoperability/test_client/V5/test_connect.py::test_basic pytest -v /paho-mqtt-testing/interoperability/test_client/V5/test_connect.py::test_basic
${PACKAGE_PATH}/emqx/bin/emqx stop "${PACKAGE_PATH}"/emqx/bin/emqx stop
echo "running ${packagename} stop" echo "running ${packagename} stop"
rm -rf ${PACKAGE_PATH}/emqx rm -rf "${PACKAGE_PATH}"/emqx
;; ;;
"deb") "deb")
packagename=`basename ${PACKAGE_PATH}/${EMQX_NAME}-*.deb` packagename=$(basename "${PACKAGE_PATH}/${EMQX_NAME}"-*.deb)
dpkg -i ${PACKAGE_PATH}/$packagename dpkg -i "${PACKAGE_PATH}/${packagename}"
if [ $(dpkg -l |grep emqx |awk '{print $1}') != "ii" ] if [ "$(dpkg -l |grep emqx |awk '{print $1}')" != "ii" ]
then then
echo "package install error" echo "package install error"
exit 1 exit 1
fi fi
echo "running ${packagename} start" echo "running ${packagename} start"
running_test running_test
echo "running ${packagename} stop" echo "running ${packagename} stop"
dpkg -r ${EMQX_NAME} dpkg -r "${EMQX_NAME}"
if [ $(dpkg -l |grep emqx |awk '{print $1}') != "rc" ] if [ "$(dpkg -l |grep emqx |awk '{print $1}')" != "rc" ]
then then
echo "package remove error" echo "package remove error"
exit 1 exit 1
fi fi
dpkg -P ${EMQX_NAME} dpkg -P "${EMQX_NAME}"
if [ ! -z "$(dpkg -l |grep emqx)" ] if dpkg -l |grep -q emqx
then then
echo "package uninstall error" echo "package uninstall error"
exit 1 exit 1
fi fi
;; ;;
"rpm") "rpm")
packagename=`basename ${PACKAGE_PATH}/${EMQX_NAME}-*.rpm` packagename=$(basename "${PACKAGE_PATH}/${EMQX_NAME}"-*.rpm)
rpm -ivh ${PACKAGE_PATH}/$packagename rpm -ivh "${PACKAGE_PATH}/${packagename}"
if [ -z $(rpm -q emqx | grep -o emqx) ];then if ! rpm -q emqx | grep -q emqx; then
echo "package install error" echo "package install error"
exit 1 exit 1
fi fi
echo "running ${packagename} start" echo "running ${packagename} start"
running_test running_test
echo "running ${packagename} stop" echo "running ${packagename} stop"
rpm -e ${EMQX_NAME} rpm -e "${EMQX_NAME}"
if [ "$(rpm -q emqx)" != "package emqx is not installed" ];then if [ "$(rpm -q emqx)" != "package emqx is not installed" ];then
echo "package uninstall error" echo "package uninstall error"
exit 1 exit 1
fi fi
;; ;;
esac esac
@ -103,8 +103,8 @@ emqx_test(){
} }
running_test(){ running_test(){
if [ ! -z $(echo ${EMQX_DEPS_DEFAULT_VSN#v} | grep -oE "[0-9]+\.[0-9]+(\.[0-9]+)?-(alpha|beta|rc)\.[0-9]") ]; then if echo "${EMQX_DEPS_DEFAULT_VSN#v}" | grep -qE "[0-9]+\.[0-9]+(\.[0-9]+)?-(alpha|beta|rc)\.[0-9]"; then
if [ ! -d /usr/lib/emqx/lib/emqx-${EMQX_DEPS_DEFAULT_VSN#v} ] || [ ! -d /usr/lib/emqx/releases/${EMQX_DEPS_DEFAULT_VSN#v} ];then if [ ! -d /usr/lib/emqx/lib/emqx-"${EMQX_DEPS_DEFAULT_VSN#v}" ] || [ ! -d /usr/lib/emqx/releases/"${EMQX_DEPS_DEFAULT_VSN#v}" ];then
echo "emqx package version error" echo "emqx package version error"
exit 1 exit 1
fi fi
@ -127,11 +127,12 @@ running_test(){
IDLE_TIME=$((IDLE_TIME+1)) IDLE_TIME=$((IDLE_TIME+1))
done done
pytest -v /paho-mqtt-testing/interoperability/test_client/V5/test_connect.py::test_basic pytest -v /paho-mqtt-testing/interoperability/test_client/V5/test_connect.py::test_basic
emqx stop || kill $(ps -ef | grep -E '\-progname\s.+emqx\s' |awk '{print $2}') # shellcheck disable=SC2009 # pgrep does not support Extended Regular Expressions
emqx stop || kill "$(ps -ef | grep -E '\-progname\s.+emqx\s' |awk '{print $2}')"
if [ $(sed -n '/^ID=/p' /etc/os-release | sed -r 's/ID=(.*)/\1/g' | sed 's/"//g') = ubuntu ] \ if [ "$(sed -n '/^ID=/p' /etc/os-release | sed -r 's/ID=(.*)/\1/g' | sed 's/"//g')" = ubuntu ] \
|| [ $(sed -n '/^ID=/p' /etc/os-release | sed -r 's/ID=(.*)/\1/g' | sed 's/"//g') = debian ] \ || [ "$(sed -n '/^ID=/p' /etc/os-release | sed -r 's/ID=(.*)/\1/g' | sed 's/"//g')" = debian ] \
|| [ $(sed -n '/^ID=/p' /etc/os-release | sed -r 's/ID=(.*)/\1/g' | sed 's/"//g') = raspbian ];then || [ "$(sed -n '/^ID=/p' /etc/os-release | sed -r 's/ID=(.*)/\1/g' | sed 's/"//g')" = raspbian ];then
service emqx start || tail /var/log/emqx/erlang.log.1 service emqx start || tail /var/log/emqx/erlang.log.1
IDLE_TIME=0 IDLE_TIME=0
while [ -z "$(emqx_ctl status |grep 'is running'|awk '{print $1}')" ] while [ -z "$(emqx_ctl status |grep 'is running'|awk '{print $1}')" ]
@ -149,18 +150,18 @@ running_test(){
} }
relup_test(){ relup_test(){
if [ -d ${RELUP_PACKAGE_PATH} ];then if [ -d "${RELUP_PACKAGE_PATH}" ];then
cd ${RELUP_PACKAGE_PATH } cd "${RELUP_PACKAGE_PATH }"
for var in $(ls ${EMQX_NAME}-*-$(uname -m).zip);do for var in "${EMQX_NAME}"-*-"$(uname -m)".zip;do
packagename=`basename ${var}` packagename=$(basename "${var}")
unzip $packagename unzip "$packagename"
./emqx/bin/emqx start ./emqx/bin/emqx start
./emqx/bin/emqx_ctl status ./emqx/bin/emqx_ctl status
./emqx/bin/emqx versions ./emqx/bin/emqx versions
cp ${PACKAGE_PATH}/${EMQX_NAME}-*-${EMQX_DEPS_DEFAULT_VSN#v}-$(uname -m).zip ./emqx/releases cp "${PACKAGE_PATH}/${EMQX_NAME}"-*-"${EMQX_DEPS_DEFAULT_VSN#v}-$(uname -m)".zip ./emqx/releases
./emqx/bin/emqx install ${EMQX_DEPS_DEFAULT_VSN#v} ./emqx/bin/emqx install "${EMQX_DEPS_DEFAULT_VSN#v}"
[ $(./emqx/bin/emqx versions |grep permanent | grep -oE "[0-9].[0-9].[0-9]") = ${EMQX_DEPS_DEFAULT_VSN#v} ] || exit 1 [ "$(./emqx/bin/emqx versions |grep permanent | grep -oE "[0-9].[0-9].[0-9]")" = "${EMQX_DEPS_DEFAULT_VSN#v}" ] || exit 1
./emqx/bin/emqx_ctl status ./emqx/bin/emqx_ctl status
./emqx/bin/emqx stop ./emqx/bin/emqx stop
rm -rf emqx rm -rf emqx

View File

@ -31,7 +31,7 @@ rm -f \
/data/conf/nodes.7001.conf \ /data/conf/nodes.7001.conf \
/data/conf/nodes.7002.conf ; /data/conf/nodes.7002.conf ;
if [ ${node} = "cluster" ] ; then if [ "${node}" = "cluster" ] ; then
if $tls ; then if $tls ; then
redis-server /data/conf/redis-tls.conf --port 7000 --cluster-config-file /data/conf/nodes.7000.conf \ redis-server /data/conf/redis-tls.conf --port 7000 --cluster-config-file /data/conf/nodes.7000.conf \
--tls-port 8000 --cluster-enabled yes ; --tls-port 8000 --cluster-enabled yes ;
@ -44,7 +44,7 @@ if [ ${node} = "cluster" ] ; then
redis-server /data/conf/redis.conf --port 7001 --cluster-config-file /data/conf/nodes.7001.conf --cluster-enabled yes; redis-server /data/conf/redis.conf --port 7001 --cluster-config-file /data/conf/nodes.7001.conf --cluster-enabled yes;
redis-server /data/conf/redis.conf --port 7002 --cluster-config-file /data/conf/nodes.7002.conf --cluster-enabled yes; redis-server /data/conf/redis.conf --port 7002 --cluster-config-file /data/conf/nodes.7002.conf --cluster-enabled yes;
fi fi
elif [ ${node} = "sentinel" ] ; then elif [ "${node}" = "sentinel" ] ; then
redis-server /data/conf/redis.conf --port 7000 --cluster-config-file /data/conf/nodes.7000.conf \ redis-server /data/conf/redis.conf --port 7000 --cluster-config-file /data/conf/nodes.7000.conf \
--cluster-enabled no; --cluster-enabled no;
redis-server /data/conf/redis.conf --port 7001 --cluster-config-file /data/conf/nodes.7001.conf \ redis-server /data/conf/redis.conf --port 7001 --cluster-config-file /data/conf/nodes.7001.conf \
@ -75,9 +75,9 @@ do
else else
continue; continue;
fi fi
if [ ${node} = "cluster" ] ; then if [ "${node}" = "cluster" ] ; then
yes "yes" | redis-cli --cluster create 172.16.239.10:7000 172.16.239.10:7001 172.16.239.10:7002; yes "yes" | redis-cli --cluster create 172.16.239.10:7000 172.16.239.10:7001 172.16.239.10:7002;
elif [ ${node} = "sentinel" ] ; then elif [ "${node}" = "sentinel" ] ; then
cp /data/conf/sentinel.conf /_sentinel.conf cp /data/conf/sentinel.conf /_sentinel.conf
redis-server /_sentinel.conf --sentinel; redis-server /_sentinel.conf --sentinel;
fi fi

18
.github/workflows/shellcheck.yaml vendored Normal file
View File

@ -0,0 +1,18 @@
name: Shellcheck
on: [pull_request]
jobs:
shellcheck:
runs-on: ubuntu-20.04
steps:
- name: Checkout source code
uses: actions/checkout@master
- name: Install shellcheck
run: |
sudo apt-get update
sudo apt install shellcheck
- name: Run shellcheck
run: |
./scripts/shellcheck.sh
echo "success"

100
bin/emqx
View File

@ -1,11 +1,12 @@
#!/bin/sh #!/bin/bash
# -*- tab-width:4;indent-tabs-mode:nil -*- # -*- tab-width:4;indent-tabs-mode:nil -*-
# ex: ts=4 sw=4 et # ex: ts=4 sw=4 et
set -e set -e
ROOT_DIR="$(cd $(dirname $(readlink $0 || echo $0))/..; pwd -P)" ROOT_DIR="$(cd "$(dirname "$(readlink "$0" || echo "$0")")"/..; pwd -P)"
. $ROOT_DIR/releases/emqx_vars # shellcheck disable=SC1090
. "$ROOT_DIR"/releases/emqx_vars
RUNNER_SCRIPT="$RUNNER_BIN_DIR/$REL_NAME" RUNNER_SCRIPT="$RUNNER_BIN_DIR/$REL_NAME"
CODE_LOADING_MODE="${CODE_LOADING_MODE:-embedded}" CODE_LOADING_MODE="${CODE_LOADING_MODE:-embedded}"
@ -79,7 +80,7 @@ relx_usage() {
check_user() { check_user() {
# Validate that the user running the script is the owner of the # Validate that the user running the script is the owner of the
# RUN_DIR. # RUN_DIR.
if ([ "$RUNNER_USER" ] && [ "x$WHOAMI" != "x$RUNNER_USER" ]); then if [ "$RUNNER_USER" ] && [ "x$WHOAMI" != "x$RUNNER_USER" ]; then
if [ "x$WHOAMI" != "xroot" ]; then if [ "x$WHOAMI" != "xroot" ]; then
echo "You need to be root or use sudo to run this command" echo "You need to be root or use sudo to run this command"
exit 1 exit 1
@ -90,13 +91,13 @@ check_user() {
done done
# This will drop priviledges into the runner user # This will drop priviledges into the runner user
# It exec's in a new shell and the current shell will exit # It exec's in a new shell and the current shell will exit
exec su - $RUNNER_USER -c "$CMD" exec su - "$RUNNER_USER" -c "$CMD"
fi fi
} }
# Make sure the user running this script is the owner and/or su to that user # Make sure the user running this script is the owner and/or su to that user
check_user $@ check_user "$@"
ES=$? ES=$?
if [ "$ES" -ne 0 ]; then if [ "$ES" -ne 0 ]; then
exit $ES exit $ES
@ -109,7 +110,7 @@ else
fi fi
# Warn the user if ulimit -n is less than 1024 # Warn the user if ulimit -n is less than 1024
ULIMIT_F=`ulimit -n` ULIMIT_F=$(ulimit -n)
if [ "$ULIMIT_F" -lt 1024 ]; then if [ "$ULIMIT_F" -lt 1024 ]; then
echo "!!!!" echo "!!!!"
echo "!!!! WARNING: ulimit -n is ${ULIMIT_F}; 1024 is the recommended minimum." echo "!!!! WARNING: ulimit -n is ${ULIMIT_F}; 1024 is the recommended minimum."
@ -133,6 +134,7 @@ esac
relx_get_pid() { relx_get_pid() {
if output="$(relx_nodetool rpcterms os getpid)" if output="$(relx_nodetool rpcterms os getpid)"
then then
# shellcheck disable=SC2001 # Escaped quote taken as closing quote in editor
echo "$output" | sed -e 's/"//g' echo "$output" | sed -e 's/"//g'
return 0 return 0
else else
@ -143,7 +145,7 @@ relx_get_pid() {
relx_get_nodename() { relx_get_nodename() {
id="longname$(relx_gen_id)-${NAME}" id="longname$(relx_gen_id)-${NAME}"
"$BINDIR/erl" -boot "$REL_DIR/start_clean" -eval '[Host] = tl(string:tokens(atom_to_list(node()),"@")), io:format("~s~n", [Host]), halt()' -noshell ${NAME_TYPE} $id "$BINDIR/erl" -boot "$REL_DIR/start_clean" -eval '[Host] = tl(string:tokens(atom_to_list(node()),"@")), io:format("~s~n", [Host]), halt()' -noshell "${NAME_TYPE}" "$id"
} }
# Connect to a remote node # Connect to a remote node
@ -154,10 +156,11 @@ relx_rem_sh() {
# Get the node's ticktime so that we use the same thing. # Get the node's ticktime so that we use the same thing.
TICKTIME="$(relx_nodetool rpcterms net_kernel get_net_ticktime)" TICKTIME="$(relx_nodetool rpcterms net_kernel get_net_ticktime)"
# shellcheck disable=SC2086 # $EPMD_ARG is supposed to be split by whitespace
# Setup remote shell command to control node # Setup remote shell command to control node
exec "$BINDIR/erl" "$NAME_TYPE" "$id" -remsh "$NAME" -boot "$REL_DIR/start_clean" \ exec "$BINDIR/erl" "$NAME_TYPE" "$id" -remsh "$NAME" -boot "$REL_DIR/start_clean" \
-boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \ -boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \
-setcookie "$COOKIE" -hidden -kernel net_ticktime $TICKTIME $EPMD_ARG -setcookie "$COOKIE" -hidden -kernel net_ticktime "$TICKTIME" $EPMD_ARG
} }
# Generate a random id # Generate a random id
@ -171,7 +174,7 @@ relx_nodetool() {
ERL_FLAGS="$ERL_FLAGS $EPMD_ARG" \ ERL_FLAGS="$ERL_FLAGS $EPMD_ARG" \
"$ERTS_DIR/bin/escript" "$ROOTDIR/bin/nodetool" "$NAME_TYPE" "$NAME" \ "$ERTS_DIR/bin/escript" "$ROOTDIR/bin/nodetool" "$NAME_TYPE" "$NAME" \
-setcookie "$COOKIE" "$command" $@ -setcookie "$COOKIE" "$command" "$@"
} }
# Run an escript in the node's environment # Run an escript in the node's environment
@ -179,7 +182,7 @@ relx_escript() {
shift; scriptpath="$1"; shift shift; scriptpath="$1"; shift
export RUNNER_ROOT_DIR export RUNNER_ROOT_DIR
"$ERTS_DIR/bin/escript" "$ROOTDIR/$scriptpath" $@ "$ERTS_DIR/bin/escript" "$ROOTDIR/$scriptpath" "$@"
} }
# Output a start command for the last argument of run_erl # Output a start command for the last argument of run_erl
@ -202,19 +205,19 @@ generate_config() {
# the vm, we need to pass it in twice. # the vm, we need to pass it in twice.
CONFIG_ARGS=" -config $RUNNER_ETC_DIR/app.config -args_file $RUNNER_ETC_DIR/vm.args -vm_args $RUNNER_ETC_DIR/vm.args " CONFIG_ARGS=" -config $RUNNER_ETC_DIR/app.config -args_file $RUNNER_ETC_DIR/vm.args -vm_args $RUNNER_ETC_DIR/vm.args "
else else
CONFIG_ARGS=`$ERTS_PATH/escript $RUNNER_ROOT_DIR/bin/cuttlefish -i $REL_DIR/emqx.schema -c $RUNNER_ETC_DIR/emqx.conf -d $RUNNER_DATA_DIR/configs generate` CONFIG_ARGS=$("$ERTS_PATH"/escript "$RUNNER_ROOT_DIR"/bin/cuttlefish -i "$REL_DIR"/emqx.schema -c "$RUNNER_ETC_DIR"/emqx.conf -d "$RUNNER_DATA_DIR"/configs generate)
## Merge cuttlefish generated *.args into the vm.args ## Merge cuttlefish generated *.args into the vm.args
CUTTLE_GEN_ARG_FILE=`echo "$CONFIG_ARGS" | sed -n 's/^.*\(vm_args[[:space:]]\)//p' | awk '{print $1}'` CUTTLE_GEN_ARG_FILE=$(echo "$CONFIG_ARGS" | sed -n 's/^.*\(vm_args[[:space:]]\)//p' | awk '{print $1}')
TMP_ARG_FILE="$RUNNER_DATA_DIR/configs/vm.args.tmp" TMP_ARG_FILE="$RUNNER_DATA_DIR/configs/vm.args.tmp"
cp "$RUNNER_ETC_DIR/vm.args" "$TMP_ARG_FILE" cp "$RUNNER_ETC_DIR/vm.args" "$TMP_ARG_FILE"
echo "" >> "$TMP_ARG_FILE" echo "" >> "$TMP_ARG_FILE"
sed '/^#/d' $CUTTLE_GEN_ARG_FILE | sed '/^$/d' | while IFS='' read -r ARG_LINE || [ -n "$ARG_LINE" ]; do sed '/^#/d' "$CUTTLE_GEN_ARG_FILE" | sed '/^$/d' | while IFS='' read -r ARG_LINE || [ -n "$ARG_LINE" ]; do
ARG_KEY=`echo "$ARG_LINE" | awk '{$NF="";print}'` ARG_KEY=$(echo "$ARG_LINE" | awk '{$NF="";print}')
ARG_VALUE=`echo "$ARG_LINE" | awk '{print $NF}'` ARG_VALUE=$(echo "$ARG_LINE" | awk '{print $NF}')
TMP_ARG_VALUE=`grep "^$ARG_KEY" "$TMP_ARG_FILE" | awk '{print $NF}'` TMP_ARG_VALUE=$(grep "^$ARG_KEY" "$TMP_ARG_FILE" | awk '{print $NF}')
if [ "$ARG_VALUE" != "$TMP_ARG_VALUE" ] ; then if [ "$ARG_VALUE" != "$TMP_ARG_VALUE" ] ; then
if [ ! -z $TMP_ARG_VALUE ]; then if [ -n "$TMP_ARG_VALUE" ]; then
sh -c "$SED_REPLACE 's/^$ARG_KEY.*$/$ARG_LINE/' $TMP_ARG_FILE" sh -c "$SED_REPLACE 's/^$ARG_KEY.*$/$ARG_LINE/' $TMP_ARG_FILE"
else else
echo "$ARG_LINE" >> "$TMP_ARG_FILE" echo "$ARG_LINE" >> "$TMP_ARG_FILE"
@ -224,6 +227,7 @@ generate_config() {
mv -f "$TMP_ARG_FILE" "$CUTTLE_GEN_ARG_FILE" mv -f "$TMP_ARG_FILE" "$CUTTLE_GEN_ARG_FILE"
fi fi
# shellcheck disable=SC2086
if ! relx_nodetool chkconfig $CONFIG_ARGS; then if ! relx_nodetool chkconfig $CONFIG_ARGS; then
echoerr "Error reading $CONFIG_ARGS" echoerr "Error reading $CONFIG_ARGS"
exit 1 exit 1
@ -233,7 +237,7 @@ generate_config() {
# Call bootstrapd for daemon commands like start/stop/console # Call bootstrapd for daemon commands like start/stop/console
bootstrapd() { bootstrapd() {
if [ -e "$RUNNER_DATA_DIR/.erlang.cookie" ]; then if [ -e "$RUNNER_DATA_DIR/.erlang.cookie" ]; then
chown $RUNNER_USER $RUNNER_DATA_DIR/.erlang.cookie chown "$RUNNER_USER" "$RUNNER_DATA_DIR"/.erlang.cookie
fi fi
} }
@ -249,8 +253,9 @@ fi
if [ -z "$NAME_ARG" ]; then if [ -z "$NAME_ARG" ]; then
NODENAME="${EMQX_NODE_NAME:-}" NODENAME="${EMQX_NODE_NAME:-}"
# check if there is a node running, inspect its name # check if there is a node running, inspect its name
[ -z "$NODENAME" ] && NODENAME=`ps -ef | grep -E '\-progname\s.*emqx\s' | grep -o -E '\-name (\S*)' | awk '{print $2}'` # shellcheck disable=SC2009 # pgrep does not support Extended Regular Expressions
[ -z "$NODENAME" ] && NODENAME=`egrep '^[ \t]*node.name[ \t]*=[ \t]*' "$RUNNER_ETC_DIR/emqx.conf" 2> /dev/null | tail -1 | cut -d = -f 2-` [ -z "$NODENAME" ] && NODENAME=$(ps -ef | grep -E '\-progname\s.*emqx\s' | grep -o -E '\-name (\S*)' | awk '{print $2}')
[ -z "$NODENAME" ] && NODENAME=$(grep -E '^[ \t]*node.name[ \t]*=[ \t]*' "$RUNNER_ETC_DIR/emqx.conf" 2> /dev/null | tail -1 | cut -d = -f 2-)
if [ -z "$NODENAME" ]; then if [ -z "$NODENAME" ]; then
echoerr "vm.args needs to have a -name parameter." echoerr "vm.args needs to have a -name parameter."
echoerr " -sname is not supported." echoerr " -sname is not supported."
@ -273,8 +278,9 @@ PIPE_DIR="${PIPE_DIR:-/$RUNNER_DATA_DIR/${WHOAMI}_erl_pipes/$NAME/}"
if [ -z "$COOKIE_ARG" ]; then if [ -z "$COOKIE_ARG" ]; then
COOKIE="${EMQX_NODE_COOKIE:-}" COOKIE="${EMQX_NODE_COOKIE:-}"
# check if there is a node running, steal its cookie # check if there is a node running, steal its cookie
[ -z "$COOKIE" ] && COOKIE=`ps -ef | grep -E '\-progname\s.*emqx\s' | grep -o -E '\-setcookie (\S*)' | awk '{print $2}'` # shellcheck disable=SC2009 # pgrep does not support Extended Regular Expressions
[ -z "$COOKIE" ] && COOKIE=`egrep '^[ \t]*node.cookie[ \t]*=[ \t]*' "$RUNNER_ETC_DIR/emqx.conf" 2> /dev/null | tail -1 | cut -d = -f 2-` [ -z "$COOKIE" ] && COOKIE=$(ps -ef | grep -E '\-progname\s.*emqx\s' | grep -o -E '\-setcookie (\S*)' | awk '{print $2}')
[ -z "$COOKIE" ] && COOKIE=$(grep -E '^[ \t]*node.cookie[ \t]*=[ \t]*' "$RUNNER_ETC_DIR/emqx.conf" 2> /dev/null | tail -1 | cut -d = -f 2-)
if [ -z "$COOKIE" ]; then if [ -z "$COOKIE" ]; then
echoerr "vm.args needs to have a -setcookie parameter." echoerr "vm.args needs to have a -setcookie parameter."
echoerr "please check $RUNNER_ETC_DIR/emqx.conf" echoerr "please check $RUNNER_ETC_DIR/emqx.conf"
@ -288,7 +294,7 @@ fi
COOKIE="$(echo "$COOKIE_ARG" | awk '{print $2}')" COOKIE="$(echo "$COOKIE_ARG" | awk '{print $2}')"
# Support for IPv6 Dist. See: https://github.com/emqtt/emqttd/issues/1460 # Support for IPv6 Dist. See: https://github.com/emqtt/emqttd/issues/1460
PROTO_DIST=`egrep '^[ \t]*cluster.proto_dist[ \t]*=[ \t]*' "$RUNNER_ETC_DIR/emqx.conf" 2> /dev/null | tail -1 | cut -d = -f 2-` PROTO_DIST=$(grep -E '^[ \t]*cluster.proto_dist[ \t]*=[ \t]*' "$RUNNER_ETC_DIR/emqx.conf" 2> /dev/null | tail -1 | cut -d = -f 2-)
if [ -z "$PROTO_DIST" ]; then if [ -z "$PROTO_DIST" ]; then
PROTO_DIST_ARG="" PROTO_DIST_ARG=""
else else
@ -327,7 +333,7 @@ case "$1" in
exit 1 exit 1
fi fi
# Bootstrap daemon command (check perms & drop to $RUNNER_USER) # Bootstrap daemon command (check perms & drop to $RUNNER_USER)
bootstrapd $@ bootstrapd
# Save this for later. # Save this for later.
CMD=$1 CMD=$1
@ -343,7 +349,7 @@ case "$1" in
HEART_OPTION="start_boot" HEART_OPTION="start_boot"
;; ;;
esac esac
RUN_PARAM="$@" RUN_PARAM="$*"
# Set arguments for the heart command # Set arguments for the heart command
set -- "$RUNNER_SCRIPT" "$HEART_OPTION" set -- "$RUNNER_SCRIPT" "$HEART_OPTION"
@ -366,9 +372,9 @@ case "$1" in
"$(relx_start_command)" "$(relx_start_command)"
WAIT_TIME=${WAIT_FOR_ERLANG:-15} WAIT_TIME=${WAIT_FOR_ERLANG:-15}
while [ $WAIT_TIME -gt 0 ]; do while [ "$WAIT_TIME" -gt 0 ]; do
if ! relx_nodetool "ping" >/dev/null 2>&1; then if ! relx_nodetool "ping" >/dev/null 2>&1; then
WAIT_TIME=`expr $WAIT_TIME - 1` WAIT_TIME=$((WAIT_TIME - 1))
sleep 1 sleep 1
continue continue
fi fi
@ -390,14 +396,14 @@ case "$1" in
if ! relx_nodetool "stop"; then if ! relx_nodetool "stop"; then
exit 1 exit 1
fi fi
while $(kill -s 0 "$PID" 2>/dev/null); do while kill -s 0 "$PID" 2>/dev/null; do
sleep 1 sleep 1
done done
;; ;;
restart|reboot) restart|reboot)
echo "$EMQX_DISCR $REL_VSN is stopped: $($RUNNER_BIN_DIR/emqx stop)" echo "$EMQX_DISCR $REL_VSN is stopped: $("$RUNNER_BIN_DIR"/emqx stop)"
$RUNNER_BIN_DIR/emqx start "$RUNNER_BIN_DIR"/emqx start
;; ;;
pid) pid)
@ -416,7 +422,7 @@ case "$1" in
escript) escript)
## Run an escript under the node's environment ## Run an escript under the node's environment
if ! relx_escript $@; then if ! relx_escript "$@"; then
exit 1 exit 1
fi fi
;; ;;
@ -429,7 +435,7 @@ case "$1" in
fi fi
# Bootstrap daemon command (check perms & drop to $RUNNER_USER) # Bootstrap daemon command (check perms & drop to $RUNNER_USER)
bootstrapd $@ bootstrapd
shift shift
exec "$BINDIR/to_erl" "$PIPE_DIR" exec "$BINDIR/to_erl" "$PIPE_DIR"
@ -443,7 +449,7 @@ case "$1" in
fi fi
# Bootstrap daemon command (check perms & drop to $RUNNER_USER) # Bootstrap daemon command (check perms & drop to $RUNNER_USER)
bootstrapd $@ bootstrapd
shift shift
relx_rem_sh relx_rem_sh
@ -485,7 +491,7 @@ case "$1" in
console|console_clean|console_boot) console|console_clean|console_boot)
# Bootstrap daemon command (check perms & drop to $RUNNER_USER) # Bootstrap daemon command (check perms & drop to $RUNNER_USER)
bootstrapd $@ bootstrapd
# .boot file typically just $REL_NAME (ie, the app name) # .boot file typically just $REL_NAME (ie, the app name)
# however, for debugging, sometimes start_clean.boot is useful. # however, for debugging, sometimes start_clean.boot is useful.
@ -519,8 +525,9 @@ case "$1" in
export PROGNAME export PROGNAME
# Store passed arguments since they will be erased by `set` # Store passed arguments since they will be erased by `set`
ARGS="$@" ARGS="$*"
# shellcheck disable=SC2086 # $RELX_CONFIG_PATH $CONFIG_ARGS $EPMD_ARG are supposed to be split by whitespace
# Build an array of arguments to pass to exec later on # Build an array of arguments to pass to exec later on
# Build it here because this command will be used for logging. # Build it here because this command will be used for logging.
set -- "$BINDIR/erlexec" -boot "$BOOTFILE" -mode "$CODE_LOADING_MODE" \ set -- "$BINDIR/erlexec" -boot "$BOOTFILE" -mode "$CODE_LOADING_MODE" \
@ -529,12 +536,12 @@ case "$1" in
$RELX_CONFIG_PATH $CONFIG_ARGS $EPMD_ARG $RELX_CONFIG_PATH $CONFIG_ARGS $EPMD_ARG
# Dump environment info for logging purposes # Dump environment info for logging purposes
echo "Exec: $@" -- ${1+$ARGS} echo "Exec: $*" -- ${1+$ARGS}
echo "Root: $ROOTDIR" echo "Root: $ROOTDIR"
# Log the startup # Log the startup
echo "$RUNNER_ROOT_DIR" echo "$RUNNER_ROOT_DIR"
logger -t "$REL_NAME[$$]" "Starting up" logger -t "${REL_NAME[$$]}" "Starting up"
# Start the VM # Start the VM
exec "$@" -- ${1+$ARGS} exec "$@" -- ${1+$ARGS}
@ -542,7 +549,7 @@ case "$1" in
foreground) foreground)
# Bootstrap daemon command (check perms & drop to $RUNNER_USER) # Bootstrap daemon command (check perms & drop to $RUNNER_USER)
bootstrapd $@ bootstrapd
# start up the release in the foreground for use by runit # start up the release in the foreground for use by runit
# or other supervision services # or other supervision services
@ -560,8 +567,9 @@ case "$1" in
export PROGNAME export PROGNAME
# Store passed arguments since they will be erased by `set` # Store passed arguments since they will be erased by `set`
ARGS="$@" ARGS="$*"
# shellcheck disable=SC2086 # $RELX_CONFIG_PATH $CONFIG_ARGS $EPMD_ARG are supposed to be split by whitespace
# Build an array of arguments to pass to exec later on # Build an array of arguments to pass to exec later on
# Build it here because this command will be used for logging. # Build it here because this command will be used for logging.
set -- "$BINDIR/erlexec" $FOREGROUNDOPTIONS \ set -- "$BINDIR/erlexec" $FOREGROUNDOPTIONS \
@ -571,14 +579,14 @@ case "$1" in
$RELX_CONFIG_PATH $CONFIG_ARGS $EPMD_ARG $RELX_CONFIG_PATH $CONFIG_ARGS $EPMD_ARG
# Dump environment info for logging purposes # Dump environment info for logging purposes
echo "Exec: $@" -- ${1+$ARGS} echo "Exec: $*" -- ${1+$ARGS}
echo "Root: $ROOTDIR" echo "Root: $ROOTDIR"
# Start the VM # Start the VM
exec "$@" -- ${1+$ARGS} exec "$@" -- ${1+$ARGS}
;; ;;
ertspath) ertspath)
echo $ERTS_PATH echo "$ERTS_PATH"
;; ;;
rpc) rpc)
# Make sure a node IS running # Make sure a node IS running
@ -589,7 +597,7 @@ case "$1" in
shift shift
relx_nodetool rpc $@ relx_nodetool rpc "$@"
;; ;;
rpcterms) rpcterms)
# Make sure a node IS running # Make sure a node IS running
@ -600,7 +608,7 @@ case "$1" in
shift shift
relx_nodetool rpcterms $@ relx_nodetool rpcterms "$@"
;; ;;
root_dir) root_dir)
# Make sure a node IS running # Make sure a node IS running
@ -620,10 +628,10 @@ case "$1" in
fi fi
shift shift
relx_nodetool "eval" $@ relx_nodetool "eval" "$@"
;; ;;
*) *)
relx_usage $1 relx_usage "$1"
exit 1 exit 1
;; ;;
esac esac

View File

@ -4,8 +4,9 @@
set -e set -e
ROOT_DIR="$(cd $(dirname $(readlink $0 || echo $0))/..; pwd -P)" ROOT_DIR="$(cd "$(dirname "$(readlink "$0" || echo "$0")")"/..; pwd -P)"
. $ROOT_DIR/releases/emqx_vars # shellcheck disable=SC1090
. "$ROOT_DIR"/releases/emqx_vars
# Echo to stderr on errors # Echo to stderr on errors
echoerr() { echo "$@" 1>&2; } echoerr() { echo "$@" 1>&2; }
@ -18,7 +19,7 @@ fi
relx_get_nodename() { relx_get_nodename() {
id="longname$(relx_gen_id)-${NAME}" id="longname$(relx_gen_id)-${NAME}"
"$BINDIR/erl" -boot start_clean -eval '[Host] = tl(string:tokens(atom_to_list(node()),"@")), io:format("~s~n", [Host]), halt()' -noshell ${NAME_TYPE} $id "$BINDIR/erl" -boot start_clean -eval '[Host] = tl(string:tokens(atom_to_list(node()),"@")), io:format("~s~n", [Host]), halt()' -noshell "${NAME_TYPE}" "$id"
} }
# Control a node # Control a node
@ -34,8 +35,9 @@ relx_nodetool() {
if [ -z "$NAME_ARG" ]; then if [ -z "$NAME_ARG" ]; then
NODENAME="${EMQX_NODE_NAME:-}" NODENAME="${EMQX_NODE_NAME:-}"
# check if there is a node running, inspect its name # check if there is a node running, inspect its name
[ -z "$NODENAME" ] && NODENAME=`ps -ef | grep -E '\progname\s.*emqx\s' | grep -o -E '\-name (\S*)' | awk '{print $2}'` # shellcheck disable=SC2009 # pgrep does not support Extended Regular Expressions
[ -z "$NODENAME" ] && NODENAME=`egrep '^[ \t]*node.name[ \t]*=[ \t]*' "$RUNNER_ETC_DIR/emqx.conf" 2> /dev/null | tail -1 | cut -d = -f 2-` [ -z "$NODENAME" ] && NODENAME=$(ps -ef | grep -E '\progname\s.*emqx\s' | grep -o -E '\-name (\S*)' | awk '{print $2}')
[ -z "$NODENAME" ] && NODENAME=$(grep -E '^[ \t]*node.name[ \t]*=[ \t]*' "$RUNNER_ETC_DIR/emqx.conf" 2> /dev/null | tail -1 | cut -d = -f 2-)
if [ -z "$NODENAME" ]; then if [ -z "$NODENAME" ]; then
echoerr "vm.args needs to have a -name parameter." echoerr "vm.args needs to have a -name parameter."
echoerr " -sname is not supported." echoerr " -sname is not supported."
@ -54,8 +56,9 @@ NAME="$(echo "$NAME_ARG" | awk '{print $2}')"
if [ -z "$COOKIE_ARG" ]; then if [ -z "$COOKIE_ARG" ]; then
COOKIE="${EMQX_NODE_COOKIE:-}" COOKIE="${EMQX_NODE_COOKIE:-}"
# check if there is a node running, steal its cookie # check if there is a node running, steal its cookie
[ -z "$COOKIE" ] && COOKIE=`ps -ef | grep -E '\-progname\s.*emqx\s' | grep -o -E '\-setcookie (\S*)' | awk '{print $2}'` # shellcheck disable=SC2009 # pgrep does not support Extended Regular Expressions
[ -z "$COOKIE" ] && COOKIE=`egrep '^[ \t]*node.cookie[ \t]*=[ \t]*' "$RUNNER_ETC_DIR/emqx.conf" 2> /dev/null | tail -1 | cut -d = -f 2-` [ -z "$COOKIE" ] && COOKIE=$(ps -ef | grep -E '\-progname\s.*emqx\s' | grep -o -E '\-setcookie (\S*)' | awk '{print $2}')
[ -z "$COOKIE" ] && COOKIE=$(grep -E '^[ \t]*node.cookie[ \t]*=[ \t]*' "$RUNNER_ETC_DIR/emqx.conf" 2> /dev/null | tail -1 | cut -d = -f 2-)
if [ -z "$COOKIE" ]; then if [ -z "$COOKIE" ]; then
echoerr "vm.args needs to have a -setcookie parameter." echoerr "vm.args needs to have a -setcookie parameter."
echoerr "please check $RUNNER_ETC_DIR/emqx.conf" echoerr "please check $RUNNER_ETC_DIR/emqx.conf"
@ -69,7 +72,7 @@ fi
COOKIE="$(echo "$COOKIE_ARG" | awk '{print $2}')" COOKIE="$(echo "$COOKIE_ARG" | awk '{print $2}')"
# Support for IPv6 Dist. See: https://github.com/emqtt/emqttd/issues/1460 # Support for IPv6 Dist. See: https://github.com/emqtt/emqttd/issues/1460
PROTO_DIST=`egrep '^[ \t]*cluster.proto_dist[ \t]*=[ \t]*' $RUNNER_ETC_DIR/emqx.conf 2> /dev/null | tail -1 | cut -d = -f 2-` PROTO_DIST=$(grep -E '^[ \t]*cluster.proto_dist[ \t]*=[ \t]*' "$RUNNER_ETC_DIR"/emqx.conf 2> /dev/null | tail -1 | cut -d = -f 2-)
if [ -z "$PROTO_DIST" ]; then if [ -z "$PROTO_DIST" ]; then
PROTO_DIST_ARG="" PROTO_DIST_ARG=""
else else

3
build
View File

@ -71,7 +71,8 @@ make_relup() {
local releases=() local releases=()
if [ -d "$releases_dir" ]; then if [ -d "$releases_dir" ]; then
while read -r dir; do while read -r dir; do
local version="$(basename "$dir")" local version
version="$(basename "$dir")"
# skip current version # skip current version
if [ "$version" != "$PKG_VSN" ]; then if [ "$version" != "$PKG_VSN" ]; then
releases+=( "$version" ) releases+=( "$version" )

View File

@ -128,9 +128,9 @@ try_fill_config() {
if grep -qE "^[#[:space:]]*$escaped_key\s*=" "$file"; then if grep -qE "^[#[:space:]]*$escaped_key\s*=" "$file"; then
echo_value "$key" "$value" echo_value "$key" "$value"
if [[ -z "$value" ]]; then if [[ -z "$value" ]]; then
echo "$(sed -r "s/^[#[:space:]]*($escaped_key)\s*=\s*(.*)/# \1 = \2/" "$file")" > "$file" sed -r "s/^[#[:space:]]*($escaped_key)\s*=\s*(.*)/# \1 = \2/" "$file" > tmpfile && cat tmpfile > "$file"
else else
echo "$(sed -r "s/^[#[:space:]]*($escaped_key)\s*=\s*(.*)/\1 = $escaped_value/" "$file")" > "$file" sed -r "s/^[#[:space:]]*($escaped_key)\s*=\s*(.*)/\1 = $escaped_value/" "$file" > tmpfile && cat tmpfile > "$file"
fi fi
# Check if config has a numbering system, but no existing configuration line in file # Check if config has a numbering system, but no existing configuration line in file
elif echo "$key" | grep -qE '\.\d+|\d+\.'; then elif echo "$key" | grep -qE '\.\d+|\d+\.'; then
@ -139,7 +139,7 @@ try_fill_config() {
template="$(echo "$escaped_key" | sed -r -e 's/\\\.[0-9]+/\\.[0-9]+/g' -e 's/[0-9]+\\\./[0-9]+\\./g')" template="$(echo "$escaped_key" | sed -r -e 's/\\\.[0-9]+/\\.[0-9]+/g' -e 's/[0-9]+\\\./[0-9]+\\./g')"
if grep -qE "^[#[:space:]]*$template\s*=" "$file"; then if grep -qE "^[#[:space:]]*$template\s*=" "$file"; then
echo_value "$key" "$value" echo_value "$key" "$value"
echo "$(sed '$a'\\ "$file")" > "$file" sed '$a'\\ "$file" > tmpfile && cat tmpfile > "$file"
echo "$key = $value" >> "$file" echo "$key = $value" >> "$file"
fi fi
fi fi
@ -171,12 +171,12 @@ fill_tuples() {
local elements=${*:2} local elements=${*:2}
for var in $elements; do for var in $elements; do
if grep -qE "\{\s*$var\s*,\s*(true|false)\s*\}\s*\." "$file"; then if grep -qE "\{\s*$var\s*,\s*(true|false)\s*\}\s*\." "$file"; then
echo "$(sed -r "s/\{\s*($var)\s*,\s*(true|false)\s*\}\s*\./{\1, true}./1" "$file")" > "$file" sed -r "s/\{\s*($var)\s*,\s*(true|false)\s*\}\s*\./{\1, true}./1" "$file" > tmpfile && mv tmpfile "$file"
elif grep -q "$var\s*\." "$file"; then elif grep -q "$var\s*\." "$file"; then
# backward compatible. # backward compatible.
echo "$(sed -r "s/($var)\s*\./{\1, true}./1" "$file")" > "$file" sed -r "s/($var)\s*\./{\1, true}./1" "$file" > tmpfile && cat tmpfile > "$file"
else else
echo "$(sed '$a'\\ "$file")" > "$file" sed '$a'\\ "$file" > tmpfile && cat tmpfile > "$file"
echo "{$var, true}." >> "$file" echo "{$var, true}." >> "$file"
fi fi
done done

View File

@ -1,4 +1,4 @@
#!/bin/sh #!/bin/bash
# #
# emqx # emqx
# #
@ -8,11 +8,11 @@
# #
# Source function library. # Source function library.
# shellcheck disable=SC1091
. /etc/rc.d/init.d/functions . /etc/rc.d/init.d/functions
RETVAL=0 RETVAL=0
PATH=/sbin:/usr/sbin:/bin:/usr/bin PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="EMQX, a distributed, massively scalable, highly extensible MQTT message broker written in Erlang/OTP"
NAME=emqx NAME=emqx
DAEMON=/usr/bin/$NAME DAEMON=/usr/bin/$NAME
lockfile=/var/lock/subsys/$NAME lockfile=/var/lock/subsys/$NAME
@ -25,6 +25,7 @@ pidfile=/var/run/$NAME/$NAME.pid
[ -d /var/lib/$NAME ] || exit 0 [ -d /var/lib/$NAME ] || exit 0
# Read configuration variable file if it is present and readable # Read configuration variable file if it is present and readable
# shellcheck disable=SC1090
[ -r /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME [ -r /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
# `service` strips all environmental VARS so # `service` strips all environmental VARS so
@ -34,15 +35,17 @@ if [ -z "$HOME" ]; then
export HOME= export HOME=
fi fi
status -p $pidfile -l $(basename $lockfile) $NAME >/dev/null 2>&1 status -p $pidfile -l "$(basename $lockfile)" $NAME >/dev/null 2>&1
running=$? running=$?
find_pid() { find_pid() {
# shellcheck disable=SC2009 # pgrep does not support Extended Regular Expressions
ps ax | grep -E "\-progname\s+$NAME\s" | awk '{print $1}' ps ax | grep -E "\-progname\s+$NAME\s" | awk '{print $1}'
} }
check_pid_status() { check_pid_status() {
local pid="$(find_pid)" local pid
pid="$(find_pid)"
if [ "$pid" = "" ]; then if [ "$pid" = "" ]; then
# prog not running? # prog not running?
return 1 return 1
@ -72,7 +75,7 @@ stop() {
# Stop daemon. # Stop daemon.
echo -n $"Shutting down emqx: " echo -n $"Shutting down emqx: "
$DAEMON stop 2>/dev/null $DAEMON stop 2>/dev/null
for n in $(seq 1 10); do for _ in $(seq 1 10); do
sleep 1 sleep 1
check_pid_status check_pid_status
RETVAL=$? RETVAL=$?
@ -93,7 +96,7 @@ stop() {
hardstop() { hardstop() {
echo -n $"Shutting down $NAME: " echo -n $"Shutting down $NAME: "
su - emqx -c "ps -ef | grep -E '\-progname\s+$NAME\s' | awk '{print \$2}' | xargs kill -9" su - emqx -c "ps -ef | grep -E '\-progname\s+$NAME\s' | awk '{print \$2}' | xargs kill -9"
for n in $(seq 1 10); do for _ in $(seq 1 10); do
sleep 1 sleep 1
check_pid_status check_pid_status
RETVAL=$? RETVAL=$?
@ -133,7 +136,7 @@ case "$1" in
restart restart
;; ;;
status) status)
status -p $pidfile -l $(basename $lockfile) $NAME status -p $pidfile -l "$(basename $lockfile)" $NAME
;; ;;
ping) ping)
$DAEMON ping || exit $? $DAEMON ping || exit $?

14
scripts/shellcheck.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
set -euo pipefail
target_files=()
while IFS='' read -r line; do target_files+=("$line"); done < <(grep -r -l --exclude-dir=.git --exclude-dir=_build "#!/bin/" .)
return_code=0
for i in "${target_files[@]}"; do
echo checking "$i" ...
if ! shellcheck "$i"; then
return_code=1
fi
done
exit $return_code

View File

@ -39,8 +39,8 @@ docker run -d -t --restart=always --name "$NODE1" \
-e EMQX_NODE_COOKIE="$COOKIE" \ -e EMQX_NODE_COOKIE="$COOKIE" \
-e WAIT_FOR_ERLANG=60 \ -e WAIT_FOR_ERLANG=60 \
-p 18083:18083 \ -p 18083:18083 \
-v $PROJ_DIR/_build/emqx/rel/emqx:/built \ -v "$PROJ_DIR"/_build/emqx/rel/emqx:/built \
$IMAGE sh -c 'cp -r /built /emqx && /emqx/bin/emqx console' "$IMAGE" sh -c 'cp -r /built /emqx && /emqx/bin/emqx console'
docker run -d -t --restart=always --name "$NODE2" \ docker run -d -t --restart=always --name "$NODE2" \
--net "$NET" \ --net "$NET" \
@ -48,8 +48,8 @@ docker run -d -t --restart=always --name "$NODE2" \
-e EMQX_NODE_COOKIE="$COOKIE" \ -e EMQX_NODE_COOKIE="$COOKIE" \
-e WAIT_FOR_ERLANG=60 \ -e WAIT_FOR_ERLANG=60 \
-p 18084:18083 \ -p 18084:18083 \
-v $PROJ_DIR/_build/emqx/rel/emqx:/built \ -v "$PROJ_DIR"/_build/emqx/rel/emqx:/built \
$IMAGE sh -c 'cp -r /built /emqx && /emqx/bin/emqx console' "$IMAGE" sh -c 'cp -r /built /emqx && /emqx/bin/emqx console'
wait (){ wait (){
container="$1" container="$1"

View File

@ -43,12 +43,14 @@ mkdir -p tmp/
download_zip() { download_zip() {
local app="$1" local app="$1"
local ref="$2" local ref="$2"
local vsn="$(echo "$ref" | tr '/' '-')" local vsn
vsn="$(echo "$ref" | tr '/' '-')"
local file="tmp/${app}-${vsn}.zip" local file="tmp/${app}-${vsn}.zip"
if [ -f "$file" ] && [ "$force" != "force" ]; then if [ -f "$file" ] && [ "$force" != "force" ]; then
return 0 return 0
fi fi
local repo="$(echo "$app" | sed 's#_#-#g')" local repo
repo=${app//_/-}
local url="https://github.com/emqx/$repo/archive/$ref.zip" local url="https://github.com/emqx/$repo/archive/$ref.zip"
echo "downloading ${url}" echo "downloading ${url}"
curl -fLsS -o "$file" "$url" curl -fLsS -o "$file" "$url"
@ -56,7 +58,7 @@ download_zip() {
default_vsn="dev/v4.3.0" default_vsn="dev/v4.3.0"
download_zip "emqx_auth_mnesia" "e4.2.3" download_zip "emqx_auth_mnesia" "e4.2.3"
for app in ${apps[@]}; do for app in "${apps[@]}"; do
download_zip "$app" "$default_vsn" download_zip "$app" "$default_vsn"
done done
@ -64,7 +66,8 @@ extract_zip(){
local app="$1" local app="$1"
local ref="$2" local ref="$2"
local vsn_arg="${3:-}" local vsn_arg="${3:-}"
local vsn_dft="$(echo "$ref" | tr '/' '-')" local vsn_dft
vsn_dft="$(echo "$ref" | tr '/' '-')"
local vsn local vsn
if [ -n "$vsn_arg" ]; then if [ -n "$vsn_arg" ]; then
vsn="$vsn_arg" vsn="$vsn_arg"
@ -72,14 +75,15 @@ extract_zip(){
vsn="$vsn_dft" vsn="$vsn_dft"
fi fi
local file="tmp/${app}-${vsn_dft}.zip" local file="tmp/${app}-${vsn_dft}.zip"
local repo="$(echo "$app" | sed 's#_#-#g')" local repo
repo=${app//_/-}
rm -rf "apps/${app}/" rm -rf "apps/${app}/"
unzip "$file" -d apps/ unzip "$file" -d apps/
mv "apps/${repo}-${vsn}/" "apps/$app/" mv "apps/${repo}-${vsn}/" "apps/$app/"
} }
extract_zip "emqx_auth_mnesia" "e4.2.3" "e4.2.3" extract_zip "emqx_auth_mnesia" "e4.2.3" "e4.2.3"
for app in ${apps[@]}; do for app in "${apps[@]}"; do
extract_zip "$app" "$default_vsn" extract_zip "$app" "$default_vsn"
done done
@ -95,6 +99,6 @@ cleanup_app(){
} }
apps+=( "emqx_auth_mnesia" ) apps+=( "emqx_auth_mnesia" )
for app in ${apps[@]}; do for app in "${apps[@]}"; do
cleanup_app $app cleanup_app "$app"
done done