help-cfengine
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: editfiles methodology question


From: Brendan Strejcek
Subject: Re: editfiles methodology question
Date: Sun, 6 Nov 2005 12:46:22 -0600
User-agent: Mutt/1.5.6+20040818i

Viraj Alankar wrote:

> Let's say I want have a file /etc/httpd/conf.d/log_sql.conf that looks
> like the following on a couple of servers:
> 
> LoadModule log_sql_module modules/mod_log_sql.so
> LoadModule log_sql_mysql_module modules/mod_log_sql_mysql.so
> LogSQLLoginInfo mysql://my:login@mysqlclust1/apachelogs
> LogSQLCreateTables on
> LogSQLMassVirtualHosting On
> LogSQLTransferLogFormat AabHhMmRrSsTUuv
> LogSQLMachineID $(short_hostname)
> 
> Now short_hostname should be replaced with a variable that I define:
> 
> short_hostname = ( ExecResult(/bin/hostname -s) )

Unrelated to your question, you could use the cfagent special variable
${host} and save a fork.

http://www.cfengine.org/docs/cfengine-Reference.html#Special-variables

> So basically I have almost identical data in the file except for the
> last line, which is specific to each host.

...

> But the problem is this does not really enforce the file always being
> the same.

If the order of lines in the file does not matter you could do:

    DeleteLinesStarting "LogSQLTransferLogFormat"
    AppendIfNoSuchLine "LogSQLTransferLogFormat AabHhMmRrSsTUuv"

    DeleteLinesStarting "LogSQLMachineID"
    AppendIfNoSuchLine "LogSQLMachineID ${host}"
    ...

One such pair for each line. This will only result in the file
actually being changed if the editfiles result is different than
the file on disk. In most cases, that should only be true once.

> I don't think I could do a copy: because the checksum will always be
> different with the short_hostname variable. If I do that and then an
> editfiles: afterwards, it seems I would always be restarting httpd.

You could also do this, if you treat the master file as a template
rather than a complete file. The trick is to edit a copy of the config
file rather than the file itself. Pseudocode:

    Copy file from repository to temp file
    Use editfiles on temp file
    Compare to real file, copy temp -> real if diff and define restart class
    If restart class defined, restart daemon

Best,
Brendan

--
Senior System Administrator
The University of Chicago
Department of Computer Science
http://www.cs.uchicago.edu/people/brendan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]