Subversion Repositories configs

Rev

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

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