328 lines
8.5 KiB
Bash
328 lines
8.5 KiB
Bash
#!/bin/bash
|
|
#
|
|
# /lib/systemd/system-generator/syslog-service-generator
|
|
#
|
|
# Copyright (c) 2011 SuSE LINUX Products GmbH, Germany.
|
|
#
|
|
# Description:
|
|
#
|
|
# Write out syslog.core and if required enable klogd.service
|
|
# depending on the configuration found in /etc/sysconfig/syslog.
|
|
# Also check if network target is required with this we do not
|
|
# required the earlysyslog hack anymore.
|
|
# Based on the /etc/init.d/syslog SysV init boot script as well
|
|
# as on the /etc/init.d/earlysyslog wrapper script.
|
|
#
|
|
# Author: Werner Fink
|
|
# Please send feedback to http://www.suse.de/feedback
|
|
#
|
|
|
|
umask 0022
|
|
TMPDIR=/run
|
|
|
|
export TMPDIR
|
|
|
|
: ${SBINDIR:=/sbin}
|
|
: ${RUN_PATH:=/run/systemd}
|
|
: ${SYSUNITDIR:=/lib/systemd/system}
|
|
: ${SYSCONFDIR:=/etc/systemd/system}
|
|
|
|
if test -s /etc/sysconfig/syslog ; then
|
|
CORE=$RUN_PATH/syslog.core
|
|
test -s $CORE -a $CORE -nt /etc/sysconfig/syslog && exit 0
|
|
. /etc/sysconfig/syslog
|
|
else
|
|
SYSLOG_DAEMON=rsyslogd
|
|
fi
|
|
|
|
#
|
|
# Danger Robinson: do not touch anything if a System logger
|
|
# is running under the control of systemd its self!
|
|
#
|
|
if test -d /sys/fs/cgroup/systemd/system/syslog.service -o \
|
|
-d /sys/fs/cgroup/systemd/system/klogd.service
|
|
then
|
|
/bin/logger -i -p daemon.warn -t ${0##*/} \
|
|
'Stop syslog.service before reloading the daemons!'
|
|
exit 1
|
|
fi
|
|
|
|
#
|
|
# Update $SYSLOG_DAEMON if not up-to-date
|
|
#
|
|
if test -z "$SYSLOG_DAEMON" -o ! -x "$SBINDIR/$SYSLOG_DAEMON" ; then
|
|
for SYSLOG_DAEMON in rsyslogd syslog-ng syslogd ; do
|
|
test -x "$SBINDIR/$SYSLOG_DAEMON" && break
|
|
done
|
|
fi
|
|
|
|
#
|
|
# Default is no network and start klogd
|
|
#
|
|
network=
|
|
start_klogd=yes
|
|
klogd=klogd.service
|
|
|
|
#
|
|
# Now check for the three possible system loggers for required
|
|
# network connection and for external klogd. Note that /var/run
|
|
# does not exist at boot time, therefore files and directories
|
|
# will be created below the /run tmpfs.
|
|
#
|
|
case "$SYSLOG_DAEMON" in
|
|
syslog-ng)
|
|
syslog=syslog-ng
|
|
config=/etc/syslog-ng/syslog-ng.conf
|
|
socksdir=/var/run/syslog-ng
|
|
socks=$socksdir/additional-log-sockets.conf
|
|
if test -s "$config" ; then
|
|
while read line ; do
|
|
case "$line" in
|
|
\#*|"") continue ;;
|
|
*udp\ *|*udp\(*) network=network.target ;;
|
|
*tcp\ *|*tcp\(*) network=network.target ;;
|
|
esac
|
|
done < ${config}
|
|
fi
|
|
if test -r "$config" ; then
|
|
while read line; do
|
|
case $line in
|
|
file*/proc/kmsg*)
|
|
start_klogd=no
|
|
break
|
|
esac
|
|
done < $config
|
|
fi
|
|
/bin/mkdir -p -m 0755 ${socksdir#/var}
|
|
/bin/touch -m 0600 ${socks#/var}
|
|
params="$SYSLOG_NG_PARAMS"
|
|
;;
|
|
rsyslogd)
|
|
syslog=rsyslogd
|
|
config=/etc/rsyslog.early.conf
|
|
socksdir=/var/run/rsyslog
|
|
socks=$socksdir/additional-log-sockets.conf
|
|
#
|
|
# In hope this works with the rsyslog.early.conf file
|
|
# (hard to implement for rsyslog with its includes/if
|
|
# statements)...
|
|
#
|
|
if test -s "$config" ; then
|
|
while read select action ; do
|
|
case "$select" in
|
|
\#*|"")
|
|
continue
|
|
esac
|
|
case "$action" in
|
|
*@*)
|
|
network=network.target
|
|
break
|
|
esac
|
|
done < ${config}
|
|
test -n "$network" && config=/etc/rsyslog.conf
|
|
else
|
|
config=/etc/rsyslog.conf
|
|
fi
|
|
if test -r "$config" ; then
|
|
while read one two rest ; do
|
|
if test "$one" = '$ModLoad' -a "$two" = 'imklog.so' ; then
|
|
start_klogd=no
|
|
break
|
|
fi
|
|
done < $config
|
|
fi
|
|
/bin/mkdir -p -m 0755 ${socksdir#/var}
|
|
/bin/touch -m 0600 ${socks#/var}
|
|
compat=${RSYSLOGD_COMPAT_VERSION:-${RSYSLOGD_NATIVE_VERSION}}
|
|
params="-c ${compat:-3} -f $config $RSYSLOGD_PARAMS"
|
|
;;
|
|
*)
|
|
syslog=syslogd
|
|
config=/etc/syslog.conf
|
|
socksdir=/var/run/syslog
|
|
socks=$socksdir/additional-log-sockets.env
|
|
if test -s "$config" ; then
|
|
while read select action ; do
|
|
case "$select" in \#*|"") continue ;; esac
|
|
case "$action" in *@*) network=network.target ;; esac
|
|
done < ${config}
|
|
fi
|
|
/bin/mkdir -p -m 0755 ${socksdir#/var}
|
|
/bin/touch -m 0600 ${socks#/var}
|
|
params="$SYSLOGD_PARAMS"
|
|
esac
|
|
|
|
syslog_bin=${SBINDIR}/$syslog
|
|
klog_bin=${SBINDIR}/klogd
|
|
|
|
test -s ${config} || exit 1
|
|
test -x ${syslog_bin} || exit 1
|
|
|
|
#
|
|
# Make sure that we have a log fifo which is used by X11
|
|
#
|
|
if test -e /dev/xconsole -a ! -p /dev/xconsole ; then
|
|
/bin/rm -f /dev/xconsole
|
|
fi
|
|
if test ! -e /dev/xconsole ; then
|
|
/bin/mknod -m 0600 /dev/xconsole p
|
|
/bin/chown root:tty /dev/xconsole
|
|
fi
|
|
|
|
#
|
|
# No klogd.service required
|
|
#
|
|
test "$start_klogd" = no && klogd=
|
|
|
|
#
|
|
# Create a temporary file for syslog.core
|
|
#
|
|
trap 'rm -f "$service"' EXIT
|
|
tmpcore=$(/bin/mktemp $RUN_PATH/syslog.XXXXXXXX) || exit 1
|
|
(/bin/cat > $tmpcore)<<-EOF
|
|
# Warning: Do not edit as this file has been and will be autogenerated
|
|
# by $0
|
|
${network:+Requires=$network}
|
|
${network:+After=$network}
|
|
${klogd:+Requires=$klogd}
|
|
${klogd:+Before=$klogd}
|
|
|
|
[Service]
|
|
Type=forking
|
|
PIDFile=/var/run/${syslog_bin##*/}.pid
|
|
Sockets=syslog.socket
|
|
StandardOutput=null
|
|
ExecStartPre=/bin/systemctl stop systemd-kmsg-syslogd.service
|
|
ExecStartPre=-$socksdir/addsockets
|
|
EOF
|
|
|
|
#
|
|
# For additional sockets we use further configuration files
|
|
# for rsyslogd and syslog-ng but an envrionment file for syslogd
|
|
#
|
|
case "$SYSLOG_DAEMON" in
|
|
rsyslogd)
|
|
(/bin/cat > ${socksdir#/var}/addsockets)<<-EOF
|
|
#!/bin/sh
|
|
# Warning: Do not edit as this file has been and will be
|
|
# autogenerated by $0
|
|
test -s /etc/sysconfig/syslog && . /etc/sysconfig/syslog
|
|
umask 0022
|
|
> $socks
|
|
for variable in \${!SYSLOGD_ADDITIONAL_SOCKET*}; do
|
|
eval value=\\\$\$variable
|
|
test -z "\$value" && continue
|
|
test ! -d \${value%/*} && continue
|
|
echo "\\\$AddUnixListenSocket \$value"
|
|
done >> $socks
|
|
EOF
|
|
;;
|
|
syslog-ng)
|
|
(/bin/cat > ${socksdir#/var}/addsockets)<<-EOF
|
|
#!/bin/sh
|
|
# Warning: Do not edit as this file has been and will be
|
|
# autogenerated by $0
|
|
test -s /etc/sysconfig/syslog && . /etc/sysconfig/syslog
|
|
umask 0022
|
|
echo 'source chroots {' > $socks
|
|
for variable in \${!SYSLOGD_ADDITIONAL_SOCKET*}; do
|
|
eval value=\\\$\$variable
|
|
test -z "\$value" && continue
|
|
test ! -d \${value%/*} && continue
|
|
echo "unix-dgram(\\"\$value\\");"
|
|
done >> $socks
|
|
echo '};' >> $socks
|
|
EOF
|
|
;;
|
|
*)
|
|
(/bin/cat > ${socksdir#/var}/addsockets)<<-EOF
|
|
#!/bin/sh
|
|
# Warning: Do not edit as this file has been and will be
|
|
# autogenerated by $0
|
|
test -s /etc/sysconfig/syslog && . /etc/sysconfig/syslog
|
|
umask 0022
|
|
echo -n 'ADDITIONAL_SOCKET="' > $socks
|
|
for variable in \${!SYSLOGD_ADDITIONAL_SOCKET*}; do
|
|
eval value=\\\$\$variable
|
|
test -z "\$value" && continue
|
|
test ! -d \${value%/*} && continue
|
|
echo -n "-a \$value "
|
|
done >> $socks
|
|
echo -n '"' >> $socks
|
|
EOF
|
|
echo "Environment=ADDITIONAL_SOCKET=" >>$tmpcore
|
|
echo "EnvironmentFile=-$socks" 1>>$tmpcore
|
|
params="${params:+$params }\$ADDITIONAL_SOCKET"
|
|
esac
|
|
chmod u+x ${socksdir#/var}/addsockets
|
|
|
|
#
|
|
# If klogd.service is required handle reload of syslog.service efficient
|
|
# otherwise we may loose kernel messages or klogd is forwarding kernel
|
|
# messages back to systemd as the creator of the system logging socket
|
|
# and we would get a message loop.
|
|
#
|
|
exec 3>&1 1>>$tmpcore
|
|
echo "ExecStart=$syslog_bin $params"
|
|
if test "$start_klogd" != no ; then
|
|
echo "ExecReload=/bin/systemctl kill --signal=TSTP klogd.service"
|
|
fi
|
|
echo "ExecReload=/sbin/killproc -p /var/run/${syslog_bin##*/}.pid -HUP $syslog_bin"
|
|
if test "$start_klogd" != no ; then
|
|
echo "ExecReload=/bin/systemctl kill --signal=CONT klogd.service"
|
|
echo "ExecReload=/bin/systemctl kill --signal=USR2 klogd.service"
|
|
fi
|
|
echo
|
|
exec 1>&3 3>&-
|
|
|
|
#
|
|
# If klogd.service is required, remove symbolic link for masking out
|
|
# otherwise just add the symbolic link
|
|
#
|
|
klogserv=$SYSCONFDIR/klogd.service
|
|
if test "$start_klogd" != no -a -x ${klog_bin} ; then
|
|
test -h $klogserv && rm -f $klogserv
|
|
else
|
|
/bin/ln -sf /dev/null $klogserv
|
|
fi
|
|
|
|
#
|
|
# Now enable the service(s) for multi-user target
|
|
#
|
|
/bin/mv $tmpcore $CORE
|
|
|
|
if test ! -d $SYSCONFDIR/multi-user.target.wants/ ; then
|
|
/bin/mkdir -p $SYSCONFDIR/multi-user.target.wants
|
|
fi
|
|
|
|
syslogserv=$SYSUNITDIR/syslog.service
|
|
enableserv=$SYSCONFDIR/multi-user.target.wants/syslog.service
|
|
if test ! -h $enableserv ; then
|
|
/bin/rm -f $enableserv
|
|
/bin/ln -sf $syslogserv $enableserv
|
|
fi
|
|
|
|
klogserv=$SYSUNITDIR/klogd.service
|
|
enableserv=$SYSCONFDIR/multi-user.target.wants/klogd.service
|
|
disablserv=$SYSCONFDIR/klogd.service
|
|
if test "$start_klogd" != no -a -e $klogserv ; then
|
|
if test ! -h $enableserv ; then
|
|
/bin/rm -f $enableserv
|
|
/bin/ln -sf $klogserv $enableserv
|
|
fi
|
|
if test -h $disablserv ; then
|
|
/bin/rm -f $disablserv
|
|
fi
|
|
else
|
|
if test ! -h $disablserv ; then
|
|
/bin/rm -f $disablserv
|
|
/bin/ln -sf /dev/null $disablserv
|
|
fi
|
|
if test -h $enableserv ; then
|
|
/bin/rm -f $enableserv
|
|
fi
|
|
fi
|
|
|
|
#
|
|
# end of /lib/systemd/system-generator/syslog-service-generator
|