Subversion Repositories configs

Rev

Rev 3 | Rev 8 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 - 1
#! /bin/sh
2
### BEGIN INIT INFO
3
# Provides: kdump
4
# Default-Start:  3 4 5
5
# Default-Stop: 0 1 6
6
# Short-Description: start and stop kdump crash recovery service
7
# Description:  The kdump init script provides the support necessary for
8
#		loading a kdump kernel into memory at system bootup time,
9
#		and for copying away a vmcore at system panic time.
10
### END INIT INFO
11
#  Copyright 2005 Red Hat, Inc.
12
#
13
#  chkconfig: - 20 80
14
#
15
#  Author:  Jeff Moyer <jmoyer@redhat.com>
16
 
17
 
18
# Source function library.
19
. /etc/init.d/functions
20
 
21
KEXEC=/sbin/kexec
22
 
23
# Will be different for ia64, for example.  For now, that architecture isn't
24
# supported.  Code needs to be added here when we do.
25
BOOTDIR="/boot"
26
 
27
KDUMP_KERNELVER=""
28
KDUMP_COMMANDLINE=""
29
KDUMP_IDE_NOPROBE_COMMANDLINE=""
30
KEXEC_ARGS=""
31
KDUMP_CONFIG_FILE="/etc/kdump.conf"
32
MEM_RESERVED=""
33
MKDUMPRD_ARGS=""
34
CLUSTER_CONFIG_FILE="/etc/cluster/cluster.conf"
35
FENCE_KDUMP_CONFIG="/etc/sysconfig/fence_kdump"
36
SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa"
37
 
38
LOGGER="/usr/bin/logger -p info -t kdump"
39
 
40
standard_kexec_args="-p"
41
 
42
if [ -f /etc/sysconfig/kdump ]; then
43
	. /etc/sysconfig/kdump
44
fi
45
 
46
function single_instance_lock()
47
{
48
	exec 9>/var/lock/kdump
49
	flock 9
50
}
51
 
52
# remove_cmdline_param <kernel cmdline> <param1> [<param2>] ... [<paramN>]
53
# Remove a list of kernel parameters from a given kernel cmdline and print the result.
54
# For each "arg" in the removing params list, "arg" and "arg=xxx" will be removed if exists.
55
function remove_cmdline_param()
56
{
57
	local cmdline=$1
58
	shift
59
 
60
	for arg in $@; do
61
		cmdline=`echo $cmdline | \
62
			 sed -e "s/\b$arg=[^ ]*\b//g" \
63
			     -e "s/\b$arg\b//g"`
64
	done
65
	echo $cmdline
66
}
67
 
68
 
69
function in_xen_pv_guest()
70
{
71
	grep -q 'xen-percpu-virq  *timer0' /proc/interrupts
72
}
73
 
74
function in_xen_hvm_guest()
75
{
76
	grep -q "xen" /sys/hypervisor/type >& /dev/null && ! grep -q 'xen-percpu-virq  *timer0' /proc/interrupts
77
}
78
 
79
function check_xen_hvm_nopv_premkdumprd()
80
{
81
	if in_xen_hvm_guest; then
82
		if grep -q "xen_.*front" /proc/modules; then
83
			return 1
84
		fi
85
	fi
86
}
87
 
88
function save_kernel_logs()
89
{
90
	local _path=$1
91
 
92
	mkdir -p $_path
93
 
94
	if [ ! -f /sbin/vmcore-dmesg ];then
95
		$LOGGER "Skipping saving vmcore-dmesg.txt. File /sbin/vmcore-dmesg is not present"
96
		return;
97
	fi
98
 
99
	echo "kdump: saving vmcore-dmesg.txt to $_path"
100
	$LOGGER "saving vmcore-dmesg.txt to $_path"
101
	/sbin/vmcore-dmesg /proc/vmcore > $_path/vmcore-dmesg-incomplete.txt
102
	if [ $? == 0 ]; then
103
		mv $_path/vmcore-dmesg-incomplete.txt $_path/vmcore-dmesg.txt
104
		echo "kdump: saved vmcore-dmesg.txt to $_path"
105
		$LOGGER "saved vmcore-dmesg.txt to $_path"
106
	else
107
		echo "kdump: failed to save vmcore-dmesg.txt to $_path"
108
		$LOGGER "failed to save vmcore-dmesg.txt to $_path"
109
	fi
110
 
111
}
112
 
