|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# NOTE(mgoddard): This has been adapted from |
| 4 | +# roles/kayobe-diagnostics/files/get_logs.sh in Kayobe. |
| 5 | + |
| 6 | +# Environment variables: |
| 7 | +# $LOG_DIR is the directory to copy logs to. |
| 8 | + |
| 9 | +# TODO: Make this script more robust and use set -e. |
| 10 | +set +o errexit |
| 11 | +set -u |
| 12 | + |
| 13 | +copy_logs() { |
| 14 | + mkdir -p ${LOG_DIR}/{docker_logs,kolla_node_configs,system_logs} |
| 15 | + |
| 16 | + cp -rnL /etc/kolla/* ${LOG_DIR}/kolla_node_configs |
| 17 | + # Don't save the IPA images. |
| 18 | + rm ${LOG_DIR}/kolla_node_configs/ironic-http/ironic-agent.{kernel,initramfs} |
| 19 | + rm ${LOG_DIR}/kolla_node_configs/ironic-tftp/ironic-agent.{kernel,initramfs} |
| 20 | + |
| 21 | + if [[ -d /opt/kayobe/etc/kolla ]]; then |
| 22 | + mkdir -p ${LOG_DIR}/kolla_build_configs |
| 23 | + cp -rnL /opt/kayobe/etc/kolla/* ${LOG_DIR}/kolla_build_configs/ |
| 24 | + fi |
| 25 | + |
| 26 | + cp -rvnL /var/log/* ${LOG_DIR}/system_logs/ |
| 27 | + |
| 28 | + journalctl --no-pager > ${LOG_DIR}/system_logs/syslog.log |
| 29 | + journalctl --no-pager -u docker.service > ${LOG_DIR}/system_logs/docker.log |
| 30 | + journalctl --no-pager -u vbmcd.service > ${LOG_DIR}/system_logs/vbmcd.log |
| 31 | + journalctl --no-pager -u NetworkManager.service > ${LOG_DIR}/system_logs/NetworkManager.log |
| 32 | + |
| 33 | + if [[ -d /etc/sysconfig/network-scripts/ ]]; then |
| 34 | + cp -r /etc/sysconfig/network-scripts/ ${LOG_DIR}/system_logs/ |
| 35 | + fi |
| 36 | + |
| 37 | + if [[ -d /etc/NetworkManager/system-connections/ ]]; then |
| 38 | + cp -r /etc/NetworkManager/system-connections/ ${LOG_DIR}/system_logs/ |
| 39 | + fi |
| 40 | + |
| 41 | + if [[ -d /etc/yum.repos.d/ ]]; then |
| 42 | + cp -r /etc/yum.repos.d/ ${LOG_DIR}/system_logs/ |
| 43 | + fi |
| 44 | + |
| 45 | + if [[ -d /etc/apt/sources.list.d/ ]]; then |
| 46 | + cp -r /etc/apt/sources.list.d/ ${LOG_DIR}/system_logs/ |
| 47 | + fi |
| 48 | + |
| 49 | + if [[ -d /etc/systemd/ ]]; then |
| 50 | + cp -rL /etc/systemd/ ${LOG_DIR}/system_logs/ |
| 51 | + fi |
| 52 | + |
| 53 | + df -h > ${LOG_DIR}/system_logs/df.txt |
| 54 | + # Gather disk usage statistics for files and directories larger than 1MB |
| 55 | + du -d 5 -hx / | sort -hr | grep '^[0-9\.]*[MGT]' > ${LOG_DIR}/system_logs/du.txt |
| 56 | + free > ${LOG_DIR}/system_logs/free.txt |
| 57 | + cat /etc/hosts > ${LOG_DIR}/system_logs/hosts.txt |
| 58 | + parted -l > ${LOG_DIR}/system_logs/parted-l.txt |
| 59 | + mount > ${LOG_DIR}/system_logs/mount.txt |
| 60 | + env > ${LOG_DIR}/system_logs/env.txt |
| 61 | + ip address > ${LOG_DIR}/system_logs/ip-address.txt |
| 62 | + ip route > ${LOG_DIR}/system_logs/ip-route.txt |
| 63 | + ip route show table all > ${LOG_DIR}/system_logs/ip-route-all-tables.txt |
| 64 | + ip rule list > ${LOG_DIR}/system_logs/ip-rule-list.txt |
| 65 | + pvs > ${LOG_DIR}/system_logs/pvs.txt |
| 66 | + vgs > ${LOG_DIR}/system_logs/vgs.txt |
| 67 | + lvs > ${LOG_DIR}/system_logs/lvs.txt |
| 68 | + |
| 69 | + iptables-save > ${LOG_DIR}/system_logs/iptables.txt |
| 70 | + |
| 71 | + if [ `command -v dpkg` ]; then |
| 72 | + dpkg -l > ${LOG_DIR}/system_logs/dpkg-l.txt |
| 73 | + fi |
| 74 | + if [ `command -v rpm` ]; then |
| 75 | + rpm -qa > ${LOG_DIR}/system_logs/rpm-qa.txt |
| 76 | + fi |
| 77 | + |
| 78 | + # final memory usage and process list |
| 79 | + ps -eo user,pid,ppid,lwp,%cpu,%mem,size,rss,cmd > ${LOG_DIR}/system_logs/ps.txt |
| 80 | + |
| 81 | + # available entropy |
| 82 | + cat /proc/sys/kernel/random/entropy_avail > ${LOG_DIR}/system_logs/entropy_avail.txt |
| 83 | + |
| 84 | + # docker related information |
| 85 | + (docker info && docker images && docker ps -a) > ${LOG_DIR}/system_logs/docker-info.txt |
| 86 | + |
| 87 | + for container in $(docker ps -a --format "{{.Names}}"); do |
| 88 | + docker logs --tail all ${container} &> ${LOG_DIR}/docker_logs/${container}.txt |
| 89 | + done |
| 90 | + |
| 91 | + # Bifrost: grab config files and logs from the container. |
| 92 | + if [[ $(docker ps -q -f name=bifrost_deploy) ]]; then |
| 93 | + mkdir -p ${LOG_DIR}/bifrost |
| 94 | + for service in dnsmasq ironic-api ironic-conductor ironic-inspector mariadb nginx rabbitmq-server; do |
| 95 | + mkdir -p ${LOG_DIR}/bifrost/$service |
| 96 | + docker exec bifrost_deploy \ |
| 97 | + systemctl status $service -l -n 10000 > ${LOG_DIR}/bifrost/$service/${service}-systemd-status.txt |
| 98 | + docker exec bifrost_deploy \ |
| 99 | + journalctl -u $service --no-pager > ${LOG_DIR}/bifrost/$service/${service}-journal.txt |
| 100 | + done |
| 101 | + docker exec -it bifrost_deploy \ |
| 102 | + journalctl --no-pager > ${LOG_DIR}/bifrost/bifrost-journal.log |
| 103 | + for d in dnsmasq.conf ironic ironic-inspector nginx/nginx.conf; do |
| 104 | + docker cp bifrost_deploy:/etc/$d ${LOG_DIR}/kolla_node_configs/bifrost/ |
| 105 | + done |
| 106 | + docker cp bifrost_deploy:/var/log/mariadb/mariadb.log ${LOG_DIR}/bifrost/mariadb/ |
| 107 | + fi |
| 108 | + |
| 109 | + # IPA build logs |
| 110 | + if [[ -f /opt/kayobe/images/ipa/ipa.stderr ]] || [[ -f /opt/kayobe/images/ipa/ipa.stdout ]]; then |
| 111 | + mkdir -p ${LOG_DIR}/ipa |
| 112 | + cp /opt/kayobe/images/ipa/ipa.stderr /opt/kayobe/images/ipa/ipa.stdout ${LOG_DIR}/ipa/ |
| 113 | + fi |
| 114 | + |
| 115 | + # Overcloud host image build logs |
| 116 | + if [[ -f /opt/kayobe/images/deployment_image/deployment_image.stderr ]] || [[ -f /opt/kayobe/images/deployment_image/deployment_image.stdout ]]; then |
| 117 | + mkdir -p ${LOG_DIR}/deployment_image |
| 118 | + cp /opt/kayobe/images/deployment_image/deployment_image.stderr /opt/kayobe/images/deployment_image/deployment_image.stdout ${LOG_DIR}/deployment_image/ |
| 119 | + fi |
| 120 | + |
| 121 | + chown -R stack: ${LOG_DIR} |
| 122 | +} |
| 123 | + |
| 124 | +copy_logs |
0 commit comments