luci-app-dockerman: fix console connection
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
This commit is contained in:
parent
169c136d61
commit
04a14ed370
1 changed files with 18 additions and 8 deletions
|
@ -704,11 +704,14 @@ elseif action == "console" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local kill_ttyd = 'netstat -lnpt | grep ":7682[ \t].*ttyd$" | awk \'{print $NF}\' | awk -F\'/\' \'{print "kill -9 " $1}\' | sh > /dev/null'
|
local pid = luci.util.trim(luci.util.exec("netstat -lnpt | grep :7682 | grep ttyd | tr -s ' ' | cut -d ' ' -f7 | cut -d'/' -f1"))
|
||||||
luci.util.exec(kill_ttyd)
|
if pid and pid ~= "" then
|
||||||
|
luci.util.exec("kill -9 " .. pid)
|
||||||
|
end
|
||||||
|
|
||||||
local hosts
|
local hosts
|
||||||
local uci = (require "luci.model.uci").cursor()
|
local uci = require "luci.model.uci".cursor()
|
||||||
local remote = uci:get_bool("dockerd", "globals", "remote_endpoint")
|
local remote = uci:get_bool("dockerd", "globals", "remote_endpoint") or false
|
||||||
local host = nil
|
local host = nil
|
||||||
local port = nil
|
local port = nil
|
||||||
local socket = nil
|
local socket = nil
|
||||||
|
@ -717,18 +720,25 @@ elseif action == "console" then
|
||||||
host = uci:get("dockerd", "globals", "remote_host") or nil
|
host = uci:get("dockerd", "globals", "remote_host") or nil
|
||||||
port = uci:get("dockerd", "globals", "remote_port") or nil
|
port = uci:get("dockerd", "globals", "remote_port") or nil
|
||||||
else
|
else
|
||||||
socket = uci:get("dockerd", "globals", "socket_path") or nil
|
socket = uci:get("dockerd", "globals", "socket_path") or "/var/run/docker.sock"
|
||||||
end
|
end
|
||||||
|
|
||||||
if remote and host and port then
|
if remote and host and port then
|
||||||
hosts = host .. ':'.. port
|
hosts = host .. ':'.. port
|
||||||
elseif socket_path then
|
elseif socket then
|
||||||
hosts = socket_path
|
hosts = socket
|
||||||
else
|
else
|
||||||
return
|
return
|
||||||
end
|
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)
|
os.execute(start_cmd)
|
||||||
|
|
||||||
o = s:option(DummyValue, "console")
|
o = s:option(DummyValue, "console")
|
||||||
|
|
Loading…
Reference in a new issue