From fa4dc6be91ad86dbaa0959b40bdb14f50ad21a67 Mon Sep 17 00:00:00 2001 From: Dirk Brenken Date: Sun, 20 May 2018 19:23:53 +0200 Subject: [PATCH] luci-app-lxc: fix "plain-vanilla" integration I've tried to get the lxc app in a more usable state. Tested with mips and amd64 targets. * fix missing tar/xz dependency, only if LXC_BUSYBOX_OPTIONS is not selected * mute needless gpg validation warning * tidy up controller a little bit * fix multiple possible dispatcher errors * fix compatibility with XHTML standard theme (looks still horrible ;-) * inform the user about custom kernel prerequisites * inform the user about the template download * inform the user if no template was found Signed-off-by: Dirk Brenken --- applications/luci-app-lxc/Makefile | 2 +- .../luci-app-lxc/luasrc/controller/lxc.lua | 28 ++-- .../luci-app-lxc/luasrc/model/cbi/lxc.lua | 4 +- applications/luci-app-lxc/luasrc/view/lxc.htm | 122 +++++++++++++----- 4 files changed, 105 insertions(+), 51 deletions(-) diff --git a/applications/luci-app-lxc/Makefile b/applications/luci-app-lxc/Makefile index 85cae5c40..379cccbfc 100644 --- a/applications/luci-app-lxc/Makefile +++ b/applications/luci-app-lxc/Makefile @@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk LUCI_TITLE:=LXC management Web UI -LUCI_DEPENDS:=+luci-mod-admin-full +lxc +lxc-attach +lxc-console +lxc-create +liblxc +rpcd-mod-lxc +getopt +LUCI_DEPENDS:=+luci-mod-admin-full +lxc +lxc-attach +lxc-console +lxc-create +liblxc +rpcd-mod-lxc +getopt +!LXC_BUSYBOX_OPTIONS:tar LUCI_PKGARCH:=all PKG_MAINTAINER:=Petar Koretic diff --git a/applications/luci-app-lxc/luasrc/controller/lxc.lua b/applications/luci-app-lxc/luasrc/controller/lxc.lua index cc490f0b8..e15915df5 100644 --- a/applications/luci-app-lxc/luasrc/controller/lxc.lua +++ b/applications/luci-app-lxc/luasrc/controller/lxc.lua @@ -14,33 +14,33 @@ Author: Petar Koretic ]]-- -local uci = require "luci.model.uci" +local uci = require "luci.model.uci".cursor() local util = require "luci.util" -local nixio = require "nixio" +local fs = require "nixio" module("luci.controller.lxc", package.seeall) function fork_exec(command) - local pid = nixio.fork() + local pid = fs.fork() if pid > 0 then return elseif pid == 0 then -- change to root dir - nixio.chdir("/") + fs.chdir("/") -- patch stdin, out, err to /dev/null - local null = nixio.open("/dev/null", "w+") + local null = fs.open("/dev/null", "w+") if null then - nixio.dup(null, nixio.stderr) - nixio.dup(null, nixio.stdout) - nixio.dup(null, nixio.stdin) + fs.dup(null, fs.stderr) + fs.dup(null, fs.stdout) + fs.dup(null, fs.stdin) if null:fileno() > 2 then null:close() end end -- replace with target command - nixio.exec("/bin/sh", "-c", command) + fs.exec("/bin/sh", "-c", command) end end @@ -71,9 +71,8 @@ function lxc_get_downloadable() local target = lxc_get_arch_target() local templates = {} - local f = io.popen('sh /usr/share/lxc/templates/lxc-download --list --no-validate --server %s' - % util.shellquote(uci.cursor():get("lxc", "lxc", "url")), 'r') - + local f = io.popen('sh /usr/share/lxc/templates/lxc-download --list --no-validate --server %s 2>/dev/null' + % util.shellquote(uci:get("lxc", "lxc", "url")), 'r') local line for line in f:lines() do local dist, version, dist_target = line:match("^(%S+)%s+(%S+)%s+(%S+)%s+default%s+%S+$") @@ -101,7 +100,7 @@ function lxc_create(lxc_name, lxc_template) name = lxc_name, template = "download", args = { - "--server", uci.cursor():get("lxc", "lxc", "url"), + "--server", uci:get("lxc", "lxc", "url"), "--no-validate", "--dist", lxc_dist, "--release", lxc_release, @@ -121,6 +120,7 @@ function lxc_get_config_path() local f = io.open("/etc/lxc/lxc.conf", "r") local content = f:read("*all") f:close() + local ret = content:match('^%s*lxc.lxcpath%s*=%s*([^%s]*)') if ret then return ret .. "/" @@ -160,7 +160,7 @@ function lxc_configuration_set(lxc_name) end function lxc_get_arch_target() - local target = nixio.uname().machine + local target = fs.uname().machine local target_map = { armv5 = "armel", armv6 = "armel", diff --git a/applications/luci-app-lxc/luasrc/model/cbi/lxc.lua b/applications/luci-app-lxc/luasrc/model/cbi/lxc.lua index ac0fdff33..7040f0ecf 100644 --- a/applications/luci-app-lxc/luasrc/model/cbi/lxc.lua +++ b/applications/luci-app-lxc/luasrc/model/cbi/lxc.lua @@ -16,7 +16,9 @@ Author: Petar Koretic local fs = require "nixio.fs" -m = Map("lxc", translate("LXC Containers")) +m = Map("lxc", translate("LXC Containers"), + translate("Please note: For LXC Containers you need a custom OpenWrt image.
") + .. translate("The image should include at least support for 'kernel cgroups', 'kernel namespaces' and 'miscellaneous LXC related options'.")) if fs.access("/etc/config/lxc") then m:section(SimpleSection).template = "lxc" diff --git a/applications/luci-app-lxc/luasrc/view/lxc.htm b/applications/luci-app-lxc/luasrc/view/lxc.htm index edfff8e06..c1b44f867 100644 --- a/applications/luci-app-lxc/luasrc/view/lxc.htm +++ b/applications/luci-app-lxc/luasrc/view/lxc.htm @@ -14,6 +14,32 @@ Author: Petar Koretic -%> +<% +local fs = require "nixio" +local target = fs.uname().machine +%> + + +
<%:Available Containers%>
@@ -43,7 +69,7 @@ Author: Petar Koretic - +