2008-05-09 02:20:19 +00:00
|
|
|
#!/bin/sh
|
2007-10-26 22:44:33 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
2008-04-04 18:33:40 +00:00
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
2008-05-09 02:20:19 +00:00
|
|
|
#=head1 syslog
|
|
|
|
#=head2 syslog command that setsup the syslogd for MS, SV and nodes.
|
|
|
|
# On MS, it makes sure all the xCAT messages goes to /var/log/messages file,
|
|
|
|
# it enables syslogd receving logs from remote machies.
|
|
|
|
# On MS, it sends all the messages to MS,
|
|
|
|
# it enables syslogd receving logs from remote nodes.
|
|
|
|
# On node, it sends all the messages its master.
|
|
|
|
# Input: none, it takes the following environment variables:
|
|
|
|
# OSVER: possible values are sles10, fedora8, redhat5, aix etc.
|
|
|
|
#=cut
|
2008-04-04 18:33:40 +00:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
2008-05-09 02:20:19 +00:00
|
|
|
master=$MASTER
|
|
|
|
conf_file="/etc/syslog.conf"
|
|
|
|
sysconfig="/etc/sysconfig/syslog"
|
|
|
|
init="/etc/init.d/syslog"
|
|
|
|
ng=0
|
|
|
|
isSN=0
|
|
|
|
isLinux=1
|
2008-08-08 20:56:02 +00:00
|
|
|
isRsyslog=0
|
|
|
|
isC3=0
|
|
|
|
|
|
|
|
config_Rsyslog_C3()
|
|
|
|
{
|
|
|
|
isReceiving=0
|
|
|
|
isLocal=$1
|
|
|
|
|
|
|
|
if [ -f /etc/xCATMN ] || [ -f /etc/xCATSN ]
|
|
|
|
then
|
|
|
|
isReceiving=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f $2.XCATORIG ]; then
|
|
|
|
cp -f $2 $2.XCATORIG
|
|
|
|
fi
|
|
|
|
|
|
|
|
grep "xCAT settings" $conf_file
|
|
|
|
if [ $? -gt 0 ]; then
|
|
|
|
echo "# xCAT settings" >> $2
|
|
|
|
#enable to receive remote logging
|
|
|
|
if [ $isReceiving -eq 1 ]; then
|
|
|
|
sed -i 's/^\#\(\s\)*\$ModLoad\(\s\)*imudp.so/\$ModLoad imudp.so/' $2
|
|
|
|
sed -i 's/^\#\(\s\)*\$UDPServerRun/\$UDPServerRun/' $2
|
|
|
|
fi
|
|
|
|
|
|
|
|
#enable to send the logging to master
|
|
|
|
if [ $isLocal -eq 1 ]; then
|
|
|
|
touch /var/log/messages
|
|
|
|
else
|
|
|
|
sed -i 's/^\(\*\..*\)/\#\1/' $2
|
|
|
|
sed -i 's/^\(news\|local7\|mail\|authpriv\|cron\|kern\)\./\#\1\./' $2
|
|
|
|
echo "*.* @$master" >> $2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
2008-05-09 02:20:19 +00:00
|
|
|
|
|
|
|
#echo "NTYPE=$NTYPE,OSVER=$OSVER,OSTYPE=$OSTYPE"
|
|
|
|
|
|
|
|
if [[ $NTYPE = service ]]; then
|
|
|
|
isSN=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $OSTYPE = linux* ]]; then
|
|
|
|
if [[ $OSVER = fedora* ]] || [[ -f /etc/fedora-release ]]; then
|
|
|
|
if [ -e /etc/rsyslog.conf ]; then
|
|
|
|
conf_file="/etc/rsyslog.conf"
|
|
|
|
sysconfig="/etc/sysconfig/rsyslog"
|
|
|
|
init="/etc/init.d/rsyslog"
|
2008-08-08 20:56:02 +00:00
|
|
|
isRsyslog=1
|
2008-05-09 02:20:19 +00:00
|
|
|
fi
|
|
|
|
else
|
2008-05-23 01:43:24 +00:00
|
|
|
if [[ $OSVER = sles* ]] || [[ $OSVER = suse* ]] || [[ -f /etc/SuSE-release ]]; then
|
2008-05-09 02:20:19 +00:00
|
|
|
#find out which syslog is used for SLES, syslog or syslog-ng
|
|
|
|
result=`grep "^SYSLOG_DAEMON=" $sysconfig 2>&1`
|
|
|
|
if [[ $result = *syslog-ng* ]]; then
|
|
|
|
conf_file="/etc/syslog-ng/syslog-ng.conf"
|
|
|
|
ng=1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
sysconfig= #AIX does not have this file
|
|
|
|
isLinux=0;
|
|
|
|
fi
|
|
|
|
|
|
|
|
#echo "isSN=$isSN, isLinux=$isLinux, ng=$ng"
|
|
|
|
#echo "sysconfig=$sysconfig, confgile=$conf_file"
|
|
|
|
|
2008-08-08 20:56:02 +00:00
|
|
|
|
|
|
|
|
2008-05-09 02:20:19 +00:00
|
|
|
#handle sysconfig file to make remote loggling possible
|
|
|
|
if [ $isLinux -eq 1 ] && [ -a $sysconfig ]; then
|
|
|
|
if [[ ! -f "$sysconfig.XCATORIG" ]]; then
|
|
|
|
cp -f $sysconfig $sysconfig.XCATORIG
|
|
|
|
fi
|
2008-08-08 20:56:02 +00:00
|
|
|
|
|
|
|
#check if it is ryslog version 3, it has totally different settings in /etc/syslog.cong
|
|
|
|
if [ $isRsyslog -eq 1 ]; then
|
|
|
|
grep "SYSLOGD_OPTIONS" $sysconfig | grep -e "[\-c 3|\-c3]"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
isC3=1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
#no need to change anything for rsyslog version 3 for /etc/sysconf/rsyslog
|
|
|
|
if [ $isC3 -eq 0 ]; then
|
|
|
|
if [ -f /etc/xCATMN ]; then
|
|
|
|
#on MN: make the syslogd be able to receive remote logs
|
|
|
|
awk '{if($0 ~ /^SYSLOGD_OPTIONS=/) {
|
2008-05-09 02:20:19 +00:00
|
|
|
if ($0 !~ /-r/) {sub(/\"$/, " -r\"", $0)}
|
|
|
|
if (($0 !~ /-m0/) && ($0 !~/-m 0/)) { sub(/\"$/, " -m 0\"", $0)}
|
|
|
|
print $0}
|
|
|
|
else { print $0}}' $sysconfig > $sysconfig.tmp
|
2008-08-08 20:56:02 +00:00
|
|
|
else
|
|
|
|
if [ $isSN -eq 1 ]; then
|
|
|
|
#on SN: make the syslog be able to receive and forward remote logs
|
|
|
|
awk '{if($0 ~ /^SYSLOGD_OPTIONS=/) {
|
2008-05-09 02:20:19 +00:00
|
|
|
if ($0 !~ /-r/) {sub(/\"$/, " -r\"", $0)}
|
|
|
|
if ($0 !~ /-h/) {sub(/\"$/, " -h\"", $0)}
|
|
|
|
if (($0 !~ /-m0/) && ($0 !~/-m 0/)) { sub(/\"$/, " -m 0\"", $0)}
|
|
|
|
print $0}
|
|
|
|
else { print $0}}' $sysconfig > $sysconfig.tmp
|
2008-08-08 20:56:02 +00:00
|
|
|
else
|
|
|
|
##turn off the time marker on all
|
|
|
|
awk '{if($0 ~ /^SYSLOGD_OPTIONS=/) {
|
2008-05-09 02:20:19 +00:00
|
|
|
if (($0 !~ /-m0/) && ($0 !~/-m 0/)) { sub(/\"$/, " -m 0\"", $0)}
|
|
|
|
print $0}
|
|
|
|
else {print $0}}' $sysconfig > $sysconfig.tmp
|
2008-08-08 20:56:02 +00:00
|
|
|
fi
|
2008-05-09 02:20:19 +00:00
|
|
|
fi
|
2008-08-08 20:56:02 +00:00
|
|
|
mv -f $sysconfig.tmp $sysconfig
|
2008-05-09 02:20:19 +00:00
|
|
|
fi
|
|
|
|
fi
|
2008-04-04 18:33:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
#syslog-ng has different way of enabling log forwarding
|
2008-05-09 02:20:19 +00:00
|
|
|
if [ $ng -eq 1 -a $isSN -eq 1 ]; then
|
|
|
|
if [ ! -f $conf_file.XCATORIG ]; then
|
|
|
|
cp -f $conf_file $conf_file.XCATORIG
|
|
|
|
fi
|
|
|
|
sed -i 's/#udp(ip("0.0.0.0/udp(ip("0.0.0.0/' $conf_file
|
|
|
|
fi
|
2008-04-04 18:33:40 +00:00
|
|
|
|
2008-08-08 20:56:02 +00:00
|
|
|
|
|
|
|
|
2008-04-04 18:33:40 +00:00
|
|
|
#now handling where the logs go
|
2008-05-09 02:20:19 +00:00
|
|
|
goLocal=0;
|
|
|
|
if [ -f /etc/xCATMN ]; then
|
|
|
|
goLocal=1
|
|
|
|
else
|
|
|
|
if [ $isSN -eq 1 ]; then
|
2008-05-12 19:28:44 +00:00
|
|
|
if [[ $SVLOGLOCAL -eq 1 ]]; then
|
2008-05-09 02:20:19 +00:00
|
|
|
goLocal=1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2008-08-08 20:56:02 +00:00
|
|
|
if [ $isC3 -eq 1 ]; then
|
|
|
|
config_Rsyslog_C3 $goLocal $conf_file
|
|
|
|
else
|
|
|
|
if [ $goLocal -eq 1 ]; then
|
|
|
|
#making sure all the messages goes to /var/log/messages
|
|
|
|
touch /var/log/messages
|
|
|
|
if [ $ng -eq 0 ]; then
|
|
|
|
if [ ! -f $conf_file.XCATORIG ]; then
|
|
|
|
cp -f $conf_file $conf_file.XCATORIG
|
|
|
|
fi
|
2008-05-09 02:20:19 +00:00
|
|
|
|
2008-08-08 20:56:02 +00:00
|
|
|
grep "xCAT settings" $conf_file
|
|
|
|
if [ $? -gt 0 ]; then
|
|
|
|
if [ $isLinux -eq 0 ]; then # aix
|
|
|
|
echo "# xCAT settings" >> $conf_file
|
|
|
|
echo "*.debug /var/log/messages rotate 1024K files 5" >> $conf_file
|
|
|
|
fi
|
2008-05-09 02:20:19 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
2008-08-08 20:56:02 +00:00
|
|
|
#now make the syslogd fowarding the messages to the the master
|
|
|
|
if [ $ng -eq 1 ]; then
|
|
|
|
if [ ! -f $conf_file.XCATORIG ]; then
|
|
|
|
cp -f $conf_file $conf_file.XCATORIG
|
|
|
|
fi
|
|
|
|
grep "xCAT settings" $conf_file
|
|
|
|
if [ $? -gt 0 ]; then
|
|
|
|
echo "# xCAT settings" >> $conf_file
|
|
|
|
echo "destination loghost { udp(\"$master\"); };" >> $conf_file
|
|
|
|
echo 'log { source(src); destination(loghost); };' >> $conf_file
|
|
|
|
fi
|
2008-05-09 02:20:19 +00:00
|
|
|
else
|
2008-08-08 20:56:02 +00:00
|
|
|
if [ -f $conf_file.XCATORIG ]; then
|
|
|
|
rm -f $conf_file
|
|
|
|
else
|
|
|
|
mv -f $conf_file $conf_file.XCATORIG
|
|
|
|
fi
|
|
|
|
echo "# xCAT settings" > $conf_file
|
|
|
|
if [ $isLinux -eq 0 ]; then
|
|
|
|
echo "*.debug @$master" >> $conf_file
|
|
|
|
else
|
|
|
|
echo "*.* @$master" >> $conf_file
|
|
|
|
fi
|
2008-06-27 16:07:41 +00:00
|
|
|
fi
|
2008-05-09 02:20:19 +00:00
|
|
|
fi
|
|
|
|
fi
|
2008-04-04 18:33:40 +00:00
|
|
|
|
|
|
|
#restart the syslog daemon to take the new conf file settings
|
2008-05-09 02:20:19 +00:00
|
|
|
if [ $isLinux -eq 0 ]; then
|
2008-10-08 15:24:04 +00:00
|
|
|
PARSE_SRC_STATE="-e1d;s/.* \([a-zA-Z0-9]*\)$/\1/"
|
|
|
|
state=$(LC_ALL=C lssrc -s syslogd | LC_ALL=C sed "$PARSE_SRC_STATE")
|
|
|
|
if [[ -n "$state" && "$state" = "active" ]];then
|
|
|
|
stopsrc -s syslogd
|
|
|
|
fi
|
|
|
|
startsrc -s syslogd
|
2008-05-09 02:20:19 +00:00
|
|
|
else
|
|
|
|
$init restart
|
|
|
|
fi
|
2008-04-04 18:33:40 +00:00
|
|
|
|
|
|
|
#keep a record
|
2008-05-09 02:20:19 +00:00
|
|
|
logger -t xcat "Install: syslog setup"
|
2007-10-26 22:44:33 +00:00
|
|
|
exit 0
|