]> git.proxmox.com Git - pve-container.git/commitdiff
implement new cmode option
authorDietmar Maurer <dietmar@proxmox.com>
Sat, 15 Aug 2015 07:56:37 +0000 (09:56 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Sat, 15 Aug 2015 07:56:37 +0000 (09:56 +0200)
So that the user can choose to use /dev/ttyX or /dev/console or /bin/sh.

src/PVE/API2/LXC.pm
src/PVE/LXC.pm
src/pct

index 2af8e4d6d3b21565786ea375ce2bc744cdd8df9f..7eb0afb1d7a4e75b11cfe53d874b594fd6f2466a 100644 (file)
@@ -732,10 +732,12 @@ __PACKAGE__->register_method ({
        my $remcmd = $remip ?
            ['/usr/bin/ssh', '-t', $remip] : [];
 
+       my $conf = PVE::LXC::load_config($vmid);
+       my $concmd = PVE::LXC::get_console_command($vmid, $conf);
+
        my $shcmd = [ '/usr/bin/dtach', '-A',
                      "/var/run/dtach/vzctlconsole$vmid",
-                     '-r', 'winch', '-z',
-                     'lxc-console', '-n', $vmid ];
+                     '-r', 'winch', '-z', @$concmd];
 
        my $realcmd = sub {
            my $upid = shift;
@@ -851,10 +853,12 @@ __PACKAGE__->register_method ({
        my $authpath = "/vms/$vmid";
        my $permissions = 'VM.Console';
 
+       my $conf = PVE::LXC::load_config($vmid);
+       my $concmd = PVE::LXC::get_console_command($vmid, $conf);
+
        my $shcmd = ['/usr/bin/dtach', '-A',
                     "/var/run/dtach/vzctlconsole$vmid",
-                    '-r', 'winch', '-z',
-                    'lxc-console', '-n', $vmid];
+                    '-r', 'winch', '-z', @$concmd];
 
        my $title = "CT $vmid";
 
index da87aaa27153390a2c2348973b02da35b186a8e7..a71a7e1092109cfbd8e7c597f465e34035726bf6 100644 (file)
@@ -161,6 +161,13 @@ my $confdesc = {
        type => 'integer',
        minimum => 0,
     },
+    cmode => {
+       optional => 1,
+       description => "Console mode. By default, the console command tries to open a connection to one of the available tty devices. By setting cmode to 'console' it tries to attach to /dev/console instead. If you set cmode to 'shell', it simply invokes a shell inside the container (no login).",
+       type => 'string',
+       enum => ['shell', 'console', 'tty'],
+       default => 'tty',
+    },
 };
 
 my $valid_lxc_conf_keys = {
@@ -1082,7 +1089,8 @@ sub update_pct_config {
            } elsif ($opt eq 'swap') {
                delete $conf->{$opt};
                write_cgroup_value("memory", $vmid, "memory.memsw.limit_in_bytes", -1);
-           } elsif ($opt eq 'description' || $opt eq 'onboot' || $opt eq 'startup') {
+           } elsif ($opt eq 'description' || $opt eq 'onboot' || $opt eq 'startup' ||
+                    $opt eq 'cmode') {
                delete $conf->{$opt};
            } elsif ($opt eq 'nameserver' || $opt eq 'searchdomain' ||
                     $opt eq 'tty' || $opt eq 'console') {
@@ -1129,6 +1137,8 @@ sub update_pct_config {
            $conf->{$opt} = $value ? 1 : 0;
        } elsif ($opt eq 'startup') {
            $conf->{$opt} = $value;
+       } elsif ($opt eq 'cmode') {
+           $conf->{$opt} = $value;
        } elsif ($opt eq 'tty' || $opt eq 'console') {
            $conf->{$opt} = $value;
            push @nohotplug, $opt;
@@ -1183,6 +1193,28 @@ sub get_tty_count {
     return $conf->{tty} // $confdesc->{tty}->{default};
 }
 
+sub get_cmode {
+    my ($conf) = @_;
+
+    return $conf->{cmode} // $confdesc->{cmode}->{default};
+}
+
+sub get_console_command {
+    my ($vmid, $conf) = @_;
+
+    my $cmode = get_cmode($conf);
+
+    if ($cmode eq 'console') {
+       return ['lxc-console', '-n',  $vmid, '-t', 0];
+    } elsif ($cmode eq 'tty') {
+       return ['lxc-console', '-n',  $vmid];
+    } elsif ($cmode eq 'shell') {
+       return ['lxc-attach', '--clear-env', '-n', $vmid];
+    } else {
+       die "internal error";
+    }
+}
+
 sub get_primary_ips {
     my ($conf) = @_;
 
diff --git a/src/pct b/src/pct
index a5af4e33c9523cc1d95e6c5e9802c1843556fb83..1d67efd84f55f4717a3564056a8cf816bbda753d 100755 (executable)
--- a/src/pct
+++ b/src/pct
@@ -55,9 +55,10 @@ __PACKAGE__->register_method ({
        my ($param) = @_;
 
        # test if container exists on this node
-       PVE::LXC::load_config($param->{vmid});
+       my $conf = PVE::LXC::load_config($param->{vmid});
 
-       exec('lxc-console', '-n',  $param->{vmid});
+       my $cmd = PVE::LXC::get_console_command($param->{vmid}, $conf);
+       exec(@$cmd);
     }});
 
 __PACKAGE__->register_method ({