PSARC/2016/303 enable rsyslog as default Solaris logger
24362425 rsyslog should degrade service if syslog.conf has been modified
--- a/components/rsyslog/files/rsyslog Tue Aug 02 04:53:05 2016 -0700
+++ b/components/rsyslog/files/rsyslog Thu Aug 04 08:26:36 2016 -0700
@@ -1,5 +1,4 @@
#!/usr/sbin/sh
-#
#
# Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
@@ -7,76 +6,165 @@
. /lib/svc/share/smf_include.sh
-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
+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 /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 [ ! -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
-if [ ! -x /usr/lib/rsyslog/rsyslogd ]; then
- echo "/usr/lib/rsyslog/rsyslogd not executable. 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
-# remove once "system-log/default" as 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
+ 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
-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
+ # 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
+}
-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
+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
-fi
-if [ ! -f /var/adm/messages ]; then
- /usr/bin/cp /dev/null /var/adm/messages
- /usr/bin/chmod 0644 /var/adm/messages
+
+ # 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
-
-# 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
-
-/usr/lib/rsyslog/rsyslogd >/dev/msglog 2>&1
+exit ${SMF_EXIT_OK}
--- a/components/rsyslog/files/rsyslog.xml Tue Aug 02 04:53:05 2016 -0700
+++ b/components/rsyslog/files/rsyslog.xml Thu Aug 04 08:26:36 2016 -0700
@@ -71,7 +71,7 @@
<exec_method
type='method'
name='start'
- exec='/lib/svc/method/rsyslog'
+ exec='/lib/svc/method/rsyslog start'
timeout_seconds='600'>
<method_context>
<method_credential
@@ -83,13 +83,13 @@
<exec_method
type='method'
name='stop'
- exec=':kill'
+ exec='/lib/svc/method/rsyslog stop'
timeout_seconds='60' />
<exec_method
type='method'
name='refresh'
- exec=':kill -HUP'
+ exec='/lib/svc/method/rsyslog refresh'
timeout_seconds='60' />
<property_group name='general' type='framework'>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/components/rsyslog/patches/rsyslogd.8.patch Thu Aug 04 08:26:36 2016 -0700
@@ -0,0 +1,23 @@
+Solaris specific patch around SMF services.
+
+
+
+--- rsyslog-8.15.0/tools/rsyslogd.8_orig 2015-11-12 03:52:06.000000000 -0800
++++ rsyslog-8.15.0/tools/rsyslogd.8 2016-08-03 15:45:05.475192214 -0700
+@@ -308,3 +308,16 @@
+ .TP
+ [email protected]
+ .PD
++.SH NOTES
++As of Solaris 12, rsyslog is now the default Solaris logger.
++
++When the service is enabled the first time, an attempt is made
++to see if any /etc/syslog.conf (see syslog.conf(5)),
++entries might need migrating and if
++so rsyslog is brought up in a degraded SMF state.
++
++Please visit /etc/rsyslog.conf (see rsyslog.conf(5)), and customize as needed.
++
++Then clear the service:
++
++# svcadm clear svc:/system/system-log:rsyslog
--- a/components/rsyslog/rsyslog.p5m Tue Aug 02 04:53:05 2016 -0700
+++ b/components/rsyslog/rsyslog.p5m Thu Aug 04 08:26:36 2016 -0700
@@ -46,6 +46,7 @@
overlay=allow preserve=true
dir path=etc/rsyslog.d
file rsyslog.xml path=lib/svc/manifest/system/rsyslog.xml \
+ restart_fmri=svc:/system/manifest-import:default \
restart_fmri=svc:/system/system-log:rsyslog
file rsyslog path=lib/svc/method/rsyslog
file path=usr/lib/rsyslog/imfile.so