6 - 113
#
114
# This function returns the "initial apicid" of the
115
# boot cpu (cpu 0) if present.
116
#
117
function get_bootcpu_initial_apicid()
118
{
119
    awk '                                                       \
120
	BEGIN { CPU = "-1"; }                                   \
121
	$1=="processor" && $2==":"      { CPU = $NF; }          \
122
	CPU=="0" && /initial apicid/    { print $NF; }          \
123
	'                                                       \
124
	/proc/cpuinfo
125
}
126
 
127
#
128
# This function appends argument "$2=$3" to string ($1) if not already present.
129
#
130
function append_cmdline()
131
{
132
    local cmdline=$1
133
    local newstr=${cmdline/$2/""}
134
 
135
    # unchanged str implies argument wasn't there
136
    if [ "$cmdline" == "$newstr" ]; then
137
        cmdline="${cmdline} ${2}=${3}"
138
    fi
139
 
140
    echo $cmdline
141
}
142
 
143
# This function performs a series of edits on the command line
144
function prepare_cmdline()
145
{
146
	local cmdline;
147
	if [ -z "$KDUMP_COMMANDLINE" ]; then
148
		cmdline=`cat /proc/cmdline`
149
	else
150
		cmdline=${KDUMP_COMMANDLINE}
151
	fi
152
	cmdline=`remove_cmdline_param "$cmdline" crashkernel mem hugepages hugepagesz`
153
	cmdline="${cmdline} ${KDUMP_COMMANDLINE_APPEND}"
154
	avoid_cdrom_drive
155
	KDUMP_COMMANDLINE="${KDUMP_COMMANDLINE} ${KDUMP_IDE_NOPROBE_COMMANDLINE}"
156
 
157
	local id=`get_bootcpu_initial_apicid`
158
	if [ ! -z ${id} ] ; then
159
		cmdline=`append_cmdline "${cmdline}" disable_cpu_apicid ${id}`
160
	fi
161
 
162
	echo $cmdline
163
}
164
 
165
 
3 - 166
function save_core()
167
{
168
	local kdump_path
169
	kdump_path=`grep ^path $KDUMP_CONFIG_FILE | cut -d' '  -f2-`
170
	if [ -z "$kdump_path" ]; then
171
		coredir="/var/crash/127.0.0.1-`date +"%Y-%m-%d-%H:%M"`"
172
	else
173
		coredir="${kdump_path}/127.0.0.1-`date +"%Y-%m-%d-%H:%M"`"
174
	fi
175
 
176
	mkdir -p $coredir
177
	save_kernel_logs "${coredir}"
178
	/usr/sbin/makedumpfile -c --message-level 1 -d 31 /proc/vmcore $coredir/vmcore-incomplete
179
	if [ $? == 0 ]; then
180
		mv $coredir/vmcore-incomplete $coredir/vmcore
181
		$LOGGER "saved a vmcore to $coredir"
182
	else
183
		$LOGGER "failed to save a vmcore to $coredir"
184
	fi
185
}
186
 
