#!/usr/sbin/sh
#
# Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
#
. /lib/svc/share/smf_include.sh
PKILL=/usr/bin/pkill
DEGRADE_STATE=false
TRANSITION_FILE=/etc/rsyslog.d/TRANSITIONED
function setup
{
SVC_FMRI=svc:/system/system-log
SYSLOG_FMRI=${SVC_FMRI}:syslog
DEFAULT_FMRI=${SVC_FMRI}:default
OLD_METHOD1="kill -HUP \`cat /var/run/syslog.pid\`"
OLD_METHOD2="kill -HUP \`cat /system/volatile/syslog.pid\`"
NEW_METHOD="/usr/sbin/svccfg -s $SVC_FMRI refresh"
LOGADM_CONF=/etc/logadm.conf
if [ ! -f /etc/rsyslog.conf ]; then
echo "/etc/rsyslog.conf not found. Exiting."
exit $SMF_EXIT_ERR_CONFIG
fi
if [ ! -f /usr/lib/rsyslog/rsyslogd ]; then
echo "/usr/lib/rsyslog/rsyslogd not found. Exiting."
exit $SMF_EXIT_ERR_CONFIG
fi
if [ ! -x /usr/lib/rsyslog/rsyslogd ]; then
echo "/usr/lib/rsyslog/rsyslogd not executable. Exiting."
exit $SMF_EXIT_ERR_CONFIG
fi
# remove once "system-log/default" has been renamed to "syslog" in ON
default=$(/usr/bin/svcprop -c -p general/enabled $DEFAULT_FMRI 2> /dev/null)
if [ "$default" = true ]; then
echo "$DEFAULT_FMRI conflicts with this instance and must be disabled first. Exiting."
exit $SMF_EXIT_ERR_CONFIG
fi
syslog=$(/usr/bin/svcprop -c -p general/enabled $SYSLOG_FMRI 2> /dev/null)
if [ "$syslog" = true ]; then
echo "$SYSLOG_FMRI conflicts with this instance and must be disabled first. Exiting."
exit $SMF_EXIT_ERR_CONFIG
fi
if smf_is_globalzone; then
#
# Before [r]syslogd starts, save any messages from
# previous crash dumps so that messages appear
# in chronological order.
#
# Need to be root to use savecore
/usr/bin/savecore -m
if [ -r /etc/dumpadm.conf ]; then
. /etc/dumpadm.conf
[ -n "$DUMPADM_DEVICE" -a \
"$DUMPADM_DEVICE" != swap ] && \
/usr/bin/savecore -m -f $DUMPADM_DEVICE
fi
fi
if [ ! -f /var/adm/messages ]; then
/usr/bin/cp /dev/null /var/adm/messages
/usr/bin/chmod 0644 /var/adm/messages
fi
# Convert the old PID-file based post-command for logadm to an SMF-based one.
TMP_CONF=$(/usr/bin/mktemp /tmp/logadm.conf.XXXXXX)
/usr/bin/sed -e "s|$OLD_METHOD1|$NEW_METHOD|" \
-e "s|$OLD_METHOD2|$NEW_METHOD|" $LOGADM_CONF > $TMP_CONF
/usr/bin/cmp -s $LOGADM_CONF $TMP_CONF
if [ $? -eq 0 ]; then
/usr/bin/rm $TMP_CONF
else
# In case the umask or group is odd.
mode=$(/usr/bin/stat -c %a $LOGADM_CONF)
owner_group=$(/usr/bin/stat -c %U:%G $LOGADM_CONF)
/usr/bin/mv $TMP_CONF $LOGADM_CONF
/usr/bin/chmod $mode $LOGADM_CONF
/usr/bin/chown $owner_group $LOGADM_CONF
fi
}
function check_update
{
# only do one transition/degrade
if [ -f $TRANSITION_FILE ]; then
return 0
fi
# cksum's of /etc/rsyslog.conf
RSYSLOG_CKSUM_1=3811874833 # s11.1, s11.2, s11.3
RSYSLOG_CKSUM_2=53416708 # s12
# cksum's of /etc/syslog.conf
SYSLOG_CKSUM_1=681212404 # s11, s11.1
SYSLOG_CKSUM_2=2956275192 # s11.2, s11.3, s12
CKSUM_ETC_RSYSLOG=`/usr/bin/cksum /etc/rsyslog.conf`
if [ $? -ne 0 ]; then
# very abnormal state; bail out
echo "cksum /etc/rsyslog.conf failed. Exiting."
exit $SMF_EXIT_ERR_CONFIG
else
CKSUM_ETC_RSYSLOG=`echo $CKSUM_ETC_RSYSLOG | /usr/bin/cut -d' ' -f1`
fi
CKSUM_ETC_SYSLOG=`/usr/bin/cksum /etc/syslog.conf`
if [ $? -ne 0 ]; then
# Don't care? Let rsyslog come up normal.
CKSUM_ETC_SYSLOG=$SYSLOG_CKSUM_2 # unmodified syslog.conf
else
CKSUM_ETC_SYSLOG=`echo $CKSUM_ETC_SYSLOG | /usr/bin/cut -d' ' -f1`
fi
# if /etc/rsyslog.conf has NOT been modified
# AND
# if /etc/syslog.conf has been modified
# then there are customizations that may need migrating so
# exit DEGRADED
if ([ $CKSUM_ETC_RSYSLOG -eq $RSYSLOG_CKSUM_1 ] || \
[ $CKSUM_ETC_RSYSLOG -eq $RSYSLOG_CKSUM_2 ]) && \
([ $CKSUM_ETC_SYSLOG -ne $SYSLOG_CKSUM_1 ] && \
[ $CKSUM_ETC_SYSLOG -ne $SYSLOG_CKSUM_2 ]); then
echo "WARNING:"
echo "Bringing up rsyslog in a degraded state."
echo "man rsyslogd"
echo "And see NOTES for further instructions."
DEGRADE_STATE=true
fi
# and don't transition/degrade again
echo "#DO NOT REMOVE" > $TRANSITION_FILE
echo "#Successful transition from syslog to rsyslog completed."\
>> $TRANSITION_FILE
}
case "$1" in
'start')
setup
check_update
/usr/lib/rsyslog/rsyslogd >/dev/msglog 2>&1
if [ $? -ne 0 ]; then
return 1
fi
;;
'stop')
$PKILL -TERM -f /usr/lib/rsyslog/rsyslogd
;;
'refresh')
$PKILL -HUP -f /usr/lib/rsyslog/rsyslogd
;;
*)
echo "Usage: $0 { start | stop | refresh }"
exit 1
;;
esac
if [ ${DEGRADE_STATE} == true ]; then
smf_method_exit ${SMF_EXIT_DEGRADED} rsyslog \
"rsyslog.conf may need customizations"
fi
exit ${SMF_EXIT_OK}