]> git.proxmox.com Git - pve-container.git/commitdiff
implement debug start
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 9 Sep 2020 16:10:43 +0000 (18:10 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 9 Sep 2020 18:54:57 +0000 (20:54 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/Makefile
src/PVE/API2/LXC/Status.pm
src/PVE/LXC.pm
src/PVE/LXC/Config.pm
src/pve-container-debug@.service [new file with mode: 0644]

index 71667088b2eed9cc6ee2bb89074f50d0e873c70a..450a8ebe8ae819511782caabd4a36e49098be9e8 100644 (file)
@@ -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}
index 89186ae54610070687ac881d84655c659ab351e2..766c2cef53920ea1fe35b3742a2767e415d77098 100644 (file)
@@ -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 {
index f9aaaa915081118ba91d7603219fb342b6901aa3..b3e35815e19cdf3a98a6e1e0528e333f8f772f2f 100644 (file)
@@ -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;
index 044e2e196f9a575b9e4e5d5ae539c95b2bf39dc8..4cd669cf7c5831d95d0a58b4035c6897236c32b2 100644 (file)
@@ -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 (file)
index 0000000..7cfebaa
--- /dev/null
@@ -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