mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-03 19:41:49 +00:00
lxc-start-ephemeral: Fix console() and add storage option
The introduction of the new console() python API broke lxc-start-ephemeral's console(tty=1) call, I now changed that to console() which does the right thing with both API versions. This also adds a new storage-type option, letting the user choose to use a standard directory instead of tmpfs for the container (but still have it ephemeral). Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
This commit is contained in:
parent
39ffde307a
commit
b58e60e232
@ -85,13 +85,17 @@ parser.add_argument("--key", "-S", type=str,
|
||||
parser.add_argument("--daemon", "-d", action="store_true",
|
||||
help=_("run in the background"))
|
||||
|
||||
parser.add_argument("--storage-type", "-s", type=str, default=None,
|
||||
choices=("tmpfs", "dir"),
|
||||
help=("type of storage use by the container"))
|
||||
|
||||
parser.add_argument("--union-type", "-U", type=str, default="overlayfs",
|
||||
choices=("overlayfs", "aufs"),
|
||||
help=_("type of union (overlayfs or aufs), "
|
||||
"defaults to overlayfs."))
|
||||
|
||||
parser.add_argument("--keep-data", "-k", action="store_true",
|
||||
help=_("Use a persistent backend instead of tmpfs."))
|
||||
help=_("don't wipe everything clean at the end"))
|
||||
|
||||
parser.add_argument("command", metavar='CMD', type=str, nargs="*",
|
||||
help=_("Run specific command in container "
|
||||
@ -104,6 +108,16 @@ args = parser.parse_args()
|
||||
if args.command and args.daemon:
|
||||
parser.error(_("You can't use -d and a command at the same time."))
|
||||
|
||||
## Check that -k isn't used with -s tmpfs
|
||||
if not args.storage_type:
|
||||
if args.keep_data:
|
||||
args.storage_type = "dir"
|
||||
else:
|
||||
args.storage_type = "tmpfs"
|
||||
|
||||
if args.keep_data and args.storage_type == "tmpfs":
|
||||
parser.error(_("You can't use -k with the tmpfs storage type."))
|
||||
|
||||
## The user needs to be uid 0
|
||||
if not os.geteuid() == 0:
|
||||
parser.error(_("You must be root to run this script. Try running: sudo %s"
|
||||
@ -190,7 +204,7 @@ LXC_NAME="%s"
|
||||
target = "%s/delta%s" % (dest_path, count)
|
||||
fd.write("mkdir -p %s %s\n" % (target, entry[1]))
|
||||
|
||||
if not args.keep_data:
|
||||
if args.storage_type == "tmpfs":
|
||||
fd.write("mount -n -t tmpfs none %s\n" % (target))
|
||||
|
||||
if args.union_type == "overlayfs":
|
||||
@ -254,7 +268,7 @@ if not dest.start() or not dest.wait("RUNNING", timeout=5):
|
||||
|
||||
# Deal with the case where we just attach to the container's console
|
||||
if not args.command and not args.daemon:
|
||||
dest.console(tty=1)
|
||||
dest.console()
|
||||
dest.shutdown(timeout=5)
|
||||
sys.exit(0)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user