Subversion Repositories configs

Rev

Rev 6 | Rev 33 | 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
 
8 - 262
		# changes in CLUSTER_CONFIG_FILE should be monitored only if fence_kdump
263
		# is not configured using fence_kdump_nodes option in /etc/kdump.conf
264
		# and fence_kdump is configured in Pacemaker cluster
265
		if ! grep -q ^fence_kdump_nodes /etc/kdump.conf \
266
			&& [ -f "$CLUSTER_CONFIG_FILE" ] \
267
			&& grep -q fence_kdump "$CLUSTER_CONFIG_FILE"
3 - 268
		then
269
		    files="$files $CLUSTER_CONFIG_FILE"
270
		    if [ -f "$FENCE_KDUMP_CONFIG" ]; then
271
			files="$files $FENCE_KDUMP_CONFIG"
272
		    fi
273
		fi
274
 
275
		for file in $files; do
276
			time_stamp=0
277
			if [ -f "$file" ]; then
278
				time_stamp=`stat -c "%Y" $file`
279
			else
280
				modified_files="$modified_files $file"
281
				continue
282
			fi
283
			if [ "$time_stamp" -gt "$image_time" ]; then
284
				modified_files="$modified_files $file"
285
			fi
286
		done
287
	fi
288
 
289
        if [ -n "$FORCE_REBUILD" -a "$modified_files"!=" " ]
290
        then
291
                modified_files="force_rebuild"
292
        fi
293
 
294
        if [ -n "$modified_files" -a "$modified_files"!=" " ]; then
295
                if [ "$modified_files" != "force_rebuild" ]
296
                then
297
                        echo "Detected change(s) the following file(s):"
298
                        echo -n "  "; echo "$modified_files" | sed 's/\s/\n  /g'
299
                fi
300
 
301
		if ! check_xen_hvm_nopv_premkdumprd; then
302
			echo "hvm guest with pv drivers is not supported."
303
			exit 1
304
		fi
305
 
306
                echo "Rebuilding $kdump_initrd"
307
		$MKDUMPRD $kdump_initrd $kdump_kver
308
                if [ $? != 0 ]; then
309
                        echo "Failed to run mkdumprd"
310
                        $LOGGER "mkdumprd: failed to make kdump initrd"
311
                        return 1
312
                fi
313
        fi
314
 
315
	#double check the xen_*front modules are not included for xen hvm
316
	if in_xen_hvm_guest; then
317
		if $(lsinitrd $kdump_initrd|grep -q "xen_.*front.ko"); then
318
			echo "Found xen pv drivers in kdump initrd"
319
			exit 1
320
		fi
321
	fi
322
        return 0
323
}
324
 
325
# This function check iomem and determines if we have more than
326
# 4GB of ram available. Returns 1 if we do, 0 if we dont
327
function need_64bit_headers()
328
{
329
    return `tail -n 1 /proc/iomem | awk '{ split ($1, r, "-"); \
330
    print (strtonum("0x" r[2]) > strtonum("0xffffffff")); }'`
331
}
332
 
333
function avoid_cdrom_drive()
334
{
335
	local DRIVE=""
336
	local MEDIA=""
337
	local IDE_DRIVES=(`echo hd{a,b,c,d}`)
338
	local COUNTER="0"
339
 
340
	for DRIVE in ${IDE_DRIVES[@]}
341
	do
342
		if ! $(echo "$KDUMP_COMMANDLINE" |grep -q "$DRIVE=");then
343
			if [ -f /proc/ide/$DRIVE/media ];then
344
				MEDIA=$(cat /proc/ide/$DRIVE/media)
345
				if [ x"$MEDIA" == x"cdrom" ]; then
346
					KDUMP_IDE_NOPROBE_COMMANDLINE="$KDUMP_IDE_NOPROBE_COMMANDLINE $DRIVE=cdrom"
347
					COUNTER=$(($COUNTER+1))
348
				fi
349
			fi
350
		else
351
			KDUMP_IDE_NOPROBE_COMMANDLINE="$KDUMP_IDE_NOPROBE_COMMANDLINE $DRIVE=noprobe"
352
		fi
353
	done
354
	# We don't find cdrom drive.
355
	if [ $COUNTER -eq 0 ]; then
356
		KDUMP_IDE_NOPROBE_COMMANDLINE=""
357
	fi
358
}
359
 
