Browse Source
This module provides syslog functionality in the initrd. This is especially interesting when complex configuration being used to provide access to the device the rootfs resides on. When this module is installed into the ramfs it is triggered by the udev event from the nic being setup (online). Then if syslog is configured it is started and will forward all kernel messages to the given syslog server. The syslog implementation is detected automatically by finding the apropriate binary with the following order: rsyslogd syslogd syslog-ng Then if detected the syslog.conf is generated and syslog is started. Bootparameters: syslogserver=ip Where to syslog to sysloglevel=level What level has to be logged syslogtype=rsyslog|syslog|syslogng Don't auto detect syslog but set itmaster


9 changed files with 202 additions and 0 deletions
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
Syslog support for dracut |
||||
|
||||
This module provides syslog functionality in the initrd. |
||||
This is especially interesting when complex configuration being |
||||
used to provide access to the device the rootfs resides on. |
||||
|
||||
When this module is installed into the ramfs it is triggered by |
||||
the udev event from the nic being setup (online). |
||||
|
||||
Then if syslog is configured it is started and will forward all |
||||
kernel messages to the given syslog server. |
||||
|
||||
The syslog implementation is detected automatically by finding the |
||||
apropriate binary with the following order: |
||||
rsyslogd |
||||
syslogd |
||||
syslog-ng |
||||
Then if detected the syslog.conf is generated and syslog is started. |
||||
|
||||
Bootparameters: |
||||
syslogserver=ip Where to syslog to |
||||
sysloglevel=level What level has to be logged |
||||
syslogtype=rsyslog|syslog|syslogng |
||||
Don't auto detect syslog but set it |
@ -0,0 +1,4 @@
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh |
||||
|
||||
# do not add this module by default |
||||
exit 255 |
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
#!/bin/sh |
||||
if which rsyslogd >/dev/null; then |
||||
installs="rsyslogd /usr/lib/rsyslog/lmnet.so /usr/lib/rsyslog/imklog.so /usr/lib/rsyslog/imuxsock.so" |
||||
elif which syslogd >/dev/null; then |
||||
installs="syslogd" |
||||
elif which syslog-ng >/dev/null; then |
||||
installs="syslog-ng" |
||||
else |
||||
dwarn "Could not find any syslog binary although the syslogmodule is selected to be installed. Please check." |
||||
fi |
||||
if [ -n "$installs" ]; then |
||||
dracut_install cat |
||||
dracut_install $installs |
||||
inst_hook cmdline 90 "$moddir/parse-syslog-opts.sh" |
||||
inst_hook pre-udev 61 "$moddir/syslog-genrules.sh" |
||||
inst_hook pre-pivot 99 "$moddir/syslog-cleanup.sh" |
||||
inst_simple "$moddir/rsyslogd-start.sh" /sbin/rsyslogd-start |
||||
inst_simple "$moddir/rsyslogd-stop.sh" /sbin/rsyslogd-stop |
||||
mkdir -p ${initdir}/etc/templates |
||||
inst_simple "${moddir}/rsyslog.conf" /etc/templates |
||||
fi |
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
#!/bin/sh |
||||
# Parses the syslog commandline options |
||||
# |
||||
#Bootparameters: |
||||
#syslogserver=ip Where to syslog to |
||||
#sysloglevel=level What level has to be logged |
||||
#syslogtype=rsyslog|syslog|syslogng |
||||
# Don't auto detect syslog but set it |
||||
if getarg rdnetdebug ; then |
||||
exec >/tmp/syslog-parse-opts.$1.$$.out |
||||
exec 2>>/tmp/syslog-parse-opts.$1.$$.out |
||||
set -x |
||||
fi |
||||
|
||||
syslogserver=$(getarg syslog) |
||||
syslogfilters=$(getargs filter) |
||||
syslogtype=$(getarg syslogtype) |
||||
|
||||
[ -n "$syslogserver" ] && echo $syslogserver > /tmp/syslog.server |
||||
[ -n "$syslogfilters" ] && echo "$syslogfilters" > /tmp/syslog.filters |
||||
[ -n "$syslogtype" ] && echo "$syslogtype" > /tmp/syslog.type |
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
#rsyslog v3 config file |
||||
|
||||
# if you experience problems, check |
||||
# http://www.rsyslog.com/troubleshoot for assistance |
||||
|
||||
#### MODULES #### |
||||
|
||||
$ModLoad imuxsock.so # provides support for local system logging (e.g. via logger command) |
||||
$ModLoad imklog.so # provides kernel logging support (previously done by rklogd) |
||||
#$ModLoad immark.so # provides --MARK-- message capability |
||||
|
||||
# Provides UDP syslog reception |
||||
#$ModLoad imudp.so |
||||
#$UDPServerRun 514 |
||||
|
||||
# Provides TCP syslog reception |
||||
#$ModLoad imtcp.so |
||||
#$InputTCPServerRun 514 |
||||
|
||||
|
||||
#### GLOBAL DIRECTIVES #### |
||||
|
||||
# Use default timestamp format |
||||
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat |
||||
|
||||
# File syncing capability is disabled by default. This feature is usually not required, |
||||
# not useful and an extreme performance hit |
||||
#$ActionFileEnableSync on |
||||
|
||||
|
||||
#### RULES #### |
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
#!/bin/sh |
||||
# Triggered by udev and starts rsyslogd with bootparameters |
||||
. /lib/dracut-lib.sh |
||||
|
||||
if getarg rdnetdebug ; then |
||||
exec >/tmp/rsyslogd-start.$1.$$.out |
||||
exec 2>>/tmp/rsyslogd-start.$1.$$.out |
||||
set -x |
||||
fi |
||||
|
||||
rsyslog_config() { |
||||
local server=$1 |
||||
shift |
||||
local syslog_template=$1 |
||||
shift |
||||
local filters=$* |
||||
local filter= |
||||
|
||||
cat $syslog_template |
||||
|
||||
for filter in $filters; do |
||||
echo "${filter} @${server}" |
||||
done |
||||
# echo "*.* /tmp/syslog" |
||||
} |
||||
|
||||
read server < /tmp/syslog.server |
||||
read filters < /tmp/syslog.filter |
||||
[ -z "$filters" ] && filters="kern.*" |
||||
read conf < /tmp/syslog.conf |
||||
[ -z "$conf" ] && conf="/etc/rsyslog.conf" && echo "$conf" > /tmp/syslog.conf |
||||
|
||||
template=/etc/templates/rsyslog.conf |
||||
if [ -n "$server" ]; then |
||||
rsyslog_config "$server" "$template" "$filters" > $conf |
||||
/sbin/rsyslogd -c3 |
||||
fi |
@ -0,0 +1,10 @@
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh |
||||
# Kills rsyslogd |
||||
|
||||
if [ -f /var/run/syslogd.pid ]; then |
||||
read pid < /var/run/syslogd.pid |
||||
kill $pid |
||||
kill -0 $pid && kill -9 $pid |
||||
else |
||||
warn "rsyslogd-stop: Could not find a pid for rsyslogd. Won't kill it." |
||||
fi |
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh |
||||
# Just cleans up a previously started syslogd |
||||
. /lib/dracut-lib.sh |
||||
|
||||
|
||||
if getarg rdnetdebug ; then |
||||
exec >/tmp/syslog-cleanup.$1.$$.out |
||||
exec 2>>/tmp/syslog-cleanup.$1.$$.out |
||||
set -x |
||||
fi |
||||
|
||||
if [ -f /tmp/syslog.server ]; then |
||||
read syslogtype < /tmp/syslog.type |
||||
if [ -e "/sbin/${syslogtype}-stop" ]; then |
||||
${syslogtype}-stop |
||||
else |
||||
warn "syslog-cleanup: Could not find script to stop syslog of type \"$syslogtype\". Syslog will not be stopped." |
||||
fi |
||||
fi |
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
#!/bin/dash |
||||
# Creates the syslog udev rules to be triggered when interface becomes online. |
||||
. /lib/dracut-lib.sh |
||||
|
||||
detect_syslog() { |
||||
syslogtype="" |
||||
if [ -e /sbin/rsyslogd ]; then |
||||
syslogtype="rsyslogd" |
||||
elif [ -e /sbin/syslogd ]; then |
||||
syslogtype="syslogd" |
||||
elif [ /sbin/syslog-ng ]; then |
||||
syslogtype="syslog-ng" |
||||
else |
||||
dwarn "Could not find any syslog binary although the syslogmodule is selected to be installed. Please check." |
||||
fi |
||||
echo "$syslogtype" |
||||
[ -n "$syslogtype" ] |
||||
} |
||||
|
||||
if getarg rdnetdebug ; then |
||||
exec >/tmp/syslog-genrules.$1.$$.out |
||||
exec 2>>/tmp/syslog-genrules.$1.$$.out |
||||
set -x |
||||
fi |
||||
|
||||
read syslogtype < /tmp/syslog.type |
||||
if [ -z "$syslogtype" ]; then |
||||
syslogtype=$(detect_syslog) |
||||
echo $syslogtype > /tmp/syslog.type |
||||
fi |
||||
if [ -e "/sbin/${syslogtype}-start" ]; then |
||||
printf 'ACTION=="online", SUBSYSTEM=="net", RUN+="/sbin/'${syslogtype}'-start $env{INTERFACE}"\n' > /etc/udev/rules.d/70-syslog.rules |
||||
else |
||||
warn "syslog-genrules: Could not find binary to start syslog of type \"$syslogtype\". Syslog will not be started." |
||||
fi |
Loading…
Reference in new issue