Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Appends configuration to files
Ruby
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
bin
features
lib
spec
.gitignore
LICENSE
README.rdoc
Rakefile
VERSION.yml
appender.gemspec

README.rdoc

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

Copyright © 2009 David Richards. See LICENSE for details.

Something went wrong with that request. Please try again.