Ask Your Question

Make exec Wait For Previous Exec To Complete

asked 2014-10-04 03:41:02 -0600

opticyclic gravatar image

My process is based on 3 execs:

  • Create schema using sqlplus
  • Populate schema from xml using java app1
  • Start java app2

I can't start the 2nd java app until the first one has complete as the database wont be fully populated. I use require to order them correctly but I can't get the wait part correct.

If I use unless and something like ps -ef|grep java app1 the 2nd java app wouldn't run at all.

How do I say "wait until this process is finished before running this next exec"?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-10-04 11:36:43 -0600

jonn gravatar image

It sounds like app1 is going into the background and populating the schema asynchronously. Is it possible to get the app to do this in the foreground and quit with an appropriate exit code when it has finished?

If not, then maybe you could have an extra exec in between those for app1 and app2. This exec could call a script that would poll the database periodically, and only return once it was satisfied that the schema had been populated correctly.

Or, if you don't need to trigger any other puppet resources from the sub-tasks, then you could put the whole "create schema/start app1/wait for schema population to complete/start app2" workflow into a single script, and use one exec for the lot.

edit flag offensive delete link more



The background issue was spot on. I was calling a script that forks a process so wait wouldn't wait for the grandchild process. I did this to work around it. PID1=$(ps -ef|grep create-db|grep 'java -server'|grep -v grep|awk '{print $2}') while [ -e /proc/$PID1 ]; do sleep 1; done

opticyclic gravatar imageopticyclic ( 2014-10-04 17:53:26 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-10-04 03:41:02 -0600

Seen: 1,712 times

Last updated: Oct 04 '14