summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-dockerman/luasrc
diff options
context:
space:
mode:
authorFlorian Eckert <fe@dev.tdt.de>2020-08-03 14:18:19 +0200
committerFlorian Eckert <fe@dev.tdt.de>2020-08-11 12:55:42 +0200
commit04a14ed3700147a6cb2d48c9493f634279e0a1a2 (patch)
tree544845f53d85950d3bd2e4dcb778cca4bec076bf /applications/luci-app-dockerman/luasrc
parent169c136d617638e97cce7fa65c1421d5765a3a89 (diff)
luci-app-dockerman: fix console connection
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
Diffstat (limited to 'applications/luci-app-dockerman/luasrc')
-rw-r--r--applications/luci-app-dockerman/luasrc/model/cbi/dockerman/container.lua26
1 files changed, 18 insertions, 8 deletions
diff --git a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/container.lua b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/container.lua
index 9ea006396..37be23e0d 100644
--- a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/container.lua
+++ b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/container.lua
@@ -704,11 +704,14 @@ elseif action == "console" then
return
end
- local kill_ttyd = 'netstat -lnpt | grep ":7682[ \t].*ttyd$" | awk \'{print $NF}\' | awk -F\'/\' \'{print "kill -9 " $1}\' | sh > /dev/null'
- luci.util.exec(kill_ttyd)
+ local pid = luci.util.trim(luci.util.exec("netstat -lnpt | grep :7682 | grep ttyd | tr -s ' ' | cut -d ' ' -f7 | cut -d'/' -f1"))
+ if pid and pid ~= "" then
+ luci.util.exec("kill -9 " .. pid)
+ end
+
local hosts
- local uci = (require "luci.model.uci").cursor()
- local remote = uci:get_bool("dockerd", "globals", "remote_endpoint")
+ local uci = require "luci.model.uci".cursor()
+ local remote = uci:get_bool("dockerd", "globals", "remote_endpoint") or false
local host = nil
local port = nil
local socket = nil
@@ -717,18 +720,25 @@ elseif action == "console" then
host = uci:get("dockerd", "globals", "remote_host") or nil
port = uci:get("dockerd", "globals", "remote_port") or nil
else
- socket = uci:get("dockerd", "globals", "socket_path") or nil
+ socket = uci:get("dockerd", "globals", "socket_path") or "/var/run/docker.sock"
end
if remote and host and port then
hosts = host .. ':'.. port
- elseif socket_path then
- hosts = socket_path
+ elseif socket then
+ hosts = socket
else
return
end
- local start_cmd = cmd_ttyd .. ' -d 2 --once -p 7682 '.. cmd_docker .. ' -H "'.. hosts ..'" exec -it ' .. (uid and uid ~= "" and (" -u ".. uid .. ' ') or "").. container_id .. ' ' .. cmd .. ' &'
+ if uid and uid ~= "" then
+ uid = "-u " .. uid
+ else
+ uid = ""
+ end
+
+ local start_cmd = string.format('%s -d 2 --once -p 7682 %s -H "unix://%s" exec -it %s %s %s&', cmd_ttyd, cmd_docker, hosts, uid, container_id, cmd)
+
os.execute(start_cmd)
o = s:option(DummyValue, "console")