2012-08-30 39 views
3

我有一个更新Web应用程序的脚本。 Web应用程序分布在2台服务器上。这里是脚本的破败完成Linux shell脚本异步命令和通知

  1. shell脚本更新git存储库。
  2. shell脚本停止应用程序服务器。
  3. shell脚本停止Web服务器。
  4. shell脚本指示应用程序服务器检出最新的git更新。
  5. shell脚本指示Web服务器检出最新的git更新。
  6. shell脚本启动应用程序服务器。
  7. shell脚本启动Web服务器。

7个步骤中的每个步骤都是一个接一个地同步完成的。总运行时间约为9秒。然而,为了减少停机时间,许多步骤可以异步完成。

例如,步骤4和5可以同时完成。我想异步启动第4步和第5步(例如在后台运行),但我无法找到如何等待它们都完成之后再继续。在您的脚本(截至&)在后台

回答

4

启动步骤4和5,然后只需调用等待bash,那么你正在寻找wait命令之前跑步步6

3

内置。

wait: wait [id] 
    Wait for job completion and return exit status. 

    Waits for the process identified by ID, which may be a process ID or a 
    job specification, and reports its termination status. If ID is not 
    given, waits for all currently active child processes, and the return 
    status is zero. If ID is a a job specification, waits for all processes 
    in the job's pipeline. 

    Exit Status: 
    Returns the status of ID; fails if ID is invalid or an invalid option is 
    given. 
7

您可能需要使用命令分组,以保持它的步骤必须同步:

step1 
(step2 && step4 && step6) & 
(step3 && step5 && step7) & 
wait && echo "all done"