360
function check_kernel_parameter()
361
{
362
	if [ -z "$KDUMP_COMMANDLINE" ]
363
	then
364
		KDUMP_COMMANDLINE=`cat /proc/cmdline`
365
	fi
366
 
367
	MEM_RESERVED=`cat /sys/kernel/kexec_crash_size`
368
 
369
	if [ $MEM_RESERVED -eq 0 ]
370
	then
371
		return 1
372
	else
373
		return 0
374
	fi
375
}
376
 
377
# Load the kdump kerel specified in /etc/sysconfig/kdump
378
# If none is specified, try to load a kdump kernel with the same version
379
# as the currently running kernel.
380
function load_kdump()
381
{
382
	ARCH=`uname -m`
383
 
384
	# Get the approx amount of ram the kernel is using in Kb
385
	KMEMINUSE=`awk '/Slab:.*/ {print $2}' /proc/meminfo`
386
	# Convert the reserved ram amount to Kb
387
	MEM_RESERVED=`dc -e"$MEM_RESERVED 1024 / p"`
388
 
389
	# Take 70% of the reserved value rounding up to the nearest integer
390
	MEM_RESERVED=`dc -e"$MEM_RESERVED .7 * 10 * 10 / p"`
391
 
392
	#On x86, we are using nr_cpus=1, so the following check is not necessary.
393
	if [ "$ARCH" != "i686" -a "$ARCH" != "i386" -a "$ARCH" != "x86_64" ]
394
	then
395
		#Check if the KMEMINUSE is greater than MEM_RESERVED
396
		# This indicates that the currently runnign kernel is using
397
		# 70% of the amount of memory that we have reserved for kdump
398
		# we should issue a warning here indicating that the user may
399
		# want to increase the amount of reserved ram on the system
400
		if [ $KMEMINUSE -gt $MEM_RESERVED ]
401
		then
402
			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"
403
			warning
404
			echo
405
		fi
406
	fi
407
 
408
	if [ "$ARCH" == "i686" -o "$ARCH" == "i386" ]
409
	then
410
 
411
		need_64bit_headers
412
		if [ $? == 1 ]
413
		then
414
			FOUND_ELF_ARGS=`echo $KEXEC_ARGS | grep elf32-core-headers`
415
			if [ -n "$FOUND_ELF_ARGS" ]
416
			then
417
				echo -n "Warning: elf32-core-headers overrides correct elf64 setting"
418
				warning
419
				echo
420
			else
421
				KEXEC_ARGS="$KEXEC_ARGS --elf64-core-headers"
422
			fi
423
		else
424
			FOUND_ELF_ARGS=`echo $KEXEC_ARGS | grep elf64-core-headers`
425
			if [ -z "$FOUND_ELF_ARGS" ]
426
			then
427
				KEXEC_ARGS="$KEXEC_ARGS --elf32-core-headers"
428
			fi
429
		fi
430
	fi
431
 
432
	if [ -f /sys/firmware/efi/systab ]
433
	then
434
		if grep -q '^ACPI20=' /sys/firmware/efi/systab
435
		then
436
			acpi_addr=$(awk -F'=' '/^ACPI20=/ {print $2}' /sys/firmware/efi/systab)
437
		else
438
			acpi_addr=$(awk -F'=' '/^ACPI=/ {print $2}' /sys/firmware/efi/systab)
439
		fi
440
		KDUMP_COMMANDLINE="$KDUMP_COMMANDLINE noefi acpi_rsdp=$acpi_addr"
441
	fi
442
 
443
	if echo "$KDUMP_COMMANDLINE_APPEND" | grep -q nr_cpus;
444
	then
445
		ver=`uname -r`
446
		maj=`echo $ver | cut -d'-' -f1`
447
		min=`echo $ver | cut -d'-' -f2`
448
		min=${min%%.*}
449
		if [ "$maj" = "2.6.32" ] && [ $min -lt 171 ]
450
		then
451
			echo "Your kernel is old, please use maxcpus=1 instead of nr_cpus=1"
452
			return 1
453
		fi
454
	fi
455
 
6 - 456
	KDUMP_COMMANDLINE=`prepare_cmdline`
457
 
3 - 458
	if ! grep -q /sys/kernel/debug /proc/mounts;
459
	then
460
		mount -t debugfs debug /sys/kernel/debug
461
		MNTDEBUG=/sys/kernel/debug
462
	fi
6 - 463
 
3 - 464
	$KEXEC $KEXEC_ARGS $standard_kexec_args \
465
		--command-line="$KDUMP_COMMANDLINE" \
466
		--initrd=$kdump_initrd $kdump_kernel 2>/dev/null
467
	if [ $? == 0 ]; then
468
		umount $MNTDEBUG 2>/dev/null
469
		$LOGGER "kexec: loaded kdump kernel"
470
		return 0
471
	else
472
		umount $MNTDEBUG 2>/dev/null
473
		$LOGGER "kexec: failed to load kdump kernel"
474
		return 1
475
	fi
476
}
477
 
