Subversion Repositories configs

Rev

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