187
function check_config()
188
{
189
	local modified_files=""
190
	local force_rebuild=0
191
	if [ -f /etc/kdump-adv-conf/initramfs.conf ]
192
	then
193
		$LOGGER "Using Kdump advanced configuration service"
194
		if [ -n "$DRACUT_CMD" ]
195
		then
196
			MKDUMPRD=$DRACUT_CMD
197
		else
198
			MKDUMPRD="dracut -f -c /etc/kdump-adv-conf/initramfs.conf"
199
		fi
200
		# We always rebuild here, since it takes longer
201
		# to figure out if anything has changed
202
		touch /etc/kdump.conf
203
	else
204
		MKDUMPRD="/sbin/mkdumprd -d -f $MKDUMPRD_ARGS"
205
	fi
206
 
207
	force_rebuild=`grep ^force_rebuild $KDUMP_CONFIG_FILE | cut -d' '  -f2`
208
	if [ -n "$force_rebuild" ] && [ "$force_rebuild" -ne 0 ]
209
	then
210
                modified_files="force_rebuild"
211
	fi
212
 
213
	if [ -z "$KDUMP_KERNELVER" ]; then
214
		local running_kernel=`uname -r`
215
 
216
		kdump_kver=`echo $running_kernel | sed 's/smp//g'`
217
	else
218
		kdump_kver=$KDUMP_KERNELVER
219
	fi
220
 
221
	kdump_kernel="${KDUMP_BOOTDIR}/${KDUMP_IMG}-${kdump_kver}${KDUMP_IMG_EXT}"
222
	kdump_initrd="${KDUMP_BOOTDIR}/initrd-${kdump_kver}kdump.img"
223
 
224
	if [ ! -f $kdump_kernel ]; then
225
		echo -n "No kdump kernel image found."; warning; echo
226
		echo "Tried to locate ${kdump_kernel}"
227
		return 0
228
	fi
229
 
230
	if [ ! -f $kdump_initrd ]; then
231
		echo  -n "No kdump initial ramdisk found."; warning; echo
232
		if ! check_xen_hvm_nopv_premkdumprd; then
233
			echo "hvm guest with pv drivers is not supported."
234
			exit 1
235
		fi
236
 
237
		echo "Rebuilding $kdump_initrd"
238
		$MKDUMPRD $kdump_initrd $kdump_kver
239
		if [ $? != 0 ]; then
240
			echo "Failed to run mkdumprd"
241
			$LOGGER "mkdumprd: failed to make kdump initrd"
242
			exit 1
243
		fi
244
		return 0
245
	fi
246
 
247
	if [ -z "$modified_files" ]
248
	then
249
		#check to see if config file or kdump post has been modified
250
		#since last build of the image file
251
		image_time=`stat -c "%Y" $kdump_initrd`
252
		EXTRA_FILES=`grep ^kdump_post $KDUMP_CONFIG_FILE | cut -d\  -f2`
253
		CHECK_FILE=`grep ^kdump_pre $KDUMP_CONFIG_FILE | cut -d\  -f2`
254
		EXTRA_FILES="$EXTRA_FILES $CHECK_FILE"
255
		CHECK_FILE=`grep ^extra_modules $KDUMP_CONFIG_FILE | cut -d\  -f2-`
256
		EXTRA_FILES="$EXTRA_FILES $CHECK_FILE"
257
		CHECK_FILE=`grep ^extra_bins $KDUMP_CONFIG_FILE | cut -d\  -f2-`
258
		EXTRA_FILES="$EXTRA_FILES $CHECK_FILE"
259
		FORCE_REBUILD=`grep ^extra_modules $KDUMP_CONFIG_FILE`
260
		files="$KDUMP_CONFIG_FILE $kdump_kernel $EXTRA_FILES"
261
 
262
		#check to see if cluster is configured to use fence_kdump
263
		if [ -f "$CLUSTER_CONFIG_FILE" ] && grep -q fence_kdump "$CLUSTER_CONFIG_FILE"
264
		then
265
		    files="$files $CLUSTER_CONFIG_FILE"
266
		    if [ -f "$FENCE_KDUMP_CONFIG" ]; then
267
			files="$files $FENCE_KDUMP_CONFIG"
268
		    fi
269
		fi
270
 
271
		for file in $files; do
272
			time_stamp=0
273
			if [ -f "$file" ]; then
274
				time_stamp=`stat -c "%Y" $file`
275
			else
276
				modified_files="$modified_files $file"
277
				continue
278
			fi
279
			if [ "$time_stamp" -gt "$image_time" ]; then
280
				modified_files="$modified_files $file"
281
			fi
282
		done
283
	fi
284
 
285
        if [ -n "$FORCE_REBUILD" -a "$modified_files"!=" " ]
286
        then
287
                modified_files="force_rebuild"
288
        fi
289
 
290
        if [ -n "$modified_files" -a "$modified_files"!=" " ]; then
291
                if [ "$modified_files" != "force_rebuild" ]
292
                then
293
                        echo "Detected change(s) the following file(s):"
294
                        echo -n "  "; echo "$modified_files" | sed 's/\s/\n  /g'
295
                fi
296
 
297
		if ! check_xen_hvm_nopv_premkdumprd; then
298
			echo "hvm guest with pv drivers is not supported."
299
			exit 1
300
		fi
301
 
302
                echo "Rebuilding $kdump_initrd"
303
		$MKDUMPRD $kdump_initrd $kdump_kver
304
                if [ $? != 0 ]; then
305
                        echo "Failed to run mkdumprd"
306
                        $LOGGER "mkdumprd: failed to make kdump initrd"
307
                        return 1
308
                fi
309
        fi
310
 
311
	#double check the xen_*front modules are not included for xen hvm
312
	if in_xen_hvm_guest; then
313
		if $(lsinitrd $kdump_initrd|grep -q "xen_.*front.ko"); then
314
			echo "Found xen pv drivers in kdump initrd"
315
			exit 1
316
		fi
317
	fi
318
        return 0
319
}
320
 
