I'm trying to come up with a very simple implementation for this problem:
- I have 2 environments behaving under a master-slave paradigm
Environment A
managesenvironment B
: configures it, runs scripts in it, etc.Environment B
cannot initiate communications withenvironment A
- Sometimes
environment A
leaves scripts running inenvironment B
's background [./myScript.sh &
], and has no way of knowing when those scripts are finished (well,environment A
could just pollB
withps -aux
, but I'm looking for a more generic system)
I'd like to create a system that satisfies these conditions:
- When a background script
myScript.sh
finishes, it leaves a message in some mailbox Environment A
keeps a runner that periodically checks the mailbox in environment B, and consumes all new messages- Adding and consuming messages to this 'queue' must be resistant to race conditions / concurrency
- The solution must be based on Bash
I thought of 2 options:
- Option A: modeling the mailbox as a file.
myScript.sh
appends notifications to the file;environment A
reads and empties the file via ssh. I guess race conditions could be solved via file locking? I think bash allows this. - Option B: much simpler,
myScript.sh
would leave messages as separate files in a well-known folder which would act as mailbox.Environment A
would get the list of files,cat
them and remove them.
But perhaps the vast know-how of StackOverflow will propose must better / simpler options.
Thanks!