Merge pull request #56513 from rosinL/wip-fix-65175
[ceph.git] / src / ceph-debugpack.in
1 #!/bin/sh
2
3 # if we start up as ./init-ceph, assume everything else is in the
4 # current directory too.
5 if [ `dirname $0` = "." ] && [ $PWD != "/etc/init.d" ]; then
6     BINDIR=.
7     LIBEXECDIR=.
8     ETCDIR=.
9 else
10     BINDIR=@bindir@
11     LIBEXECDIR=@libexecdir@/ceph
12     ETCDIR=@sysconfdir@/ceph
13 fi
14
15 BINDBGDIR="/usr/lib/debug/usr/bin"
16
17 usage_exit() {
18     echo "usage: $0 [-c ceph.conf] <filename.tar.gz>"
19     exit
20 }
21
22 wait_pid_exit() {
23         pid=$1
24
25         for i in $(seq 10); do
26                 [ -e /proc/$pid ] || return
27                 sleep 1
28         done
29         if [ -e /proc/$pid ]; then
30             echo Killing pid $pid
31             kill $pid
32         fi
33 }
34
35 . $LIBEXECDIR/ceph_common.sh
36
37 dest_tar=''
38 while [ $# -ge 1 ]; do
39 case $1 in
40     --conf | -c)
41             [ -z "$2" ] && usage_exit
42             shift
43             conf=$1
44             ;;
45     *)
46             if [ -n "$dest_tar" ]; then
47                 echo unrecognized option \'$1\'
48                 usage_exit
49             fi
50             dest_tar=$1
51             ;;
52 esac
53 shift
54 done
55
56 [ "$dest_tar" = "" ] && usage_exit
57
58 echo "$0: generating debugpack tarball..."
59
60 if [ -e $dest_tar ]; then
61     echo "$0: dest $dest_tar already exists, aborting"
62     exit 1
63 fi
64
65 # get absolute path for dest_tar
66 bins="ceph-mon ceph-mds ceph-osd radosgw"
67 core_paths="/ $BINDIR $BINDBGDIR"
68 [ "$conf" = "" ] && conf=$ETCDIR/ceph.conf
69 log_path=`$CCONF -c $conf "log dir"`
70
71 [ -z "$conf" ] && usage_exit
72
73 # all configs
74 files='/etc/ceph'
75
76 # binaries
77 for bin in bins; do
78     if [ -e "/usr/bin/$bin" ]; then
79         files="$files /usr/bin/$bin"
80     fi
81     if [ -e "/usr/lib/debug/usr/bin/$bin" ]; then
82         files="$files /usr/lib/debug/usr/bin/$bin"
83     fi
84 done
85
86 # logs (the non-rotated ones)
87 for f in `find $path -maxdepth 1 -name 'core*'`; do
88     files="$files $f"
89 done
90
91 # copy cores (if exist)
92 for path in $core_paths; do
93     if [ -d $path ]; then
94         for f in `find $path -maxdepth 1 -name 'core*'`; do
95             files="$files $f"
96         done
97     fi
98 done
99
100 # cluster state
101 tmp_path=`mktemp -d /tmp/ceph-debugpack.XXXXXXXXXX`
102
103 $BINDIR/ceph report > $tmp_path/ceph-report &
104 wait_pid_exit $!
105
106 files="$files $tmp_path"
107
108 # now create a tarball
109 tar cvfz $dest_tar $files
110 rm -rf $tmp_path
111
112 echo "$0: created debugpack tarball at $dest_tar"
113