lxc与host的coredump配置

core dump configuration for host and lxc container
a, put this file in host's filesystem: /usr/bin/
        /usr/bin/corecompress.sh:

        #!/bin/bash

        set -o noclobber

        LXC=$(echo $1 | cut -d '_' -f2)

        if [ ! -d /var/log/$LXC/dump ]; then
                mkdir -p /var/log/$LXC/dump
        fi


        if [ -s $1 ]; then
                cat > /dev/null
        else
                gzip -c > /var/log/$LXC/dump/$1
        fi
b, configure core_pattern in host's terminal(two method as below) 

       1) echo "|/usr/bin/corecompress.sh core_%h_%e_%p.gz" > /proc/sys/kernel/core_pattern   #temporary

       2) vi /etc/sysctl.conf, then add the line: kernel.core_pattern = |/usr/bin/corecompress.sh core_%h_%e_%p.gz  #permanent 

c, mount "/var/log" for each lxc container
      lxc.mount.entry=/var/log/lxc_name /usr/local/var/lib/lxc/lxc_name/rootfs/var/log none rw,bind 0 0   lxc_name is the lxc name, which is set in "lxc.utsname = lxc_name"

d, 1> when coredump happened on lxc container lxc_name, we can see the coredump file both on host and lxc container
      1) on host: /var/log/lxc_name/dump/core_xx_xx_xx.gz
      2) on lxc container: /var/log/dump/core_xx_xx_xx.gz
    2> when coredump happened on host, we can see the coredump file in the path of host: "/var/log/host_name/dump/core_xx_xx_xx.gz"

lxc与host的coredump配置

lxc与host的coredump配置