Skip to content

Instantly share code, notes, and snippets.

@ErykDarnowski
Last active April 30, 2023 10:50
Show Gist options
  • Save ErykDarnowski/6712a5f49cdb74de5a432a84fd18acf7 to your computer and use it in GitHub Desktop.
Save ErykDarnowski/6712a5f49cdb74de5a432a84fd18acf7 to your computer and use it in GitHub Desktop.
How to check if Laravel's `sail up` command is finished (if all the containers are healthy) before doing other actions (like migrating a DB and so on) in bash. Concept by @rosiakpiotr execution by me :)
#!/bin/bash
check_sail_containers_status() {
# A bit of delay to not run the function too quickly:
sleep 2
# Getting current container state:
local STATUS=$(sudo ./vendor/bin/sail ps | grep starting)
# Checking if they're healthy:
if ! [ "$STATUS" == "" ]; then
# Recursively running the function:
check_sail_containers_status
fi
}
# Starting sail in detached mode:
sudo ./vendor/bin/sail up -d
echo -e "\nChecking sail containers state..."
check_sail_containers_status
echo -e "\nAll containers HEALTHY\n"
# Here you can be sure that the containers are healthy and thus you can safely do anything you need with them.
# ---
# To to be more user friendly and indicate activity happening in the background, you can use this spinner animation: <https://stackoverflow.com/a/12498305/11749019>!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment