2

I'm using cfengine to start the foobar process. Apparently the LHS is discarded when I use process_select? Can I simply pass the LHS to a function, rather than having to put the command match pattern in a body argument?

I wanted to only match foobar processes belonging to a particular user, since another user could easily be running foobar for testing.

bundle agent foobar {
processes:
    "foobar" # documented way would be to use .* here
        process_select => command("foobar"),
        restart_class => start_foobar;

commands:
    start_foobar::
        "/usr/bin/foobar";
}

body process_select command(c) {
    command => "$(c)";
    process_result => "command";
}
joeforker
  • 2,399
  • 4
  • 26
  • 35

1 Answers1

2

As far as I know, if you just want to look for the "foobar" process, you don't need to use the process_select feature at all.

Can't you just do this?

processes:
    "foobar"
        restart_class => start_foobar;

If you also need to match other criteria at the same time, like the user running it as you suggest, I would recommend either using a variable like:

vars:
   "program" string => "foobar"; 

Or, better still, writing a bundle that takes some parameters, something like this:

bundle agent restart(program, path) {
processes:
    "${program}" # documented way would be to use .* here
        process_select => command("${program}"),
        restart_class => start_foobar;

commands:
    start_foobar::
        "${path}/${program}";
}

body process_select command(c) {
    command => "$(c)";
    process_result => "command";
}

And then just call this bundle as restart("foobar", "/usr/bin").

I haven't tested the code above, you might have to tweak it!

Jonathan Clarke
  • 1,667
  • 2
  • 11
  • 25