No commit activity in last 3 years
No release in over 3 years
Appends configuration to files
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

Appender¶ ↑

This is a general tool for cleaning configuration files and appending text in them. The need for something like this occurs when some process is changing a configuration file but isn’t necessarily the only process that manages that file. If manual changes are allowed, or other deployment scripts are touching the same file, we want to only remove our own lines and append them to the file.

To do this with a little extra safety, appender log rotates the configuration file with a time-stamped history. This way, rollbacks can be managed manually.

The workflow is very basic:

  • Rotate the configuration file, in case a mistake has been made

  • Remove lines that match a pattern

  • Append some new configuration at the end of the file

This doesn’t mean the file looks pretty when we’re finished.

When possible, a fully-owned configuration file makes more sense. I.e., let Sprinkle, Puppet, Chef, whatever fully own a configuration file and make the changes in the configuration management tool, rather than appending the file.

This appender approach can easily break if:

  • You get your search and replace wrong

  • The configuration file is context sensitive (which is often true)

Usage¶ ↑

From Ruby:

new_content = %[
destination df_cron { file("/var/log/cron.log"); };
filter f_cron { facility(cron); };
]
Appender.process(:config_file => '/etc/syslog-ng/syslog-ng.conf', :append => new_content, :remove => 'f_cron')

From the command line:

appender --file /etc/syslog-ng/syslog-ng.conf --remove "destination df_cron" --append "destination df_cron { file(\"/var/log/cron.log\"); };"
appender --file /etc/syslog-ng/syslog-ng.conf --remove "filter f_cron" --append "filter f_cron {facility(cron); };"

Another way to do this is simply with bash:

cat /etc/syslog-ng/syslog-ng.conf | grep -v "destination df_cron" > syslog-ng.conf.tmp
echo "destination df_cron { file(\"/var/log/cron.log\"); };" >> syslog-ng.conf.tmp
mv syslog-ng.conf.tmp /etc/syslog-ng/syslog-ng.conf

The problem with this bash approach is:

  • limited regular expression support

  • less error control

  • manual configuration history management

Yet, I prefer the simpler bash approach when I can do it that way.

Installation¶ ↑

gem install davidrichards-appender

Dependencies¶ ↑

* logrotate

Copyright © 2009 David Richards. See LICENSE for details.