HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Check a process is running with Salt Stack?

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
processstackwithsaltrunningcheck

Problem

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?

Solution

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.

Code Snippets

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

Context

StackExchange DevOps Q#1805, answer score: 7

Revisions (0)

No revisions yet.