478
function propagate_ssh_key()
479
{
480
	while read config_opt config_val; do
481
		case "$config_opt" in
482
		sshkey)
483
			SSH_KEY_LOCATION="$config_val"
484
			;;
485
		*)
486
			;;
487
		esac
488
	done < $KDUMP_CONFIG_FILE
489
 
490
	local KEYFILE=$SSH_KEY_LOCATION
491
	local errmsg="Failed to propagate ssh key"
492
 
493
	#make sure they've configured kdump.conf for ssh dumps
494
	local SSH_TARGET=`awk '/^\ *net.*@.*$/ {print $0}' $KDUMP_CONFIG_FILE`
495
	[ -z "$SSH_TARGET" ] && SSH_TARGET=`awk '/^\ *ssh.*@.*$/ {print $0}' $KDUMP_CONFIG_FILE`
496
	if [ -z "$SSH_TARGET" ]; then
497
		echo "No ssh config specified in $KDUMP_CONFIG_FILE.  Can't propagate"
498
		$LOGGER "$errmsg, no ssh config specified in $KDUMP_CONFIG_FILE"
499
		exit 1
500
	fi
501
 
502
	#Check to see if we already created key, if not, create it.
503
	if [ -f $KEYFILE ]; then
504
		echo "Using existing keys..."
505
	else
506
		echo -n "Generating new ssh keys... "
507
		/usr/bin/ssh-keygen -t rsa -f $KEYFILE -N "" 2>&1 > /dev/null
508
		echo "done."
509
	fi
510
 
511
	#now find the target ssh user and server to contact.
512
	SSH_USER=`echo $SSH_TARGET | cut -d\  -f2 | cut -d@ -f1`
513
	SSH_SERVER=`echo $SSH_TARGET | sed -e's/\(.*@\)\(.*$\)/\2/'`
514
 
515
	#now send the found key to the found server
516
	ssh-copy-id -i $KEYFILE $SSH_USER@$SSH_SERVER &>/dev/null
517
	RET=$?
518
	if [ $RET == 0 ]; then
519
		echo $KEYFILE has been added to ~$SSH_USER/.ssh/authorized_keys on $SSH_SERVER
520
		$LOGGER "propagated ssh key (ssh server: $SSH_SERVER)"
521
		return 0
522
	else
523
		echo $KEYFILE failed in transfer to $SSH_SERVER
524
		$LOGGER "$errmsg, unable to transfer $KEYFILE to $SSH_SERVER"
525
		exit 1
526
	fi
527
 
528
}
529
 
