├── debian ├── compat ├── copyright ├── ceph-kdump-copy.substvars ├── ceph-kdump-copy.install ├── changelog ├── control ├── ceph-kdump-copy.default ├── rules └── ceph-kdump-copy.init └── ceph-kdump-copy /debian/compat: -------------------------------------------------------------------------------- 1 | 6 2 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | MIT 2 | -------------------------------------------------------------------------------- /debian/ceph-kdump-copy.substvars: -------------------------------------------------------------------------------- 1 | misc:Depends= 2 | -------------------------------------------------------------------------------- /debian/ceph-kdump-copy.install: -------------------------------------------------------------------------------- 1 | usr/bin/ceph-kdump-copy 2 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | ceph-kdump-copy (0.1-1) UNRELEASED; urgency=low 2 | 3 | * Initial release. (Closes: #XXXXXX) 4 | 5 | -- Sage Weil Mon, 11 Jun 2012 16:09:04 -0700 6 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: ceph-kdump-copy 2 | Section: admin 3 | Priority: optional 4 | Homepage: http://ceph.newdream.net/ 5 | Vcs-Git: git://github.com/ceph/ceph-kdump-copy.git 6 | Vcs-Browser: https://github.com/ceph/ceph-kdump-copy 7 | Maintainer: Sage Weil 8 | Uploaders: Sage Weil 9 | Build-Depends: debhelper (>= 6.0.7~) 10 | Standards-Version: 3.9.3 11 | 12 | Package: ceph-kdump-copy 13 | Architecture: linux-any 14 | Section: devel 15 | Priority: extra 16 | Depends: ${misc:Depends}, linux-crashdump 17 | Description: Shell script to repackage linux crashdump files generated by 18 | Ubuntu apport, then copy them to a remote system to facilitate 19 | offline analysis. Also includes an init script and associated 20 | configuration file to allow this to happen automatically at boot 21 | time. 22 | . 23 | This package contains an init script and supporting shell script to 24 | copy crashdump files to a remote server. 25 | -------------------------------------------------------------------------------- /debian/ceph-kdump-copy.default: -------------------------------------------------------------------------------- 1 | # ceph-kdump-copy configuration 2 | # --------------------------------------------------------------------------- 3 | 4 | # --------------------------------------------------------------------------- 5 | # Remote host information: 6 | # 7 | # These first two MUST be specified 8 | # KDUMP_HOST - The remote host to which kdumps will be copied. 9 | # KDUMP_HOST_USER - The ssh user on KDUMP_HOST that has write 10 | # permission in KDUMP_HOST_COREDIR. 11 | KDUMP_HOST="YOU_MUST_SPECIFY_THIS" 12 | KDUMP_HOST_USER="YOU_MUST_SPECIFY_THIS_TOO" 13 | 14 | # KDUMP_HOST_COREDIR - Full path to the directory on KDUMP_HOST that 15 | # will contain copied kdumps. If not set, "/var/crash/remote" is 16 | # the default. 17 | # KDUMP_HOST_COREDIR="/var/crash/remote" 18 | 19 | # KDUMP_HOST_MY_ID - Name for "me", used as the directory name 20 | # under KDUMP_HOST_COREDIR under which all kdumps from this 21 | # host are placed. Each kdump is identified by a date stamp. 22 | # If not set, "$(hostname)" is the default. 23 | # KDUMP_HOST_MY_ID="$(hostname)" 24 | 25 | # --------------------------------------------------------------------------- 26 | # Local host information: 27 | # 28 | # The local directory in which dumps are saved. If not set, "/var/crash" 29 | # is the default. 30 | # KDUMP_COREDIR="/var/crash" 31 | 32 | # --------------------------------------------------------------------------- 33 | # Architecture specific Overrides: 34 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | # -*- makefile -*- 3 | export DH_VERBOSE=1 4 | export DESTDIR=$(CURDIR)/debian/tmp 5 | 6 | export DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE) 7 | export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) 8 | 9 | # Recommended snippet for Autoconf 2.52 or later 10 | ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE)) 11 | confflags += --build $(DEB_HOST_GNU_TYPE) 12 | else 13 | confflags += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE) 14 | endif 15 | 16 | export DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH) 17 | 18 | configure: configure-stamp 19 | configure-stamp: 20 | dh_testdir 21 | touch $@ 22 | 23 | build-arch: build 24 | build-indep: build 25 | 26 | build: build-stamp 27 | build-stamp: configure-stamp 28 | dh_testdir 29 | touch $@ 30 | 31 | clean: 32 | dh_testdir 33 | dh_testroot 34 | rm -f build-stamp configure-stamp 35 | dh_clean 36 | 37 | install: build 38 | dh_testdir 39 | dh_testroot 40 | dh_clean -k 41 | dh_installdirs 42 | 43 | mkdir -p $(DESTDIR)/usr/bin 44 | install -D -m 755 ceph-kdump-copy $(DESTDIR)/usr/bin 45 | 46 | # Add here commands to install the package into debian/testpack. 47 | # Build architecture-independent files here. 48 | binary-indep: build install 49 | 50 | # We have nothing to do by default. 51 | # Build architecture-dependent files here. 52 | binary-arch: build install 53 | dh_testdir 54 | dh_testroot 55 | dh_installchangelogs 56 | # dh_installdocs --all ChangeLog 57 | dh_installexamples 58 | dh_install --sourcedir=$(DESTDIR) --list-missing 59 | dh_installlogrotate 60 | dh_installinit 61 | #dh_installman 62 | #dh_lintian 63 | dh_link 64 | 65 | dh_compress 66 | dh_fixperms 67 | #dh_makeshlibs -n # we do the postinst/postrm scripts manually 68 | dh_python2 69 | dh_installdeb 70 | dh_shlibdeps 71 | dh_gencontrol 72 | dh_md5sums 73 | dh_builddeb 74 | 75 | binary: binary-indep binary-arch 76 | .PHONY: build clean binary-indep binary-arch binary install configure 77 | -------------------------------------------------------------------------------- /debian/ceph-kdump-copy.init: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | ### BEGIN INIT INFO 3 | # Provides: ceph-kdump-copy 4 | # Required-Start: $remote_fs $network $named 5 | # Required-Stop: $remote_fs $network $named 6 | # Default-Start: 2 7 | # Default-Stop: 6 8 | # Short-Description: Copies kdump crash files to remote server 9 | # Description: This file is used to move crash files generated 10 | # by Ubuntu apport via the kdump init script to a 11 | # remote host. 12 | ### END INIT INFO 13 | 14 | # Author: Alex Elder 15 | 16 | # To install and activate this init script: 17 | # update-rc.d ceph-kdump-copy start 02 2 . 18 | # To deactivate and uninstall this init script: 19 | # update-rc.d -f ceph-kdump-copy remove 20 | 21 | # PATH should only include /usr/* if it runs after the mountnfs.sh script 22 | PATH="/sbin:/usr/sbin:/bin:/usr/bin" 23 | DESC="Copies kdump crash files to remote server" 24 | NAME="ceph-kdump-copy" 25 | SCRIPTNAME="/etc/init.d/${NAME}" 26 | CONFIGFILE="/etc/default/${NAME}" 27 | 28 | # Exit if the copy command is not installed 29 | [ -x "/usr/bin/ceph-kdump-copy" ] || exit 0 30 | 31 | # Read configuration variable file if it is present 32 | [ -r "${CONFIGFILE}" ] && . "${CONFIGFILE}" 33 | 34 | [ -z "${KDUMP_HOST}" ] && 35 | err "please specify KDUMP_HOST in '${CONFIGFILE}'" 36 | [ -z "${KDUMP_HOST_USER}" ] && 37 | err "please specify KDUMP_HOST_USER in '${CONFIGFILE}'" 38 | export KDUMP_HOST KDUMP_HOST_USER 39 | 40 | # Load the VERBOSE setting and other rcS variables 41 | . /lib/init/vars.sh 42 | 43 | # Define LSB log_* functions. 44 | # Depend on lsb-base (>= 3.2-14) to ensure that this file is present 45 | # and status_of_proc is working. 46 | . /lib/lsb/init-functions 47 | 48 | case "$1" in 49 | start) 50 | [ "$VERBOSE" != no ] && log_action_begin_msg "Copying kdump files" 51 | /usr/bin/ceph-kdump-copy 52 | if [ "$?" -eq 0 ]; then 53 | [ "$VERBOSE" != no ] && log_end_msg 0 54 | else 55 | [ "$VERBOSE" != no ] && log_end_msg 1 56 | fi 57 | ;; 58 | stop) # No-op 59 | ;; 60 | status|reload|force-reload|restart) 61 | echo "Error: argument '$1' not supported" >&2 62 | echo "Usage: $SCRIPTNAME {start|stop}" >&2 63 | exit 3 64 | ;; 65 | *) 66 | echo "Usage: $SCRIPTNAME {start|stop}" >&2 67 | exit 3 68 | ;; 69 | esac 70 | -------------------------------------------------------------------------------- /ceph-kdump-copy: -------------------------------------------------------------------------------- 1 | #!/bin/bash -norc 2 | 3 | # Copyright (C) 2012 Alex Elder 4 | # 5 | # This is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License version 2.1, as published by the Free Software 8 | # Foundation. See file COPYING. 9 | 10 | PROGNAME=$(basename $0) 11 | 12 | # issue a message to stderr and exit 13 | function err() { 14 | echo "${PROGNAME}: $@" >&2 15 | exit 1 16 | } 17 | 18 | ###################### 19 | 20 | # This script is normally called by /etc/init.d/ceph-kdump-copy, 21 | # which will set up these variables based on its config file, found 22 | # in /etc/default/ceph-kdump-copy. 23 | 24 | [ -z "${KDUMP_HOST}" ] && 25 | err "KDUMP_HOST must be specified" 26 | [ -z "${KDUMP_HOST_USER}" ] && 27 | err "KDUMP_HOST_UESR must be specified" 28 | 29 | # The local directory in which dumps are saved. 30 | KDUMP_COREDIR="${KDUMP_COREDIR:-/var/crash}" 31 | 32 | # Subdirectory on dump host under which my dumps are collected 33 | KDUMP_HOST_MY_ID="${KDUMP_HOST_MY_ID:-$(hostname)}" 34 | 35 | # Path on the dump host to the directory in which dumps are copied. 36 | KDUMP_HOST_COREDIR="${KDUMP_HOST_COREDIR:-/var/crash/remote}" 37 | 38 | KDUMP_HOST_MY_COREDIR="${KDUMP_HOST_COREDIR}/${KDUMP_HOST_MY_ID}" 39 | 40 | ##################################################################### 41 | 42 | 43 | # If no arguments are provided, it is a simple usage message (no error). 44 | # Otherwise display the message before printing usage information, and 45 | # exit with status indicating error. 46 | function usage () { 47 | local status=0 48 | 49 | echo "" >&2 50 | if [ $# -gt 0 ]; then 51 | status=1 52 | echo "${PROGNAME}: $@" >&2 53 | echo "" >&2 54 | fi 55 | echo "Usage: ${PROGNAME}" >&2 56 | echo "" >&2 57 | echo " each crash_file is the name of a crash file in " >&2 58 | echo " ${KDUMP_COREDIR} generated by kernel_crashdump" >&2 59 | echo "" >&2 60 | 61 | exit ${status} 62 | } 63 | 64 | # Run a command (or semicolon-separated commands) on the dump host 65 | function on_dump_host() { 66 | ssh -T "${KDUMP_HOST_USER}@${KDUMP_HOST}" "$@" 67 | } 68 | 69 | # Create a summary file based on apport crashfile content 70 | function summarize() { 71 | echo "Crash Summary" 72 | echo "-------------" 73 | echo "hostname: $(hostname)" 74 | echo "host arch: $(arch)" 75 | echo "time collected: $(date)" 76 | echo "crash_dir: ${CRASH_DIR}" 77 | echo "" 78 | echo "crash uname: $(cat Uname)" 79 | echo "crash timestamp: $(cat Date)" 80 | echo "kernel package: $(cat Package)" 81 | echo "distribution: $(cat DistroRelease)" 82 | } 83 | 84 | # Collect information related to a dump file. The file name provided 85 | # is the name of a file in ${KDUMP_COREDIR} containing a crash file 86 | # generated by /usr/share/apport/kernel_crashdump. Ubuntu uses its 87 | # apport package to bundle up information from the crash. We'll unpack 88 | # that and re-bundle it in a way less specific to Ubuntu. We'll also 89 | # gather a few more files to make the result self-contained. 90 | function collect_dump_info() { 91 | [ $# -eq 2 ] || exit 99 92 | local crash_release="$1" 93 | local crash_dir="$2" 94 | local i original copy 95 | 96 | # We need the debug version of vmlinux matching the dump. 97 | # Grab a few other useful files from /boot as well. 98 | for i in /usr/lib/debug/boot/vmlinux \ 99 | /boot/System.map /boot/vmcoreinfo \ 100 | /boot/config /boot/abi 101 | do 102 | original="${i}-${crash_release}" 103 | copy="${crash_dir}/$(basename "${original}")" 104 | 105 | cp "${original}" "${copy}" 106 | gzip "${copy}" # Compressing could be optional 107 | done 108 | } 109 | 110 | # Copy a directory containing a kdump and associated files. 111 | function move_crash_to_repository() { 112 | [ $# -eq 1 ] || exit 99 113 | local crash_dir="$1" 114 | 115 | tar cf - "./${crash_dir}" | 116 | on_dump_host "tar -C '${KDUMP_HOST_MY_COREDIR}' -xf -" && 117 | # Removing it should be the default, but optionally skipped 118 | rm -rf "./${crash_dir}" 119 | } 120 | 121 | # Process a single apport-generated crash file 122 | function process_crash_file() { 123 | [ $# -eq 1 ] || exit 99 124 | local crash_file="$1" 125 | local apport_dir crash_release crash_dir 126 | 127 | apport_dir="${crash_file}-apport_dir" 128 | mkdir "${apport_dir}" 129 | 130 | # Unpack the crash file 131 | apport-unpack "${crash_file}" "${apport_dir}" 132 | rm -f "${crash_file}" 133 | 134 | # Grab the release id from the kernel that crashed 135 | crash_release=$(cat "${apport_dir}"/Uname | awk '{print $2}') 136 | 137 | # Create a date-stamped directory in which to hold this crash 138 | crash_dir=$(date '+%F-%T%z') 139 | mkdir "${crash_dir}" 140 | 141 | # Produce a summary and save the actual core file 142 | ( cd "${apport_dir}"; summarize ) > "${crash_dir}/summary.txt" 143 | gzip "${crash_dir}/summary.txt" 144 | 145 | # Save and compress the actual core file 146 | mv ${apport_dir}/VmCore "${crash_dir}/vmcore-${crash_release}" 147 | gzip "${crash_dir}/vmcore-${crash_release}" 148 | 149 | # We've got what we need from the crash file 150 | rm -rf "${apport_dir}" 151 | 152 | # Collect the other related files 153 | collect_dump_info "${crash_release}" "${crash_dir}" 154 | 155 | # Create a little README file 156 | ( 157 | echo "To analyze the kernel core dump here:" 158 | echo " gunzip 'vmcore-${crash_release}'" 159 | echo " crash 'vmlinux-${crash_release}.gz' \\" 160 | echo " 'vmcore-${crash_release}'" 161 | echo "" 162 | echo "Other files provide additional context." 163 | ) > "${crash_dir}/README" 164 | 165 | # Remove other files we don't have any need for 166 | rm config_link kernel_link system.map_link 167 | 168 | # Finally, copy the crash directory over to the repository 169 | move_crash_to_repository "${crash_dir}" 170 | } 171 | 172 | ######### Start ######### 173 | 174 | cd "${KDUMP_COREDIR}" 175 | CRASH_FILES=$(ls linux-image-*.crash 2> /dev/null) 176 | [ -z "${CRASH_FILES}" ] && exit 0 # Quit if there's nothing to do 177 | 178 | # Make sure the directory to contain our dumps is there on the dump host 179 | on_dump_host "mkdir -p '${KDUMP_HOST_MY_COREDIR}'" || 180 | err "unable to create '${KDUMP_HOST_MY_COREDIR}' on host '${KDUMP_HOST}'" 181 | 182 | # Now process each crash file; exit on the first error. 183 | for crash_file in ${CRASH_FILES}; do 184 | process_crash_file "${crash_file}" || 185 | err "unable to process '${crsh_file}'" 186 | done 187 | 188 | exit 0 189 | --------------------------------------------------------------------------------