Multi-Experience Operations (MEO) includes a post-site-create hook. Use this script to automate setup tasks after you create or duplicate a site.
Purpose of the hook
Automate common tasks to avoid manual configuration:
- Update configuration: Set specific Drupal variables or site names.
- Manage modules: Enable required modules or deactivate unnecessary modules.
- Clear caches: Rebuild Drupal or Varnish caches so the site is ready.
- Connect services: Register the new site URL with external monitoring or security tools.
Set up the hook
Insert the executable command (Bash or PHP) in the following directory in the codebase: hooks/common/post-site-create/
After the hook triggers, Cloud Platform passes these four arguments to the script:
- site: Name of the new site.
- target_env: Environment that hosts the site, such as dev or prod.
- db_name: Name of the new database.
- source_site: Name of the template site if you use the Duplicate Site feature.
Best practices
- Write idempotent scripts: Ensure that the script runs safely multiple times without errors.
- Add error handling: Use logic to catch failures so that a script error does not stop the workflow.
- Use logs: Use echo statements to track progress. You can access these logs in the Task Log on Cloud Platform.
- Prioritize security: Avoid hardcoding passwords. Use environment variables or platform Drush aliases instead.
Monitor hooks
To monitor the script:
- Sign in to the Cloud Platform user interface.
- Go to Codebases.
The system displays all available codebases along with the number of sites and environments associated with the codebases. - Click Overview and ensure the Task Log contains the post-site-create entry.
Post-site creation hooks
Multi-Experience Operations (MEO) includes a post-site-create hook. Use this script to automate setup tasks after you create or duplicate a site.
Purpose of the hook
Automate common tasks to avoid manual configuration:
- Update configuration: Set specific Drupal variables or site names.
- Manage modules: Enable required modules or deactivate unnecessary modules.
- Clear caches: Rebuild Drupal or Varnish caches so the site is ready.
- Connect services: Register the new site URL with external monitoring or security tools.
Set up the hook
Insert the executable command (Bash or PHP) in the following directory in the codebase: hooks/common/post-site-create/
After the hook triggers, Cloud Platform passes these four arguments to the script:
- site: Name of the new site.
- target_env: Environment that hosts the site, such as dev or prod.
- db_name: Name of the new database.
- source_site: Name of the template site if you use the Duplicate Site feature.
Best practices
- Write idempotent scripts: Ensure that the script runs safely multiple times without errors.
- Add error handling: Use logic to catch failures so that a script error does not stop the workflow.
- Use logs: Use echo statements to track progress. You can access these logs in the Task Log on Cloud Platform.
- Prioritize security: Avoid hardcoding passwords. Use environment variables or platform Drush aliases instead.
Monitor hooks
To monitor the script:
- Sign in to the Cloud Platform user interface.
- Go to Codebases.
The system displays all available codebases along with the number of sites and environments associated with the codebases. - Click Overview and ensure the Task Log contains the post-site-create entry.