6

Is it possible to check if a specific process is running via a Salt State? Looking through Salt Stack documentation and scouring forums I haven't found any way of simply checking if a service is running and reporting the output.

I have however found this:

httpd-absent:
  process.absent:
    - name: apache2

The opposite of this would be ideal for my needs e.g:

httpd-present:
  process.present:
    - name: apache2

Is anyone aware of a method in Salt which would check if a defined process is running based on a name or pattern (regex) and simply report back with a true/false or similar?

jto
  • 378
  • 1
  • 6
  • 19

1 Answers1

7

It's a bit hacky, but you can always do something like:

check_process:
  cmd.run:
    - name: ps aux | grep '[f]oobar'

The exit code will be non-zero and the state will fail if foobar doesn't exist.

Josh Correia
  • 105
  • 4
user2640621
  • 1,405
  • 9
  • 20