0

I'm using an RPM to install a binary and some config files to CentOS. My issue is that I need to find a way to set up the rsyslog rules during the RPM install. Up until now I've just been adding the lines manually myself near the top of the file. Other than just adding the lines in using sed in the spec file, what options do I have?

Luke
  • 203
  • 1
  • 7

2 Answers2

1

Put the following in your rsyslog.conf:

$IncludeConfig /etc/rsyslog.d/*.conf

Then have your rpm drop a file into that directory.

  • Reference: [$IncludeConfig](http://www.rsyslog.com/doc/rsconf1_includeconfig.html) –  Jun 14 '13 at 17:18
  • What if I didn't have access to the rsyslog.conf file other than through the rpm package? – Luke Jun 14 '13 at 17:19
  • Rebuild the package to include the directive if it doesn't already. –  Jun 14 '13 at 17:29
  • I'm saying how would I add the $IncludeConfig line to rsyslog.conf via the rpm package? sed? – Luke Jun 14 '13 at 17:43
  • 1
    The idea is that you don't have to. You have that line in there already and your new rpm that wants to add a rule simply drops a file into the /etc/rsyslog.d/ directory. I suppose you could write a script using awk/sed/grep/etc to check for the existing directive and add it if it's not found, but I find it *very* bad practice to modify files owned by other RPMs. –  Jun 14 '13 at 17:51
  • This is what I ended up using in the spec file %post: – Luke Jun 19 '13 at 16:13
0

This is what I ended up using in the spec file %post:

if grep -q "MY_SERVICE" /etc/rsyslog.conf
then
        echo "do nothing"
else
        mv /etc/rsyslog.conf /etc/rsyslog.conf.orig
        sed -e'/^#### RULES/a :syslogtag, contains, "MY_SERVICE" \/var\/log\/MY_SERVICE.log\n\& ~' /etc/rsyslog.conf.orig > /etc/rsyslog.conf
fi
service rsyslog restart
Luke
  • 203
  • 1
  • 7