diff --git a/luasrc/model/cbi/nodered.lua b/luasrc/model/cbi/nodered.lua index 17f80b1..2585ccb 100644 --- a/luasrc/model/cbi/nodered.lua +++ b/luasrc/model/cbi/nodered.lua @@ -9,12 +9,12 @@ local m, s, o m = taskd.docker_map("nodered", "nodered", "/usr/libexec/apps/nodered/nodered.sh", translate("Nodered"), translate("Node-RED is a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways.") - .. translate("Official website:") .. ' https://www.nodered.org/') + .. "
" .. translate("Official website:") .. ' https://www.nodered.org/') -s = m:section(SimpleSection, translate("Service Status"), translate("nodered status:")) +s = m:section(SimpleSection, translate("Service Status")) s:append(Template("nodered/status")) -s = m:section(TypedSection, "nodered", translate("Setup"), translate("Refresh to update settings.")) +s = m:section(TypedSection, "nodered", translate("Setup"), translate("The following parameters will only take effect during installation or upgrade:")) s.addremove=false s.anonymous=true diff --git a/luasrc/view/nodered/status.htm b/luasrc/view/nodered/status.htm index f6a8355..d29563c 100644 --- a/luasrc/view/nodered/status.htm +++ b/luasrc/view/nodered/status.htm @@ -1,31 +1,22 @@ <% local util = require "luci.util" local container_status = util.trim(util.exec("/usr/libexec/apps/nodered/nodered.sh status")) -local container_running = string.find(string.lower(container_status), "up") and string.find(string.lower(container_status), "(healthy)") +local container_running = string.match(string.lower(container_status), "^up%W") +local port=util.trim(util.exec("/usr/libexec/apps/nodered/nodered.sh port")) -%>
-
<% if container_running then %> + <% + if port == "" then + port="1880" + end + -%> + <% else %> <% end %>
- -<% -if container_running then - local port=util.trim(util.exec("/usr/libexec/apps/nodered/nodered.sh port")) - if port == "" then - port="1880" - end --%> -
- -
- -
-
-<% end %> diff --git a/root/usr/libexec/apps/nodered/nodered.sh b/root/usr/libexec/apps/nodered/nodered.sh old mode 100644 new mode 100755 index cb0eafd..5a66e29 --- a/root/usr/libexec/apps/nodered/nodered.sh +++ b/root/usr/libexec/apps/nodered/nodered.sh @@ -87,16 +87,31 @@ case "${ACTION}" in ;; "start" | "stop" | "restart") APP_NAME="node-red" - CONTAINER_IDS=$(docker ps -a --filter "ancestor=${APP_NAME}" --format '{{.ID}}') + CONTAINER_IDS=$(docker ps -a | grep "$APP_NAME" | awk '{print $1}') + + # Echo action message + if [ "$ACTION" == "start" ]; then + echo "Starting $APP_NAME container(s)" + elif [ "$ACTION" == "stop" ]; then + echo "Stopping $APP_NAME container(s)" + elif [ "$ACTION" == "restart" ]; then + echo "Restarting $APP_NAME container(s)" + fi + for ID in $CONTAINER_IDS; do docker "${ACTION}" "${ID}" done ;; "status") - APP_NAME="node-red" - CONTAINER_NAMES=$(docker ps -a --filter "name=${APP_NAME}" --format '{{.Names}}') - docker ps --all -f "name=${CONTAINER_NAMES}" --format '{{.Status}}' - ;; + APP_NAME="node-red" + CONTAINER_NAME=$(docker ps -a --filter "name=${APP_NAME}" --format '{{.Names}}') + CONTAINER_STATUS=$(docker ps --all --filter "name=${CONTAINER_NAME}" --format '{{.Status}}' | awk '/^Up/ { print "up " substr($0, 4) } !/^Up/ && /.+/ { print "down" }') + if [ -z "$CONTAINER_NAME" ]; then + echo "${APP_NAME} is not installed" + else + echo "${CONTAINER_STATUS}" + fi + ;; "port") APP_NAME="node-red" CONTAINER_NAMES=$(docker ps -a --filter "ancestor=${APP_NAME}" --format '{{.Names}}')