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;
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";
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 = {
} 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') {
$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;
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) = @_;
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 ({