diff --git a/README.md b/README.md index ccfc105..787887e 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,12 @@ Listen to UDP 10101 for beacon messages broadcast by your SDL Manager. nc -u -l -k 10101 |jq ``` +Or to get the install command from the beacon message: + +``` +nc -u -l -k 10101 | jq -r '.msg.sdl_wkr_install_cmd[]' +``` + > NOTE: CTRL-C to exit `nc`. You cannot run `nc` on port 10101 in parallel with the sdl-wkr. So run it once to get the install command. Tnen install sdl-wkr. Run the **curl** or **wget** command provided by SDL Manager UDP beacon to install SDL Worker locally. diff --git a/sdl-mgr/app/modules/sdl-mgr/index.js b/sdl-mgr/app/modules/sdl-mgr/index.js index de10346..b2e9338 100644 --- a/sdl-mgr/app/modules/sdl-mgr/index.js +++ b/sdl-mgr/app/modules/sdl-mgr/index.js @@ -352,6 +352,7 @@ function publishStatus(client, topic) { //get ip addr const interfaces = os.networkInterfaces(); let ip_addr = null; + let web_port = config.modules.web.port; for (const [iface, addrs] of Object.entries(interfaces)) { for (const addr of addrs) { @@ -385,7 +386,7 @@ function publishStatus(client, topic) { sdl: { version: config.package.version, uptime: getUptimeDHMS(), - update_cmd: `curl -s http://${ip_addr}:${config.modules.web.port}/dist/install-sdl-wkr.sh | bash -s ${ip_addr}` + update_cmd: `curl -s http://${ip_addr}:${config.modules.web.port}/dist/install-sdl-wkr.sh | bash -s ${ip_addr}:${web_port}`, }, cluster: config.cluster, resources: updatedState.meta.stats.resources, // ✅ Add cluster resources @@ -591,8 +592,8 @@ function startUdpBeacon() { web_ui_url: `http://${addr.address}:${config.modules.web.port}`, }, sdl_wkr_install_cmd: { - curl: `curl -s http://${addr.address}:${config.modules.web.port}/dist/install-sdl-wkr.sh | bash -s ${addr.address}`, - wget: `wget -O - http://${addr.address}:${config.modules.web.port}/dist/install-sdl-wkr.sh | bash -s ${addr.address}` + curl: `curl -s http://${addr.address}:${config.modules.web.port}/dist/install-sdl-wkr.sh | bash -s ${addr.address}:${config.modules.web.port}`, + wget: `wget -O - http://${addr.address}:${config.modules.web.port}/dist/install-sdl-wkr.sh | bash -s ${addr.address}:${config.modules.web.port}`, } } }; diff --git a/sdl-wkr/scripts/install-sdl-wkr.sh b/sdl-wkr/scripts/install-sdl-wkr.sh index 0fd833d..f31bdf6 100644 --- a/sdl-wkr/scripts/install-sdl-wkr.sh +++ b/sdl-wkr/scripts/install-sdl-wkr.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # install-sdl-wkr.sh - Script to install SDL Worker -# Usage: curl -s http://:8081/dist/install-sdl-wkr.sh | bash -s +# Usage: curl -s http://:/dist/install-sdl-wkr.sh | bash -s : set -euo pipefail # ------------------------------------------------------------ @@ -79,11 +79,11 @@ install_nodejs() { esac - NODE_VER=$(curl -s http://${SDL_MGR_IP}:8081/api/config | jq -r '.nodejs.version') + NODE_VER=$(curl -s http://${SDL_MGR_IP}:${SDL_MGR_PORT}/api/config | jq -r '.nodejs.version') NODE_DIR="${SDL_HOME}/nodejs" NODE_VER_BASE="node-${NODE_VER}-${OS_PLATFORM}-${OS_ARCH}" NODE_FILE="node-${NODE_VER}-${OS_PLATFORM}-${OS_ARCH}.${EXT}" - NODE_URL="http://${SDL_MGR_IP}:8081/dist/${NODE_FILE}" + NODE_URL="http://${SDL_MGR_IP}:${SDL_MGR_PORT}/dist/${NODE_FILE}" #echo "NodeJS Version: ${NODE_VER}" @@ -138,16 +138,18 @@ if [ -z "$1" ]; then exit 1 fi -SDL_MGR_IP=$1 +ARG1=$1 # SDL_MGR_IP:PORT +SDL_MGR_IP=$(echo "$ARG1" | cut -d ':' -f 1) +SDL_MGR_PORT=$(echo "$ARG1" | cut -d ':' -f 2) -# SDL_HOME=$(curl -s http://${SDL_MGR_IP}:8081/api/config | jq -r '.dirs.sdlhome') +# SDL_HOME=$(curl -s http://${SDL_MGR_IP}:${SDL_MGR_PORT}/api/config | jq -r '.dirs.sdlhome') SDL_HOME=$HOME/.sdl -SDL_VER=$(curl -s http://${SDL_MGR_IP}:8081/api/config | jq -r '.package.version') -SDL_DESC=$(curl -s http://${SDL_MGR_IP}:8081/api/config | jq -r '.package.description') -# SDL_ABBR=$(curl -s http://${SDL_MGR_IP}:8081/api/config | jq -r '.package.abbr') -SDL_COPYRT=$(curl -s http://${SDL_MGR_IP}:8081/api/config | jq -r '.package.copyright') +SDL_VER=$(curl -s http://${SDL_MGR_IP}:${SDL_MGR_PORT}/api/config | jq -r '.package.version') +SDL_DESC=$(curl -s http://${SDL_MGR_IP}:${SDL_MGR_PORT}/api/config | jq -r '.package.description') +# SDL_ABBR=$(curl -s http://${SDL_MGR_IP}:${SDL_MGR_PORT}/api/config | jq -r '.package.abbr') +SDL_COPYRT=$(curl -s http://${SDL_MGR_IP}:${SDL_MGR_PORT}/api/config | jq -r '.package.copyright') echo "###############################################" # echo "${SDL_DESC} (${SDL_ABBR})" @@ -160,7 +162,7 @@ echo "" TMP_DIR="${SDL_HOME}/tmp" SDL_WKR_DIR="${SDL_HOME}/sdl-wkr" -SDL_WKR_VERSION=$(curl -s http://${SDL_MGR_IP}:8081/api/config | jq -r '.package.version') +SDL_WKR_VERSION=$(curl -s http://${SDL_MGR_IP}:${SDL_MGR_PORT}/api/config | jq -r '.package.version') SDL_WKR_TGZ="sdl-wkr_${SDL_WKR_VERSION}.tgz" SDL_CONF_DIR="${SDL_HOME}/conf" SLD_LOGS_DIR="${SDL_HOME}/logs" @@ -177,8 +179,8 @@ mkdir -p "${TMP_DIR}" # Download the latest sdl-wkr version to TMP_DIR -WKR_TGZ_URL="http://${SDL_MGR_IP}:8081/dist/${SDL_WKR_TGZ}" -WKR_TGZ_SHA256_URL="http://${SDL_MGR_IP}:8081/dist/${SDL_WKR_TGZ}.sha256" +WKR_TGZ_URL="http://${SDL_MGR_IP}:${SDL_MGR_PORT}/dist/${SDL_WKR_TGZ}" +WKR_TGZ_SHA256_URL="http://${SDL_MGR_IP}:${SDL_MGR_PORT}/dist/${SDL_WKR_TGZ}.sha256" curl -sSL --fail "${WKR_TGZ_URL}" -o "${TMP_DIR}/${SDL_WKR_TGZ}" || { echo "Failed to download sdl-wkr"; exit 1; } curl -sSL --fail "${WKR_TGZ_SHA256_URL}" -o "${TMP_DIR}/${SDL_WKR_TGZ}.sha256" || { echo "Failed to download sdl-wkr SHA256"; exit 1; } @@ -214,7 +216,7 @@ cp "$SDL_WKR_DIR/current/scripts/sdl-wkr.service" ~/.config/systemd/user/ # Install Node.js idempotently -NODE_VER=$(curl -s http://${SDL_MGR_IP}:8081/api/config | jq -r '.nodejs.version') +NODE_VER=$(curl -s http://${SDL_MGR_IP}:${SDL_MGR_PORT}/api/config | jq -r '.nodejs.version') NODE_DIR="${SDL_HOME}/nodejs" NODE_BIN="${NODE_DIR}/current/bin/node" NPM_BIN="${NODE_DIR}/current/bin/npm"