321
# This function check iomem and determines if we have more than
322
# 4GB of ram available. Returns 1 if we do, 0 if we dont
323
function need_64bit_headers()
324
{
325
    return `tail -n 1 /proc/iomem | awk '{ split ($1, r, "-"); \
326
    print (strtonum("0x" r[2]) > strtonum("0xffffffff")); }'`
327
}
328
 
329
function avoid_cdrom_drive()
330
{
331
	local DRIVE=""
332
	local MEDIA=""
333
	local IDE_DRIVES=(`echo hd{a,b,c,d}`)
334
	local COUNTER="0"
335
 
336
	for DRIVE in ${IDE_DRIVES[@]}
337
	do
338
		if ! $(echo "$KDUMP_COMMANDLINE" |grep -q "$DRIVE=");then
339
			if [ -f /proc/ide/$DRIVE/media ];then
340
				MEDIA=$(cat /proc/ide/$DRIVE/media)
341
				if [ x"$MEDIA" == x"cdrom" ]; then
342
					KDUMP_IDE_NOPROBE_COMMANDLINE="$KDUMP_IDE_NOPROBE_COMMANDLINE $DRIVE=cdrom"
343
					COUNTER=$(($COUNTER+1))
344
				fi
345
			fi
346
		else
347
			KDUMP_IDE_NOPROBE_COMMANDLINE="$KDUMP_IDE_NOPROBE_COMMANDLINE $DRIVE=noprobe"
348
		fi
349
	done
350
	# We don't find cdrom drive.
351
	if [ $COUNTER -eq 0 ]; then
352
		KDUMP_IDE_NOPROBE_COMMANDLINE=""
353
	fi
354
}
355
 
356
function check_kernel_parameter()
357
{
358
	if [ -z "$KDUMP_COMMANDLINE" ]
359
	then
360
		KDUMP_COMMANDLINE=`cat /proc/cmdline`
361
	fi
362
 
363
	MEM_RESERVED=`cat /sys/kernel/kexec_crash_size`
364
 
365
	if [ $MEM_RESERVED -eq 0 ]
366
	then
367
		return 1
368
	else
369
		return 0
370
	fi
371
}
372
 