530
function status()
531
{
532
	if [ ! -e /sys/kernel/kexec_crash_loaded ]
533
	then
534
		return 2
535
	fi
536
 
537
	if in_xen_pv_guest; then
538
		return 2
539
	elif in_xen_hvm_guest && ! grep -q -e xen_emul_unplug=never -e xen_emul_unplug=unnecessary /proc/cmdline; then
540
		echo 'kdump only supported on xen hvm guests booted with xen_emul_unplug=never or xen_emul_unplug=unnecessary'
541
		return 2
542
	fi
543
 
544
	rc=`cat /sys/kernel/kexec_crash_loaded`
545
	if [ $rc == 1 ]; then
546
		return 0
547
	else
548
		return 1
549
	fi
550
}
551
 
552
function save_raw()
553
{
554
	local raw_part=$(awk '$1 ~ /^raw$/ { print $2; }' $KDUMP_CONFIG_FILE)
555
	local kdump_dir
556
	if [ "$raw_part" ]; then
557
		[ -b "$raw_part" ] || {
558
			echo "raw partition $raw_part not found"
559
			return 1
560
		}
561
		kdump_dir=`grep ^path $KDUMP_CONFIG_FILE | cut -d' '  -f2-`
562
		if [ -z "${kdump_dir}" ]; then
563
			coredir="/var/crash/`date +"%Y-%m-%d-%H:%M"`"
564
		else
565
			coredir="${kdump_dir}/`date +"%Y-%m-%d-%H:%M"`"
566
		fi
567
		mkdir -p "$coredir"
568
		[ -d "$coredir" ] || {
569
			echo "failed to create $coredir"
570
			return 1
571
		}
572
		if makedumpfile -R $coredir/vmcore <$raw_part >/dev/null 2>&1; then
573
			# dump found
574
			echo "Dump saved to $coredir/vmcore"
575
			# wipe makedumpfile header
576
			dd if=/dev/zero of=$raw_part bs=1b count=1 2>/dev/null
577
		else
578
			rm -rf "$coredir"
579
		fi
580
	fi
581
	return 0
582
}
583
 
584
get_save_path() {
585
	local _save_path=$(grep "^path" /etc/kdump.conf|awk '{print $2}')
586
	if [ -z "$_save_path" ]; then
587
		_save_path="/var/crash"
588
	fi
589
 
590
	echo $_save_path
591
}
592
 
593
is_dump_target_configured() {
594
    local _target
595
 
596
    _target=$(egrep "^ext[234]|^xfs|^btrfs|^minix|^raw|^ssh|^nfs|^nfs4|^net" /etc/kdump.conf)
597
 
598
     [ -n "$_target" ]
599
}
600
 
601
local_fs_dump_target()
602
{
603
	local _target
604
 
605
	_target=$(egrep "^ext[234]|^xfs|^btrfs|^minix" /etc/kdump.conf)
606
	if [ $? -eq 0 ]; then
607
		echo $_target|awk '{print $2}'
608
	fi
609
}
610
 
611
path_to_be_relabeled() {
612
	local _path _target _mnt="/" _rmnt
613
 
614
	if is_dump_target_configured; then
615
		_target=$(local_fs_dump_target)
616
		if [[ -n "$_target" ]]; then
617
			_mnt=$(findmnt -k -f -n -r -o TARGET $_target)
618
			if [ -z "$_mnt" ]; then
619
				return
620
			fi
621
		else
622
			return
623
		fi
624
	fi
625
 
626
	_path=$(get_save_path)
627
	# if $_path is masked by other mount, we will not relabel it.
628
	# one exception is ! is_dump_target_configure && "$_rmnt" != "$_mnt"
629
	# for this exception see mkdumprd code about [ -z "$USING_METHOD" ]
630
	_rmnt=$(df $_mnt/$_path 2>/dev/null | tail -1 | awk '{ print $NF }')
631
	if [[ "$_rmnt" == "$_mnt" ]] || ! is_dump_target_configured; then
632
		echo $_mnt/$_path
633
	fi
634
}
635
 
