2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-22 11:42:05 +00:00

Merge pull request #198 from immarvin/onsyslog

fix defect # 197 and #196 on "syslog" postscript
This commit is contained in:
Xiaopeng Wang 2015-09-29 13:23:39 +08:00
commit ceb9be565d

View File

@ -13,7 +13,6 @@
# OSVER: possible values are sles10, fedora8, redhat5, aix etc.
#=cut
#-------------------------------------------------------------------------------
if [ "$(uname -s|tr 'A-Z' 'a-z')" = "linux" ];then
str_dir_name=`dirname $0`
. $str_dir_name/xcatlib.sh
@ -85,42 +84,32 @@ config_Rsyslog_C3()
grep "xCAT settings" $conf_file 2>&1 1> /dev/null
if [ $? -eq 0 ]; then
sed "/# xCAT settings/,$ d" $2 >/tmp/sed.tmp
cat /tmp/sed.tmp >$2
#remove the previous syslog rule generated by xCAT
sed -i "/# xCAT settings/,$ d" $2
fi
echo "# xCAT settings" >> $2
#enable to receive remote logging
if [ $isReceiving -eq 1 ]; then
sed 's/^\#\(\s\)*\$ModLoad\(\s\)*imudp/\$ModLoad imudp/' $2 >/tmp/sed.tmp
cat /tmp/sed.tmp >$2
sed 's/^\#\(\s\)*\$UDPServerRun/\$UDPServerRun/' $2 >/tmp/sed.tmp
cat /tmp/sed.tmp >$2
sed -i -e '/# Provides TCP syslog reception/,/#### GLOBAL DIRECTIVES ####/c \
# Provides TCP syslog reception \
$ModLoad imtcp \
$InputTCPServerRun 514 \
#### GLOBAL DIRECTIVES #### \
' /etc/rsyslog.conf
#listen on the udp and tcp port to receive the remote logs
sed -i 's/^\#\(\s\)*\$ModLoad\(\s\)*imudp/\$ModLoad imudp/
s/^\#\(\s\)*\$UDPServerRun/\$UDPServerRun/;
s/#\$ModLoad imtcp/\$ModLoad imtcp/;
s/#\$InputTCPServerRun 514/\$InputTCPServerRun 514/' $2
fi
#enable to send the logging to master
if [ $isLocal -eq 1 ]; then
#enable the MN to log all the logs from CN and MN itself
sed 's/\(^[^\#].*\/var\/log\/messages\)/\#\1/g' $2 >/tmp/sed.tmp
cat /tmp/sed.tmp >$2
#enable the MN to log all the logs from CN and MN itself
sed -i 's/\(^[^\#].*\/var\/log\/messages\)/\#\1/g' $2
echo "*.debug /var/log/messages" >> $2
touch /var/log/messages
if ( pmatch $OSVER "ubuntu*" ) || ( is_lsb_ubuntu ) || ( pmatch $OSVER "debian*" ); then
chown syslog:adm /var/log/messages
fi
else
sed 's/^\(\*\..*\)/\#\1/' $2 >/tmp/sed.tmp
cat /tmp/sed.tmp >$2
sed 's/^\(news\|local7\|mail\|authpriv\|cron\|kern\)\./\#\1\./' $2 >/tmp/sed.tmp
cat /tmp/sed.tmp >$2
sed -i 's/^\(\*\..*\)/\#\1/;
s/^\(news\|local7\|mail\|authpriv\|cron\|kern\)\./\#\1\./' $2
echo "*.* @$master" >> $2
fi
}
@ -156,6 +145,18 @@ config_rsyslog_V8()
fi
fi
# check if already an entry by xCAT. If so, we need to replace it
grep "xCAT settings" $conf_file 2>&1 1> /dev/null
if [ $? -eq 0 ]; then
sed -i "/# xCAT settings/,$ d" $conf_file
fi
grep "xCAT settings" $remoteconf 2>&1 1> /dev/null
if [ $? -eq 0 ]; then
sed -i "/# xCAT settings/,$ d" $remoteconf
fi
if [ $goLocal -eq 1 ]; then
#logging is local, do not forward
#making sure all the messages goes to /var/log/messages
@ -168,19 +169,22 @@ config_rsyslog_V8()
cp -f $conf_file $conf_file.XCATORIG
fi
grep "xCAT settings" $conf_file 2>&1 1> /dev/null
if [ $? -eq 0 ]; then
sed "/# xCAT settings/,$ d" $conf_file >/tmp/sed.tmp
cat /tmp/sed.tmp >$conf_file
fi
#comment out the rules which will write logs to /var/log/messages
# to prevent duplicate logs after "syslog" script is run
sed -i '/^[^#].*\/var\/log\/messages/s/^/#/' $conf_file
echo "# xCAT settings" >> $conf_file
echo "*.debug /var/log/messages" >> $conf_file
# Need to uncomment the lines $ModLoad imudp.so and $UDPServerRun 514,
# to make the MN be able to receive syslog from remote hosts
if [ -f "$remoteconf" ]; then
sed -i 's/#\$ModLoad imudp.so/\$ModLoad imudp.so/' $remoteconf
sed -i 's/#\$UDPServerRun 514/\$UDPServerRun 514/' $remoteconf
##listen on tcp and udp port to enable receiving the xcat debug logs
##forwarded via tcp/udp protocol
sed -i 's/#\$ModLoad imudp.so/\$ModLoad imudp.so/;
s/#\$UDPServerRun 514/\$UDPServerRun 514/;
s/#\$ModLoad imtcp.so/\$ModLoad imtcp.so/;
s/#\$InputTCPServerRun <port>/\$InputTCPServerRun 514/' $remoteconf
fi
else
# not logging local, forward logging
@ -188,13 +192,17 @@ config_rsyslog_V8()
if [ ! -f $remoteconf.XCATORIG ]; then
cp -f $remoteconf $remoteconf.XCATORIG
fi
# check if already an entry by xCAT. If so, we need to replace it
grep "xCAT settings" $remoteconf 2>&1 1> /dev/null
if [ $? -eq 0 ]; then
sed "/# xCAT settings/,$ d" $remoteconf >/tmp/sed.tmp
cat /tmp/sed.tmp >$remoteconf
if [ $isSN -eq 1 ];then
##listen on tcp and udp port to enable receiving the xcat debug logs
##forwarded via tcp/udp protocol
sed -i 's/#\$ModLoad imudp.so/\$ModLoad imudp.so/;
s/#\$UDPServerRun 514/\$UDPServerRun 514/;
s/#\$ModLoad imtcp.so/\$ModLoad imtcp.so/;
s/#\$InputTCPServerRun <port>/\$InputTCPServerRun 514/' $remoteconf
fi
# add xCAT entries
echo "# xCAT settings" >> $remoteconf
echo "*.* @$master" >> $remoteconf
@ -282,7 +290,7 @@ if [ $isLinux -eq 1 ] && [ -e $sysconfig ]; then
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=|^SYSLOGD_PARAMS=/) {
awk '{if ($0 ~ /^SYSLOGD_OPTIONS=|^SYSLOGD_PARAMS=/) {
if ($0 !~ /-r/) {sub(/-/, "-r -", $0)}
if (($0 !~ /-m0/) && ($0 !~/-m 0/)) { sub(/-/, "-m 0 -", $0)}
print $0}
@ -315,8 +323,7 @@ if [ $ng -eq 1 ]; then
if [ ! -f $conf_file.XCATORIG ]; then
cp -f $conf_file $conf_file.XCATORIG
fi
sed 's/#udp(ip("0.0.0.0/udp(ip("0.0.0.0/' $conf_file >/tmp/sed.tmp
cat /tmp/sed.tmp >$conf_file
sed -i 's/#udp(ip("0.0.0.0/udp(ip("0.0.0.0/' $conf_file
fi
fi
@ -350,8 +357,7 @@ else
grep "xCAT settings" $conf_file 2>&1 1> /dev/null
if [ $? -eq 0 ]; then
sed "/# xCAT settings/,$ d" $conf_file >/tmp/sed.tmp
cat /tmp/sed.tmp >$conf_file
sed -i "/# xCAT settings/,$ d" $conf_file
fi
if [ $isLinux -eq 0 ]; then # aix
@ -359,11 +365,11 @@ else
echo "*.debug /var/log/messages rotate 1024K files 5" >> $conf_file
fi
else
# enable the settings that will log to local files in syslog-ng
sed -i '/destination messages/s/^#*//' $conf_file
sed -i '/destination(messages)/s/^#*//' $conf_file
sed -i '/destination warn/s/^#*//' $conf_file
sed -i '/destination(warn)/s/^#*//' $conf_file
#enable the settings that will log to local files in syslog-ng
sed -i '/destination messages/s/^#*//;
/destination(messages)/s/^#*//;
/destination warn/s/^#*//;
/destination(warn)/s/^#*//' $conf_file
fi
#Ubuntu doesn't have sysconfig
@ -383,18 +389,17 @@ else
fi
grep "xCAT settings" $conf_file 2>&1 1> /dev/null
if [ $? -eq 0 ]; then
sed "/# xCAT settings/,$ d" $conf_file >/tmp/sed.tmp
cat /tmp/sed.tmp >$conf_file
sed -i "/# xCAT settings/,$ d" $conf_file
fi
echo "# xCAT settings" >> $conf_file
echo "destination loghost { udp(\"$master\"); };" >> $conf_file
echo 'log { source(src); destination(loghost); };' >> $conf_file
# remove the settings that will log to local files
sed -i '/destination messages/s/^/#/' $conf_file
sed -i '/destination(messages)/s/^/#/' $conf_file
sed -i '/destination warn/s/^/#/' $conf_file
sed -i '/destination(warn)/s/^/#/' $conf_file
sed -i '/destination messages/s/^/#/;
/destination(messages)/s/^/#/;
/destination warn/s/^/#/;
/destination(warn)/s/^/#/;' $conf_file
else
if [ -f $conf_file.XCATORIG ]; then
rm -f $conf_file