Project

General

Profile

Actions

Question #3661

closed

Need help with new technique: Commands Management

Added by Dennis Cabooter almost 11 years ago. Updated about 6 years ago.

Status:
Resolved
Priority:
N/A
Assignee:
-
Category:
Techniques
Regression:

Description

I've started to create a new technique called Commands Management:

- Define a (shell) command to run. E.g. /usr/bin/getent passwd $username
- Define the exit status which you should get back to run the second command. E.g. if set to 0, the next command will only run if the previous command has exit status 0
- Define a (shell) command to run if the first command exits with the defined status. E.g. /usr/bin/mail -s "$username does exist" $recipient

This is where I came up with untill now. From this point on I don't know how to finish this technique.

- /var/rudder/configuration-repository/techniques/systemSettings/process/commandsManagement/1.0/metadata.xml

<TECHNIQUE name="Commands Management">
  <DESCRIPTION>Run a command based on the exit status of another command</DESCRIPTION>
  <COMPATIBLE>
    <OS version=">= 4 (Etch)">Debian</OS>
    <OS version=">= 4 (Nahant)">RHEL / CentOS</OS>
    <OS version=">= 10 SP1 (Agama Lizard)">SuSE LES / DES / OpenSuSE</OS>
    <AGENT version=">= 3.2">cfengine-community</AGENT>
  </COMPATIBLE>

  <MULTIINSTANCE>true</MULTIINSTANCE>
  <BUNDLES>
    <NAME>commands_management</NAME>
  </BUNDLES>

  <TMLS>
    <TML name="commandsManagement"/>
  </TMLS>

  <TRACKINGVARIABLE>
    <SAMESIZEAS>COMMAND_EXECUTE_FIRST</SAMESIZEAS>
  </TRACKINGVARIABLE>

  <SECTIONS>
    <SECTION name="Command to execute first" multivalued="true">

    <INPUT>
        <NAME>COMMAND_EXECUTE_FIRST</NAME>
        <DESCRIPTION>Command to execute first</DESCRIPTION>
    </INPUT>

    <SECTION name="Command to execute next"  multivalued="false"  component="true" componentKey="COMMAND_EXECUTE_FIRST">
      <INPUT>
        <NAME>EXIT_STATUS</NAME>
        <DESCRIPTION>The exit status to run the second command should be</DESCRIPTION>
        <CONSTRAINT>
          <TYPE>integer</TYPE>
          <DEFAULT>0</DEFAULT>
        </CONSTRAINT>
      </INPUT>

      <INPUT>
        <NAME>COMMAND_EXECUTE_NEXT</NAME>
        <DESCRIPTION>Command to execute next</DESCRIPTION>
      </INPUT>
    </SECTION>
    </SECTION>
  </SECTIONS>
</TECHNIQUE>

- /var/rudder/configuration-repository/techniques/systemSettings/process/commandsManagement/1.0/commandsManagement.st

bundle agent commands_management
{
  commands:
    "&COMMAND_EXECUTE_FIRST&" 
    contain => in_shell,
    classes => get_exit_status;

    execute_next::
      "&COMMAND_EXECUTE_NEXT&" 
      contain => in_shell;
}

body classes get_exit_status
{
  kept_returncodes => { "&EXIT_STATUS&" };
  promise_kept => { "execute_next" };
}
Actions

Also available in: Atom PDF