636
selinux_relabel()
637
{
638
	local _path _i _attr
639
 
640
	_path=$(path_to_be_relabeled)
641
	if [ -z "$_path" ] || ! [ -d "$_path" ] ; then
642
		return
643
	fi
644
 
645
	for _i in $(find $_path); do
646
		_attr=$(getfattr -m "security.selinux" $_i 2>/dev/null)
647
		if [ -z "$_attr" ]; then
648
			restorecon $_i;
649
		fi
650
	done
651
}
652
 
653
 
654
# Notes about xen support:
655
# pv guests are not supported
656
# hvm guests are supported only when you ensure below items:
657
# 1. Boot guests with either xen_emul_unplug=never or
658
#    xen_emul_unplug=unnecessary.
659
# 2. While recreating kdump initrd xen_netfront and xen_blkfront modules
660
#    are not loaded
661
function start()
662
{
663
	if sestatus 2>/dev/null | grep -q "SELinux status.*enabled"; then
664
		selinux_relabel
665
	fi
666
	save_raw
667
	if [ $? -ne 0 ]; then
668
		echo -n "Starting kdump:"; failure; echo
669
		$LOGGER "failed to start up"
670
		return 1
671
	fi
672
	status
673
	rc=$?
674
	if [ $rc == 2 ]; then
675
		echo -n "Kdump is not supported on this kernel"; failure; echo
676
		return 1;
677
	else
678
		if [ $rc == 0 ]; then
679
			echo -n "Kdump already running"; success; echo
680
			return 0
681
		fi
682
	fi
683
 
684
	check_kernel_parameter
685
	if [ $? != 0 ]; then
686
		echo -n "Starting kdump:"; failure; echo
687
		$LOGGER "No crashkernel parameter specified for running kernel"
688
		return 1
689
	fi
690
 
691
	check_config
692
	if [ $? != 0 ]; then
693
		echo -n "Starting kdump:"; failure; echo
694
		$LOGGER "failed to start up, config file incorrect"
695
		return 1
696
	fi
697
	load_kdump
698
	if [ $? != 0 ]; then
699
		echo -n "Starting kdump:"; failure; echo
700
		$LOGGER "failed to start up"
701
		return 1
702
	fi
703
 
704
	echo -n "Starting kdump:"; success; echo
705
	$LOGGER "started up"
706
}
707
 
708
function stop()
709
{
710
	$KEXEC -p -u 2>/dev/null
711
	if [ $? == 0 ]; then
712
		$LOGGER "kexec: unloaded kdump kernel"
713
		echo -n "Stopping kdump:"; success; echo
714
		$LOGGER "stopped"
715
		return 0
716
	else
717
		$LOGGER "kexec: failed to unload kdump kernel"
718
		echo -n "Stopping kdump:"; failure; echo
719
		$LOGGER "failed to stop"
720
		return 1
721
	fi
722
}
723
 
724
# Other kdump init instances will block in queue, until this one exits.
725
single_instance_lock
726
 
727
case "$1" in
728
  start)
729
	if [ -s /proc/vmcore ]; then
730
		save_core
731
		reboot
732
	else
733
		start
734
	fi
735
	;;
736
  stop)
737
	stop
738
	;;
739
  status)
740
	EXIT_CODE=0
741
	status
742
	case "$?" in
743
	0)
744
		echo "Kdump is operational"
745
		EXIT_CODE=0
746
		;;
747
	1)
748
		echo "Kdump is not operational"
749
		EXIT_CODE=3
750
		;;
751
	2)
752
		echo "Kdump is unsupported on this kernel"
753
		EXIT_CODE=3
754
		;;
755
	esac
756
	exit $EXIT_CODE
757
	;;
758
  restart)
759
	stop
760
	start
761
	;;
762
  condrestart)
763
        EXIT_CODE=1
764
        status
765
        case "$?" in
766
        0)
767
                stop
768
                start
769
                EXIT_CODE=0
770
        ;;
771
        esac
772
        exit $EXIT_CODE
773
	;;
774
  propagate)
775
	propagate_ssh_key
776
	;;
777
  *)
778
	echo $"Usage: $0 {start|stop|status|restart|propagate}"
779
	exit 1
780
esac
781
 
782
exit $?