373
# Load the kdump kerel specified in /etc/sysconfig/kdump
374
# If none is specified, try to load a kdump kernel with the same version
375
# as the currently running kernel.
376
function load_kdump()
377
{
378
	ARCH=`uname -m`
379
 
380
	# Get the approx amount of ram the kernel is using in Kb
381
	KMEMINUSE=`awk '/Slab:.*/ {print $2}' /proc/meminfo`
382
	# Convert the reserved ram amount to Kb
383
	MEM_RESERVED=`dc -e"$MEM_RESERVED 1024 / p"`
384
 
385
	# Take 70% of the reserved value rounding up to the nearest integer
386
	MEM_RESERVED=`dc -e"$MEM_RESERVED .7 * 10 * 10 / p"`
387
 
388
	#On x86, we are using nr_cpus=1, so the following check is not necessary.
389
	if [ "$ARCH" != "i686" -a "$ARCH" != "i386" -a "$ARCH" != "x86_64" ]
390
	then
391
		#Check if the KMEMINUSE is greater than MEM_RESERVED
392
		# This indicates that the currently runnign kernel is using
393
		# 70% of the amount of memory that we have reserved for kdump
394
		# we should issue a warning here indicating that the user may
395
		# want to increase the amount of reserved ram on the system
396
		if [ $KMEMINUSE -gt $MEM_RESERVED ]
397
		then
398
			echo -n "Your running kernel is using more than 70% of the amount of space you reserved for kdump, you should consider increasing your crashkernel reservation"
399
			warning
400
			echo
401
		fi
402
	fi
403
 
404
	if [ "$ARCH" == "i686" -o "$ARCH" == "i386" ]
405
	then
406
 
407
		need_64bit_headers
408
		if [ $? == 1 ]
409
		then
410
			FOUND_ELF_ARGS=`echo $KEXEC_ARGS | grep elf32-core-headers`
411
			if [ -n "$FOUND_ELF_ARGS" ]
412
			then
413
				echo -n "Warning: elf32-core-headers overrides correct elf64 setting"
414
				warning
415
				echo
416
			else
417
				KEXEC_ARGS="$KEXEC_ARGS --elf64-core-headers"
418
			fi
419
		else
420
			FOUND_ELF_ARGS=`echo $KEXEC_ARGS | grep elf64-core-headers`
421
			if [ -z "$FOUND_ELF_ARGS" ]
422
			then
423
				KEXEC_ARGS="$KEXEC_ARGS --elf32-core-headers"
424
			fi
425
		fi
426
	fi
427
 
428
	if [ -f /sys/firmware/efi/systab ]
429
	then
430
		if grep -q '^ACPI20=' /sys/firmware/efi/systab
431
		then
432
			acpi_addr=$(awk -F'=' '/^ACPI20=/ {print $2}' /sys/firmware/efi/systab)
433
		else
434
			acpi_addr=$(awk -F'=' '/^ACPI=/ {print $2}' /sys/firmware/efi/systab)
435
		fi
436
		KDUMP_COMMANDLINE="$KDUMP_COMMANDLINE noefi acpi_rsdp=$acpi_addr"
437
	fi
438
 
439
	if echo "$KDUMP_COMMANDLINE_APPEND" | grep -q nr_cpus;
440
	then
441
		ver=`uname -r`
442
		maj=`echo $ver | cut -d'-' -f1`
443
		min=`echo $ver | cut -d'-' -f2`
444
		min=${min%%.*}
445
		if [ "$maj" = "2.6.32" ] && [ $min -lt 171 ]
446
		then
447
			echo "Your kernel is old, please use maxcpus=1 instead of nr_cpus=1"
448
			return 1
449
		fi
450
	fi
451
 
6 - 452
	KDUMP_COMMANDLINE=`prepare_cmdline`
453
 
3 - 454
	if ! grep -q /sys/kernel/debug /proc/mounts;
455
	then
456
		mount -t debugfs debug /sys/kernel/debug
457
		MNTDEBUG=/sys/kernel/debug
458
	fi
6 - 459
 
3 - 460
	$KEXEC $KEXEC_ARGS $standard_kexec_args \
461
		--command-line="$KDUMP_COMMANDLINE" \
462
		--initrd=$kdump_initrd $kdump_kernel 2>/dev/null
463
	if [ $? == 0 ]; then
464
		umount $MNTDEBUG 2>/dev/null
465
		$LOGGER "kexec: loaded kdump kernel"
466
		return 0
467
	else
468
		umount $MNTDEBUG 2>/dev/null
469
		$LOGGER "kexec: failed to load kdump kernel"
470
		return 1
471
	fi
472
}
473
 
