From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id AF9496076F for ; Wed, 9 Sep 2020 21:12:31 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A7E0714078 for ; Wed, 9 Sep 2020 21:12:31 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 0333E1406D for ; Wed, 9 Sep 2020 21:12:30 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id C2ABA433C3 for ; Wed, 9 Sep 2020 21:12:29 +0200 (CEST) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Date: Wed, 9 Sep 2020 21:12:20 +0200 Message-Id: <20200909191223.4187564-2-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200909191223.4187564-1-t.lamprecht@proxmox.com> References: <20200909191223.4187564-1-t.lamprecht@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.185 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [lxc.pm, config.pm, status.pm] Subject: [pve-devel] applied: [PATCH container 2/5] implement debug start X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Sep 2020 19:12:31 -0000 Signed-off-by: Thomas Lamprecht --- src/Makefile | 6 ++++-- src/PVE/API2/LXC/Status.pm | 8 +++++++- src/PVE/LXC.pm | 10 +++++++--- src/PVE/LXC/Config.pm | 6 ++++++ src/pve-container-debug@.service | 22 ++++++++++++++++++++++ 5 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 src/pve-container-debug@.service diff --git a/src/Makefile b/src/Makefile index 7166708..450a8eb 100644 --- a/src/Makefile +++ b/src/Makefile @@ -38,8 +38,9 @@ check: test make -C test .PHONY: install -install: pct lxc-pve.conf lxc-pve-prestart-hook lxc-pve-autodev-hook lxc-pve-poststop-hook \ - lxcnetaddbr pct.1 pct.conf.5 pct.bash-completion pct.zsh-completion pve-userns.seccomp +install: pct lxc-pve.conf pct.1 pct.conf.5 pct.bash-completion pct.zsh-completion \ + pve-userns.seccomp pve-container@.service pve-container-debug@.service \ + lxc-pve-prestart-hook lxc-pve-autodev-hook lxc-pve-poststop-hook lxcnetaddbr PVE_GENERATING_DOCS=1 perl -I. -T -e "use PVE::CLI::pct; PVE::CLI::pct->verify_api();" install -d ${SBINDIR} install -m 0755 pct ${SBINDIR} @@ -48,6 +49,7 @@ install: pct lxc-pve.conf lxc-pve-prestart-hook lxc-pve-autodev-hook lxc-pve-pos install -m 0755 pve-container-stop-wrapper ${LXC_SCRIPT_DIR} install -d -m0755 ${SERVICEDIR} install -m0644 pve-container@.service ${SERVICEDIR}/ + install -m0644 pve-container-debug@.service ${SERVICEDIR}/ install -m0644 'system-pve\x2dcontainer.slice' ${SERVICEDIR}/ install -d ${LXC_HOOK_DIR} install -m 0755 lxc-pve-prestart-hook ${LXC_HOOK_DIR} diff --git a/src/PVE/API2/LXC/Status.pm b/src/PVE/API2/LXC/Status.pm index 89186ae..766c2ce 100644 --- a/src/PVE/API2/LXC/Status.pm +++ b/src/PVE/API2/LXC/Status.pm @@ -130,6 +130,12 @@ __PACKAGE__->register_method({ node => get_standard_option('pve-node'), vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid_stopped }), skiplock => get_standard_option('skiplock'), + debug => { + optional => 1, + type => 'boolean', + description => "If set, enables very verbose debug log-level on start.", + default => 0, + }, }, }, returns => { @@ -188,7 +194,7 @@ __PACKAGE__->register_method({ }); } - PVE::LXC::vm_start($vmid, $conf, $skiplock); + PVE::LXC::vm_start($vmid, $conf, $skiplock, $param->{debug}); }; my $lockcmd = sub { diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index f9aaaa9..b3e3581 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -2218,7 +2218,7 @@ my sub monitor_start($$) { } sub vm_start { - my ($vmid, $conf, $skiplock) = @_; + my ($vmid, $conf, $skiplock, $debug) = @_; # apply pending changes while starting if (scalar(keys %{$conf->{pending}})) { @@ -2247,15 +2247,19 @@ sub vm_start { unlink "/run/pve/ct-$vmid.stderr"; # systemd does not truncate log files - my $base_unit = $conf->{debug} ? 'pve-container-debug' : 'pve-container'; + my $is_debug = $debug || (!defined($debug) && $conf->{debug}); + my $base_unit = $is_debug ? 'pve-container-debug' : 'pve-container'; - my $cmd = ['systemctl', 'start', "pve-container\@$vmid"]; + my $cmd = ['systemctl', 'start', "$base_unit\@$vmid"]; PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'pre-start', 1); eval { PVE::Tools::run_command($cmd); monitor_start($monitor_socket, $vmid) if defined($monitor_socket); + + # if debug is requested, print the log it also when the start succeeded + print_ct_stderr_log($vmid) if $is_debug; }; if (my $err = $@) { unlink $skiplock_flag_fn; diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm index 044e2e1..4cd669c 100644 --- a/src/PVE/LXC/Config.pm +++ b/src/PVE/LXC/Config.pm @@ -508,6 +508,12 @@ my $confdesc = { description => 'Tags of the Container. This is only meta information.', optional => 1, }, + debug => { + optional => 1, + type => 'boolean', + description => "Try to be more verbose. For now this only enables debug log-level on start.", + default => 0, + }, }; my $valid_lxc_conf_keys = { diff --git a/src/pve-container-debug@.service b/src/pve-container-debug@.service new file mode 100644 index 0000000..7cfebaa --- /dev/null +++ b/src/pve-container-debug@.service @@ -0,0 +1,22 @@ +# based on lxc@.service, but without an install section because +# starting and stopping should be initiated by PVE code, not +# systemd. +[Unit] +Description=PVE LXC Container: %i +DefaultDependencies=No +After=lxc.service +Wants=lxc.service +Documentation=man:lxc-start man:lxc man:pct + +[Service] +Type=simple +Delegate=yes +KillMode=mixed +TimeoutStopSec=120s +ExecStart=/usr/bin/lxc-start -F -n %i -o /dev/stderr -l DEBUG +ExecStop=/usr/share/lxc/pve-container-stop-wrapper %i +# Environment=BOOTUP=serial +# Environment=CONSOLETYPE=serial +# Prevent container init from putting all its output into the journal +StandardOutput=null +StandardError=file:/run/pve/ct-%i.stderr -- 2.20.1