patternMinor
Check a process is running with Salt Stack?
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:
The opposite of this would be ideal for my needs e.g:
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?
I have however found this:
httpd-absent:
process.absent:
- name: apache2The opposite of this would be ideal for my needs e.g:
httpd-present:
process.present:
- name: apache2Is 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:
The exit code will be non-zero and the state will fail if
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.