474
function propagate_ssh_key()
475
{
476
	while read config_opt config_val; do
477
		case "$config_opt" in
478
		sshkey)
479
			SSH_KEY_LOCATION="$config_val"
480
			;;
481
		*)
482
			;;
483
		esac
484
	done < $KDUMP_CONFIG_FILE
485
 
486
	local KEYFILE=$SSH_KEY_LOCATION
487
	local errmsg="Failed to propagate ssh key"
488
 
489
	#make sure they've configured kdump.conf for ssh dumps
490
	local SSH_TARGET=`awk '/^\ *net.*@.*$/ {print $0}' $KDUMP_CONFIG_FILE`
491
	[ -z "$SSH_TARGET" ] && SSH_TARGET=`awk '/^\ *ssh.*@.*$/ {print $0}' $KDUMP_CONFIG_FILE`
492
	if [ -z "$SSH_TARGET" ]; then
493
		echo "No ssh config specified in $KDUMP_CONFIG_FILE.  Can't propagate"
494
		$LOGGER "$errmsg, no ssh config specified in $KDUMP_CONFIG_FILE"
495
		exit 1
496
	fi
497
 
498
	#Check to see if we already created key, if not, create it.
499
	if [ -f $KEYFILE ]; then
500
		echo "Using existing keys..."
501
	else
502
		echo -n "Generating new ssh keys... "
503
		/usr/bin/ssh-keygen -t rsa -f $KEYFILE -N "" 2>&1 > /dev/null
504
		echo "done."
505
	fi
506
 
507
	#now find the target ssh user and server to contact.
508
	SSH_USER=`echo $SSH_TARGET | cut -d\  -f2 | cut -d@ -f1`
509
	SSH_SERVER=`echo $SSH_TARGET | sed -e's/\(.*@\)\(.*$\)/\2/'`
510
 
511
	#now send the found key to the found server
512
	ssh-copy-id -i $KEYFILE $SSH_USER@$SSH_SERVER &>/dev/null
513
	RET=$?
514
	if [ $RET == 0 ]; then
515
		echo $KEYFILE has been added to ~$SSH_USER/.ssh/authorized_keys on $SSH_SERVER
516
		$LOGGER "propagated ssh key (ssh server: $SSH_SERVER)"
517
		return 0
518
	else
519
		echo $KEYFILE failed in transfer to $SSH_SERVER
520
		$LOGGER "$errmsg, unable to transfer $KEYFILE to $SSH_SERVER"
521
		exit 1
522
	fi
523
 
524
}
525
 
526
function status()
527
{
528
	if [ ! -e /sys/kernel/kexec_crash_loaded ]
529
	then
530
		return 2
531
	fi
532
 
533
	if in_xen_pv_guest; then
534
		return 2
535
	elif in_xen_hvm_guest && ! grep -q -e xen_emul_unplug=never -e xen_emul_unplug=unnecessary /proc/cmdline; then
536
		echo 'kdump only supported on xen hvm guests booted with xen_emul_unplug=never or xen_emul_unplug=unnecessary'
537
		return 2
538
	fi
539
 
540
	rc=`cat /sys/kernel/kexec_crash_loaded`
541
	if [ $rc == 1 ]; then
542
		return 0
543
	else
544
		return 1
545
	fi
546
}
547
 
