|
| 1 | +# Exec Child Example |
| 2 | + |
| 3 | +This example demonstrates how to execute a child process using the `exec` function in a container. |
| 4 | + |
| 5 | +## Usage |
| 6 | + |
| 7 | +Start the main controller: |
| 8 | + |
| 9 | +``` |
| 10 | +> bundle exec ./start |
| 11 | + 0.0s info: AppController [oid=0x938] [ec=0x94c] [pid=96758] [2024-12-12 14:33:45 +1300] |
| 12 | + | Controller starting... |
| 13 | + 0.65s info: Jobs [oid=0x8e8] [ec=0x8fc] [pid=96763] [2024-12-12 14:33:45 +1300] |
| 14 | + | Starting jobs... |
| 15 | + 0.65s info: Jobs [oid=0x8e8] [ec=0x8fc] [pid=96763] [2024-12-12 14:33:45 +1300] |
| 16 | + | Notifying container ready... |
| 17 | + 0.65s info: Jobs [oid=0x8e8] [ec=0x8fc] [pid=96763] [2024-12-12 14:33:45 +1300] |
| 18 | + | Jobs running... |
| 19 | + 0.65s info: Web [oid=0x8e8] [ec=0x8fc] [pid=96760] [2024-12-12 14:33:45 +1300] |
| 20 | + | Starting web... |
| 21 | + 0.65s info: Web [oid=0x8e8] [ec=0x8fc] [pid=96760] [2024-12-12 14:33:45 +1300] |
| 22 | + | Notifying container ready... |
| 23 | + 0.65s info: Web [oid=0x8e8] [ec=0x8fc] [pid=96760] [2024-12-12 14:33:45 +1300] |
| 24 | + | Web running... |
| 25 | + 0.09s info: AppController [oid=0x938] [ec=0x94c] [pid=96758] [2024-12-12 14:33:45 +1300] |
| 26 | + | Controller started... |
| 27 | +``` |
| 28 | + |
| 29 | +In another terminal: `kill -HUP 96758` to cause a blue-green restart, which causes a new container to be started with new jobs and web processes: |
| 30 | + |
| 31 | +``` |
| 32 | + 9.57s info: Jobs [oid=0x8e8] [ec=0x8fc] [pid=96836] [2024-12-12 14:33:54 +1300] |
| 33 | + | Starting jobs... |
| 34 | + 9.57s info: Web [oid=0x8e8] [ec=0x8fc] [pid=96833] [2024-12-12 14:33:54 +1300] |
| 35 | + | Starting web... |
| 36 | + 9.57s info: Jobs [oid=0x8e8] [ec=0x8fc] [pid=96836] [2024-12-12 14:33:54 +1300] |
| 37 | + | Notifying container ready... |
| 38 | + 9.57s info: Web [oid=0x8e8] [ec=0x8fc] [pid=96833] [2024-12-12 14:33:54 +1300] |
| 39 | + | Notifying container ready... |
| 40 | + 9.57s info: Jobs [oid=0x8e8] [ec=0x8fc] [pid=96836] [2024-12-12 14:33:54 +1300] |
| 41 | + | Jobs running... |
| 42 | + 9.57s info: Web [oid=0x8e8] [ec=0x8fc] [pid=96833] [2024-12-12 14:33:54 +1300] |
| 43 | + | Web running... |
| 44 | +``` |
| 45 | + |
| 46 | +Once the new container is running and the child processes have notified they are ready, the controller will stop the old container: |
| 47 | + |
| 48 | +``` |
| 49 | + 9.01s info: Async::Container::Group [oid=0xa00] [ec=0x94c] [pid=96758] [2024-12-12 14:33:54 +1300] |
| 50 | + | Stopping all processes... |
| 51 | + | { |
| 52 | + | "timeout": true |
| 53 | + | } |
| 54 | + 9.01s info: Async::Container::Group [oid=0xa00] [ec=0x94c] [pid=96758] [2024-12-12 14:33:54 +1300] |
| 55 | + | Sending interrupt to 2 running processes... |
| 56 | + 9.57s info: Web [oid=0x8e8] [ec=0x8fc] [pid=96760] [2024-12-12 14:33:54 +1300] |
| 57 | + | Exiting web... |
| 58 | + 9.57s info: Jobs [oid=0x8e8] [ec=0x8fc] [pid=96763] [2024-12-12 14:33:54 +1300] |
| 59 | + | Exiting jobs... |
| 60 | +``` |
| 61 | + |
| 62 | +The new container continues to run as expected: |
| 63 | + |
| 64 | +``` |
| 65 | +19.57s info: Web [oid=0x8e8] [ec=0x8fc] [pid=96833] [2024-12-12 14:34:04 +1300] |
| 66 | + | Web running... |
| 67 | +19.57s info: Jobs [oid=0x8e8] [ec=0x8fc] [pid=96836] [2024-12-12 14:34:04 +1300] |
| 68 | + | Jobs running... |
| 69 | +``` |
0 commit comments