help-cfengine
[Top][All Lists]
Advanced

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

RE: activating a class from shellcommands


From: Wheeler, John
Subject: RE: activating a class from shellcommands
Date: Tue, 5 Nov 2002 22:08:36 -0600

yep, went through this scenerio with the solution I'm trying to impliment. A module will solve my problem, but I want a shell command because I want to be able to invoke the shell command based on a class. I could embed the logic of verifing which class is active in the module, but that wouldn't be very cfengine like ;)

I found another possible solution was to have the script read an environment variable. The issue with this is that I use cfexecd run out of init to startup cfagent, so I can't pass cfagent any command line params. :(

I've resorted to a less elegant solution that requires two passes of cfagent to perform my task, software distribution.

Thanks for your help. Speaking of modules, the one I was going to use always seem to run twice. Anyone else seen this? version 2.0.3 solaris 2.8

wheeler

-----Original Message-----
From: Chris Edillon [mailto:jce@zot.com]
Sent: Tuesday, November 05, 2002 9:07 PM
To: Wheeler, John
Cc: 'help-cfengine@gnu.org'
Subject: Re: activating a class from shellcommands


On Tue, 5 Nov 2002, Wheeler, John wrote:

> It appears that my script "checksw2" which I'd like to pass all classes to
> using $(allclasses) is actually getting the class in the define statement.
> My guess is that if the script successeds it activates the class. I couldn't
> find where this behavior is defined.

  when cfagent executes a shellcommand or a module (see below),
it passes in the environment variable $CFALLCLASSES.  this is
a colon-separated list of all currently defined classes, which
you can split out and use as you need in a script.  however...

> Can somone help me solve this? Is what I'm trying to do, set a class based
> on the return value of a script in shellcomands, possible?
>
  sounds like what you actually want is a module.  cfengine
allows for user-defined plugin modules which can be used to
define variables and classes based on arbitrary tests.  a
module is an external script/program which has a certain
output format which cfengine uses to define classes and
variables.  read the "writing plugin modules" section of
the cfengine tutorials for details, but here's a quick
example:

    #!/bin/sh
    #
    # redhat linux boxes will set up host-based packet filtering
    # using ipchains or iptables if either an "ipchains" or "iptables"
    # setup file exists in /etc/sysconfig
    #
    if [ ! -f /etc/redhat-release ]; then exit 0; fi
    if [ -n /etc/sysconfig/ipchains -o -/etc/sysconfig/iptables ]
    then
        echo "+is_filtering"
    fi

this would define a class called "is_filtering" if either ipchains
or iptables is set up on the machine.  you'd have to name the above
script something like "module:filtercheck" and place it in the
modules directory (defined in the control: section).  you'd then
make it an early part of the action sequence so that your class
would be defined before you had to use it, and you'd have to put
the class name in the AddInstallables control variable so that
cfengine would know that it's a class which may be defined on
the fly:

    control:
        moduledirectory = ( /etc/cfengine/modules )
        AddInstallables = ( is_filtering )
        actionsequence  = ( module:filtercheck
                            ...
                          )

again, the cfengine tutorial convers this in greater detail.


reply via email to

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