548
function save_raw()
549
{
550
	local raw_part=$(awk '$1 ~ /^raw$/ { print $2; }' $KDUMP_CONFIG_FILE)
551
	local kdump_dir
552
	if [ "$raw_part" ]; then
553
		[ -b "$raw_part" ] || {
554
			echo "raw partition $raw_part not found"
555
			return 1
556
		}
557
		kdump_dir=`grep ^path $KDUMP_CONFIG_FILE | cut -d' '  -f2-`
558
		if [ -z "${kdump_dir}" ]; then
559
			coredir="/var/crash/`date +"%Y-%m-%d-%H:%M"`"
560
		else
561
			coredir="${kdump_dir}/`date +"%Y-%m-%d-%H:%M"`"
562
		fi
563
		mkdir -p "$coredir"
564
		[ -d "$coredir" ] || {
565
			echo "failed to create $coredir"
566
			return 1
567
		}
568
		if makedumpfile -R $coredir/vmcore <$raw_part >/dev/null 2>&1; then
569
			# dump found
570
			echo "Dump saved to $coredir/vmcore"
571
			# wipe makedumpfile header
572
			dd if=/dev/zero of=$raw_part bs=1b count=1 2>/dev/null
573
		else
574
			rm -rf "$coredir"
575
		fi
576
	fi
577
	return 0
578
}
579
 
580
get_save_path() {
581
	local _save_path=$(grep "^path" /etc/kdump.conf|awk '{print $2}')
582
	if [ -z "$_save_path" ]; then
583
		_save_path="/var/crash"
584
	fi
585
 
586
	echo $_save_path
587
}
588
 
589
is_dump_target_configured() {
590
    local _target
591
 
592
    _target=$(egrep "^ext[234]|^xfs|^btrfs|^minix|^raw|^ssh|^nfs|^nfs4|^net" /etc/kdump.conf)
593
 
594
     [ -n "$_target" ]
595
}
596
 
597
local_fs_dump_target()
598
{
599
	local _target
600
 
601
	_target=$(egrep "^ext[234]|^xfs|^btrfs|^minix" /etc/kdump.conf)
602
	if [ $? -eq 0 ]; then
603
		echo $_target|awk '{print $2}'
604
	fi
605
}
606
 
607
path_to_be_relabeled() {
608
	local _path _target _mnt="/" _rmnt
609
 
610
	if is_dump_target_configured; then
611
		_target=$(local_fs_dump_target)
612
		if [[ -n "$_target" ]]; then
613
			_mnt=$(findmnt -k -f -n -r -o TARGET $_target)
614
			if [ -z "$_mnt" ]; then
615
				return
616
			fi
617
		else
618
			return
619
		fi
620
	fi
621
 
622
	_path=$(get_save_path)
623
	# if $_path is masked by other mount, we will not relabel it.
624
	# one exception is ! is_dump_target_configure && "$_rmnt" != "$_mnt"
625
	# for this exception see mkdumprd code about [ -z "$USING_METHOD" ]
626
	_rmnt=$(df $_mnt/$_path 2>/dev/null | tail -1 | awk '{ print $NF }')
627
	if [[ "$_rmnt" == "$_mnt" ]] || ! is_dump_target_configured; then
628
		echo $_mnt/$_path
629
	fi
630
}
631
 
632
selinux_relabel()
633
{
634
	local _path _i _attr
635
 
636
	_path=$(path_to_be_relabeled)
637
	if [ -z "$_path" ] || ! [ -d "$_path" ] ; then
638
		return
639
	fi
640
 
641
	for _i in $(find $_path); do
642
		_attr=$(getfattr -m "security.selinux" $_i 2>/dev/null)
643
		if [ -z "$_attr" ]; then
644
			restorecon $_i;
645
		fi
646
	done
647
}
648
 
