2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-06-18 20:30:56 +00:00

enable syslog in the stateless initrd, add logs in the xcat dracut module for redhat

This commit is contained in:
yangsong
2015-08-02 04:17:30 -04:00
parent f906b12eed
commit 275089f2d6
7 changed files with 245 additions and 4 deletions

View File

@ -749,9 +749,17 @@ sub mknetboot
my ($host, $ipaddr) = xCAT::NetworkUtils->gethostnameandip($xcatmaster);
if($ipaddr){
#for use in postscript and postbootscript in xcatdsklspost in the rootimg
$kcmdline .=" LOGSERVER=$ipaddr ";
#for use in syslog dracut module in the initrd
$kcmdline .=" syslog.server=$ipaddr syslog.type=rsyslogd syslog.filter=*.* ";
}else{
#for use in postscript and postbootscript in xcatdsklspost in the rootimg
$kcmdline .=" LOGSERVER=$xcatmaster ";
#for use in syslog dracut module in the initrd
$kcmdline .=" syslog.server=$xcatmaster syslog.type=rsyslogd syslog.filter=*.* ";
}
$kcmdline .= " xcatdebugmode=1 ";

View File

@ -0,0 +1,58 @@
#!/bin/sh
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
#
# Licensed under the GPLv2+
#
# Copyright 2008-2010, Red Hat, Inc.
# Harald Hoyer <harald@redhat.com>
PATH=/usr/sbin:/usr/bin:/sbin:/bin
type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
while [ $# -gt 0 ]; do
case "$1" in
--onetime)
onetime="yes";;
--settled)
qname="/settled";;
--finished)
qname="/finished";;
--timeout)
qname="/timeout";;
--online)
qname="/online";;
--unique)
unique="yes";;
--name)
name="$2";shift;;
--env)
env="$2"; shift;;
*)
break;;
esac
shift
done
if [ -z "$unique" ]; then
job="${name}$$"
else
job="${name:-$1}"
job=${job##*/}
fi
exe=$1
shift
[ -x "$exe" ] || exe=$(command -v $exe)
{
[ -n "$onetime" ] && echo '[ -e "$job" ] && rm -f -- "$job"'
[ -n "$env" ] && echo "$env"
echo "$exe $@"
} > "/tmp/$$-${job}.sh"
mv -f "/tmp/$$-${job}.sh" "$hookdir/initqueue${qname}/${job}.sh"
[ -z "$qname" ] && >> $hookdir/initqueue/work
exit 0

View File

@ -0,0 +1,40 @@
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
check() {
# do not add this module by default
return 255
}
depends() {
return 0
}
install() {
local _i
local _installs
if type -P rsyslogd >/dev/null; then
_installs="rsyslogd"
inst_libdir_file rsyslog/lmnet.so rsyslog/imklog.so rsyslog/imuxsock.so
elif type -P syslogd >/dev/null; then
_installs="syslogd"
elif type -P syslog-ng >/dev/null; then
_installs="syslog-ng"
else
derror "Could not find any syslog binary although the syslogmodule" \
"is selected to be installed. Please check."
fi
if [ -n "$_installs" ]; then
inst_multiple cat $_installs
inst_hook cmdline 90 "$moddir/parse-syslog-opts.sh"
inst_hook pre-udev 61 "$moddir/syslog-genrules.sh"
inst_hook cleanup 99 "$moddir/syslog-cleanup.sh"
inst_simple "$moddir/rsyslogd-start.sh" /sbin/rsyslogd-start
inst_simple "$moddir/rsyslogd-stop.sh" /sbin/rsyslogd-stop
mkdir -m 0755 -p ${initdir}/etc/templates
inst_simple "${moddir}/rsyslog.conf" /etc/templates/rsyslog.conf
fi
dracut_need_initqueue
}

View File

@ -0,0 +1,51 @@
#!/bin/sh
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
# Triggered by udev and starts rsyslogd with bootparameters
type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
rsyslog_config() {
local server=$1
shift
local syslog_template=$1
shift
local filters=$*
local filter=
local confline=
cat $syslog_template
# for filter in $filters; do
# echo "${filter} @${server}"
# done
if [ -n "$filters" ];then
confline="${filters}";
else
confline="*.*"
fi
if [ -n "$server" ];then
confline="$confline @${server}"
else
confline="$confline /var/log/messages"
fi
echo "$confline"
# echo "*.* /tmp/syslog"
}
read server < /tmp/syslog.server
read filters < /tmp/syslog.filters
[ -z "$filters" ] && filters="kern.*"
read conf < /tmp/syslog.conf
[ -z "$conf" ] && conf="/etc/rsyslog.conf" && echo "$conf" > /tmp/syslog.conf
template=/etc/templates/rsyslog.conf
if [ -n "$server" ]; then
rsyslog_config "$server" "$template" "$filters" > $conf
rsyslogd -i /var/run/syslogd.pid
fi

View File

@ -0,0 +1,34 @@
#!/bin/sh
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
# Creates the syslog udev rules to be triggered when interface becomes online.
type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
detect_syslog() {
syslogtype=""
if [ -e /sbin/rsyslogd ]; then
syslogtype="rsyslogd"
elif [ -e /sbin/syslogd ]; then
syslogtype="syslogd"
elif [ /sbin/syslog-ng ]; then
syslogtype="syslog-ng"
else
warn "Could not find any syslog binary although the syslogmodule is selected to be installed. Please check."
fi
echo "$syslogtype"
[ -n "$syslogtype" ]
}
read syslogtype < /tmp/syslog.type
if [ -z "$syslogtype" ]; then
syslogtype=$(detect_syslog)
echo $syslogtype > /tmp/syslog.type
fi
if [ -e "/sbin/${syslogtype}-start" ]; then
#printf 'ACTION=="online", SUBSYSTEM=="net", RUN+="/sbin/initqueue --onetime /sbin/'${syslogtype}'-start $env{INTERFACE}"\n' > /etc/udev/rules.d/70-syslog.rules
#printf 'ATTR{operstate}!="down", SUBSYSTEM=="net", RUN+="/sbin/initqueue --onetime /sbin/'${syslogtype}'-start $env{INTERFACE}"\n' > /etc/udev/rules.d/70-syslog.rules
/sbin/initqueue --online --onetime /sbin/${syslogtype}-start
else
warn "syslog-genrules: Could not find binary to start syslog of type \"$syslogtype\". Syslog will not be started."
fi

View File

@ -1,4 +1,6 @@
#!/bin/sh
logger -t xcat -p debug "running xcatroot...."
NEWROOT=$3
RWDIR=.statelite
XCATMASTER=$XCAT
@ -17,7 +19,11 @@ XCATIPORT="3002"
fi
logger -t xcat -p debug "MASTER=$MASTER XCATIPORT=$XCATIPORT"
if [ $NODESTATUS -ne 0 ];then
logger -t xcat -p debug "nodestatus: netbooting,reporting..."
/tmp/updateflag $MASTER $XCATIPORT "installstatus netbooting"
fi
@ -26,8 +32,10 @@ if [ ! -z "$imgurl" ]; then
NFS=0
FILENAME=${imgurl##*/}
while [ ! -r "$FILENAME" ]; do
logger -t xcat -p debug "downloading $imgurl...."
echo Getting $imgurl...
if ! wget $imgurl; then
logger -t xcat -p debug "downloading $imgurl failed,retrying...."
rm -f $FILENAME
sleep 27
fi
@ -58,6 +66,7 @@ if [ -r /rootimg.sfs ]; then
mount --move /ro $NEWROOT/ro
mount --move /rw $NEWROOT/rw
elif [ -r /rootimg.gz ]; then
logger -t xcat -p debug "rootimg.gz downloaded,setting up RAM-root tmpfs...."
echo Setting up RAM-root tmpfs.
if [ -z $rootlimit ];then
mount -t tmpfs -o mode=755 rootfs $NEWROOT
@ -66,6 +75,7 @@ elif [ -r /rootimg.gz ]; then
fi
cd $NEWROOT
logger -t xcat -p debug "Extracting root filesystem:"
echo -n "Extracting root filesystem:"
if [ -x /bin/cpio ]; then
gzip -cd /rootimg.gz |/bin/cpio -idum
@ -73,6 +83,7 @@ elif [ -r /rootimg.gz ]; then
gzip -cd /rootimg.gz |cpio -idum
fi
$NEWROOT/etc/init.d/localdisk
logger -t xcat -p debug "Done...."
echo Done
elif [ -r /rootimg-statelite.gz ]; then
echo Setting up RAM-root tmpfs for statelite mode.
@ -197,11 +208,18 @@ elif [ -r /rootimg-statelite.gz ]; then
mount -n --bind /sys $NEWROOT/sys
else
logger -t xcat -p debug "Failed to download image, panicing in 5..."
echo -n Failed to download image, panicing in 5...
for i in 4 3 2 1 0; do
/bin/sleep 1
logger -t xcat -p debug "$i..."
echo -n $i...
done
done
logger -t xcat -p debug "You're dead. rpower nodename reset to play again."
logger -t xcat -p debug "* Did you packimage with -m cpio, -m squashfs, or -m nfs?"
logger -t xcat -p debug "* If using -m squashfs did you include aufs.ko with geninitrd? e.g.: -n tg3,squashfs,aufs,loop"
logger -t xcat -p debug "If using -m nfs did you export NFS and sync rootimg? And did you include the aufs and nfs modules in the proper order: e.g.: -n tg3,aufs,loop,sunrpc,lockd,nfs_acl,nfs"
echo
echo "You're dead. rpower nodename reset to play again.
@ -242,6 +260,7 @@ if [ -z $STATEMNT ]; then
netif=${lf#*.}
netif=${netif%.*}
cp $lf "$NEWROOT/var/lib/dhclient/dhclient-$netif.leases"
logger -t xcat -p debug "saving $NEWROOT/var/lib/dhclient/dhclient-$netif.leases"
done
if [ ! -z "$ifname" ]; then
@ -257,10 +276,13 @@ if [ -z $STATEMNT ]; then
ETHX=$(getdevfrommac $MACX)
fi
if [ ! -z "$MACX" ] && [ ! -z "$ETHX" ]; then
if [ ! -e $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX ]; then
logger -t xcat -p debug "creating $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX"
touch $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
fi
logger -t xcat -p debug "writing $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX: DEVICE=$ETHX;BOOTPROTO=dhcp;HWADDR=$MACX;ONBOOT=yes"
echo "DEVICE=$ETHX" > $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
echo "BOOTPROTO=dhcp" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
echo "HWADDR=$MACX" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
@ -268,12 +290,15 @@ if [ -z $STATEMNT ]; then
fi
fi
logger -t xcat -p debug "saving $NEWROOT/etc/resolv.conf"
cp /etc/resolv.conf "$NEWROOT/etc/"
if [ -d "$NEWROOT/etc/sysconfig" -a ! -e "$NEWROOT/etc/sysconfig/selinux" ]; then
logger -t xcat -p debug "disable selinux ..."
echo "SELINUX=disabled" >> "$NEWROOT/etc/sysconfig/selinux"
fi
logger -t xcat -p debug "exiting xcatroot..."
# inject new exit_if_exists
echo 'settle_exit_if_exists="--exit-if-exists=/dev/root"; rm "$job"' > $hookdir/initqueue/xcat.sh
# force udevsettle to break

View File

@ -582,11 +582,13 @@ foreach my $dn (@ndrivers) {
}
@ndrivers = @fulldrivers;
my $dracutver;
unlink "/tmp/genimage.$$.yum.conf";
if ( (-d "$rootimg_dir/usr/share/dracut") or (-d "$rootimg_dir/usr/lib/dracut") ) {
$dracutmode = 1;
# get dracut version
my $dracutver = `rpm --root $rootimg_dir -qi dracut | grep Version | awk -F' ' '{print \$3}'`;
$dracutver = `rpm --root $rootimg_dir -qi dracut | grep Version | awk -F' ' '{print \$3}'`;
chomp($dracutver);
if ($dracutver =~ /^\d\d\d$/) {
if ($dracutver >= "033") {
@ -826,6 +828,27 @@ sub mkinitrd_dracut {
$dracutmoduledir="$rootimg_dir/usr/lib/dracut/modules.d/";
}
if ($dracutver > "033") {
my $perm = (stat("$fullpath/$dracutdir/patch/initqueue.sh"))[2];
cp("$fullpath/$dracutdir/patch/initqueue.sh", $dracutmoduledir."99base/");
chmod($perm&07777, $dracutmoduledir."99base/"."initqueue.sh");
$perm = (stat("$fullpath/$dracutdir/patch/module-setup.sh"))[2];
cp("$fullpath/$dracutdir/patch/module-setup.sh", $dracutmoduledir."98syslog/");
chmod($perm&07777, $dracutmoduledir."98syslog/"."module-setup.sh");
$perm = (stat("$fullpath/$dracutdir/patch/rsyslogd-start.sh"))[2];
cp("$fullpath/$dracutdir/patch/rsyslogd-start.sh", $dracutmoduledir."98syslog/");
chmod($perm&07777, $dracutmoduledir."98syslog/"."rsyslogd-start.sh");
$perm = (stat("$fullpath/$dracutdir/patch/syslog-genrules.sh"))[2];
cp("$fullpath/$dracutdir/patch/syslog-genrules.sh", $dracutmoduledir."98syslog/");
chmod($perm&07777, $dracutmoduledir."98syslog/"."syslog-genrules.sh");
}
my $dracutmpath = $dracutmoduledir."97xcat/";
mkpath($dracutmpath);
@ -910,10 +933,10 @@ sub mkinitrd_dracut {
# update etc/dracut.conf
open($DRACUTCONF, '>', "$rootimg_dir/etc/dracut.conf");
if (-d glob($dracutmoduledir."[0-9]*fadump")){
print $DRACUTCONF qq{dracutmodules+="xcat nfs base network kernel-modules fadump"\n};
print $DRACUTCONF qq{dracutmodules+="xcat nfs base network kernel-modules fadump syslog"\n};
}
else{
print $DRACUTCONF qq{dracutmodules+="xcat nfs base network kernel-modules"\n};
print $DRACUTCONF qq{dracutmodules+="xcat nfs base network kernel-modules syslog"\n};
}
print $DRACUTCONF qq{add_drivers+="$add_drivers"\n};
close $DRACUTCONF;
@ -930,6 +953,8 @@ sub mkinitrd_dracut {
$additional_options= qq{--include /tmp/cmdline /etc/cmdline};
}
# force the dracut run in non-hostonly mode for dracut higher than version 033
if ($dracutver > "033") {
$additional_options .= " -N";