Reputation: 8505
My application is composed of 4 unique processess. For HA reason, i am going to start 3 instances of each such that 2 instances of each process would run on a single linux host and one another set on a different linux host. I am trying to write a monitoring script (bash script) that would periodically poll for these processess. My main challenge is that it sounds kludgy to write a script which is host name and process name dependent. For example , i dont want to write a script which monitors process-A-1, process-B-1, process-A-2, process-B-2 on linux host with IP Address A and process-A-3 on linux IP host Address B.
One way to write a monitoring script which is independent of host and process name is that when each of these process starts, they create a mutex name. For example, process-A-1 will create a mutex called mutex.process-A-1 and process-A-2 will create a mutex called mutex.process-A-2. Then all the script has to do is look for mutexes on a system with name like mutex.process-A*. The script then can use a ps command to check if those processess are running.
My question is that coupling with mutex name okay? Is there another way you have solved this problem on linux?
Upvotes: 1
Views: 398
Reputation: 1927
I would personally write a bash script which runs all this processes in background, then you can store their PIDs directly after calling them, storing process1_pid=$!
after you send each one to the background and then trigger another script for monitoring using those pids.
Other way to get their PIDs is using the jobs
command which will list all the jobs you have set to the background, jobs -p
will list all the PIDs you have on the background. You can also make use of jobs to know if they're still running or not.
http://www.gnu.org/software/bash/manual/bashref.html#Job-Control
I'd start from there, if it's more complicated and your processes are being created from other places you can always use a particular user to run them all and use ps -u
to filter them by user.
Upvotes: 1