649
 
650
# Notes about xen support:
651
# pv guests are not supported
652
# hvm guests are supported only when you ensure below items:
653
# 1. Boot guests with either xen_emul_unplug=never or
654
#    xen_emul_unplug=unnecessary.
655
# 2. While recreating kdump initrd xen_netfront and xen_blkfront modules
656
#    are not loaded
657
function start()
658
{
659
	if sestatus 2>/dev/null | grep -q "SELinux status.*enabled"; then
660
		selinux_relabel
661
	fi
662
	save_raw
663
	if [ $? -ne 0 ]; then
664
		echo -n "Starting kdump:"; failure; echo
665
		$LOGGER "failed to start up"
666
		return 1
667
	fi
668
	status
669
	rc=$?
670
	if [ $rc == 2 ]; then
671
		echo -n "Kdump is not supported on this kernel"; failure; echo
672
		return 1;
673
	else
674
		if [ $rc == 0 ]; then
675
			echo -n "Kdump already running"; success; echo
676
			return 0
677
		fi
678
	fi
679
 
680
	check_kernel_parameter
681
	if [ $? != 0 ]; then
682
		echo -n "Starting kdump:"; failure; echo
683
		$LOGGER "No crashkernel parameter specified for running kernel"
684
		return 1
685
	fi
686
 
687
	check_config
688
	if [ $? != 0 ]; then
689
		echo -n "Starting kdump:"; failure; echo
690
		$LOGGER "failed to start up, config file incorrect"
691
		return 1
692
	fi
693
	load_kdump
694
	if [ $? != 0 ]; then
695
		echo -n "Starting kdump:"; failure; echo
696
		$LOGGER "failed to start up"
697
		return 1
698
	fi
699
 
700
	echo -n "Starting kdump:"; success; echo
701
	$LOGGER "started up"
702
}
703
 
704
function stop()
705
{
706
	$KEXEC -p -u 2>/dev/null
707
	if [ $? == 0 ]; then
708
		$LOGGER "kexec: unloaded kdump kernel"
709
		echo -n "Stopping kdump:"; success; echo
710
		$LOGGER "stopped"
711
		return 0
712
	else
713
		$LOGGER "kexec: failed to unload kdump kernel"
714
		echo -n "Stopping kdump:"; failure; echo
715
		$LOGGER "failed to stop"
716
		return 1
717
	fi
718
}
719
 
720
# Other kdump init instances will block in queue, until this one exits.
721
single_instance_lock
722
 
723
case "$1" in
724
  start)
725
	if [ -s /proc/vmcore ]; then
726
		save_core
727
		reboot
728
	else
729
		start
730
	fi
731
	;;
732
  stop)
733
	stop
734
	;;
735
  status)
736
	EXIT_CODE=0
737
	status
738
	case "$?" in
739
	0)
740
		echo "Kdump is operational"
741
		EXIT_CODE=0
742
		;;
743
	1)
744
		echo "Kdump is not operational"
745
		EXIT_CODE=3
746
		;;
747
	2)
748
		echo "Kdump is unsupported on this kernel"
749
		EXIT_CODE=3
750
		;;
751
	esac
752
	exit $EXIT_CODE
753
	;;
754
  restart)
755
	stop
756
	start
757
	;;
758
  condrestart)
759
        EXIT_CODE=1
760
        status
761
        case "$?" in
762
        0)
763
                stop
764
                start
765
                EXIT_CODE=0
766
        ;;
767
        esac
768
        exit $EXIT_CODE
769
	;;
770
  propagate)
771
	propagate_ssh_key
772
	;;
773
  *)
774
	echo $"Usage: $0 {start|stop|status|restart|propagate}"
775
	exit 1
776
esac
777
 
778
exit $?