bootstrap.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <h1>The Drush Bootstrap Process</h1>
  2. <p>
  3. When preparing to run a command, drush works by "bootstrapping"
  4. the Drupal environment in very much the same way that is done
  5. during a normal page request from the web server, so most drush
  6. commands run in the context of a fully-initialized website.
  7. <p>
  8. For efficiency and convenience, some drush commands can work
  9. without first bootstrapping a Drupal site, or by only partially
  10. bootstrapping a site. This is more efficient, because there is
  11. sometimes a slight delay involved with bootstrapping, especially
  12. in some of the later stages. It is also a matter of convenience,
  13. because some commands are useful to use even when you do not
  14. have a working Drupal site available to bootstrap. For example,
  15. you can use drush to download Drupal with `drush dl drupal`. This
  16. obviously does not require any bootstrapping to work.
  17. <p>
  18. The drush bootstrapping process is also very closely related with
  19. drush configuration files. At each bootstrap phase, drush may load
  20. additional configuration files that may contain additional drush
  21. settings. This has two very important connotations. First, settings
  22. that are only loaded in a later bootstrap phase are not available
  23. for commands that do not reach that bootstrap phase. Second, it
  24. is possible to alter drush behavior on a per-site basis by applying
  25. settings in a site-specific configuration file. See
  26. `drush topic docs-configuration` for details on drush configuration
  27. files.
  28. <h2>DRUSH_BOOTSTRAP_DRUSH</h2>
  29. <p>
  30. Configuration files loaded during this phase:<ul>
  31. <li>Drush installation folder.
  32. <li>System wide configuration folder (e.g. /etc/drush/drushrc.php).
  33. <li>User's .drush folder (i.e. ~/.drush/drushrc.php).
  34. <li>In any location, as specified by the --config (-c) option.
  35. </ul><p>
  36. Only bootstrap Drush, without any Drupal specific code.
  37. <p>
  38. Any code that operates on the Drush installation, and not specifically
  39. any Drupal directory, should bootstrap to this phase.
  40. <h2>DRUSH_BOOTSTRAP_DRUPAL_ROOT</h2>
  41. <p>
  42. Configuration files loaded during this phase:<ul>
  43. <li>Drupal installation root.
  44. </ul><p>
  45. Set up and test for a valid drupal root, either through the -r/--root options,
  46. or evaluated based on the current working directory.
  47. <p>
  48. Any code that interacts with an entire Drupal installation, and not a specific
  49. site on the Drupal installation should use this bootstrap phase.
  50. <h2>DRUSH_BOOTSTRAP_DRUPAL_SITE</h2>
  51. <p>
  52. Configuration files loaded during this phase:<ul>
  53. <li>Drupal site folder (e.g sites/{default|example.com}/drushrc.php).
  54. </ul><p>
  55. Set up a Drupal site directory and the correct environment variables to
  56. allow Drupal to find the configuration file.
  57. <p>
  58. If no site is specified with the -l / --uri options, Drush will assume the
  59. site is 'default', which mimics Drupal's behaviour.
  60. <p>
  61. If you want to avoid this behaviour, it is recommended that you use the
  62. DRUSH_BOOTSTRAP_DRUPAL_ROOT bootstrap phase instead.
  63. <p>
  64. Any code that needs to modify or interact with a specific Drupal site's
  65. settings.php file should bootstrap to this phase.
  66. <h2>DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION</h2>
  67. <p>
  68. Load the settings from the Drupal sites directory.
  69. <p>
  70. This phase is analagous to the DRUPAL_BOOTSTRAP_CONFIGURATION bootstrap phase in Drupal
  71. itself, and this is also the first step where Drupal specific code is included.
  72. <p>
  73. This phase is commonly used for code that interacts with the Drupal install API,
  74. as both install.php and update.php start at this phase.
  75. <h2>DRUSH_BOOTSTRAP_DRUPAL_DATABASE</h2>
  76. <p>
  77. Connect to the Drupal database using the database credentials loaded
  78. during the previous bootstrap phase.
  79. <p>
  80. This phase is analogous to the DRUPAL_BOOTSTRAP_DATABASE bootstrap phase in
  81. Drupal.
  82. <p>
  83. Any code that needs to interact with the Drupal database API needs to
  84. be bootstrapped to at least this phase.
  85. <h2>DRUSH_BOOTSTRAP_DRUPAL_FULL</h2>
  86. <p>
  87. Fully initialize Drupal.
  88. <p>
  89. This is the default bootstrap phase all commands will try to reach,
  90. unless otherwise specified.
  91. This is analogous to the DRUPAL_BOOTSTRAP_FULL bootstrap phase in
  92. Drupal.
  93. <p>
  94. Any code that interacts with the general Drupal API should be
  95. bootstrapped to this phase.
  96. <h2>DRUSH_BOOTSTRAP_DRUPAL_LOGIN</h2>
  97. <p>
  98. Log in to the initialiased Drupal site.
  99. <p>
  100. This bootstrap phase is used after the site has been
  101. fully bootstrapped.
  102. <p>
  103. This phase will log you in to the drupal site with the username
  104. or user ID specified by the --user/ -u option.
  105. <p>
  106. Use this bootstrap phase for your command if you need to have access
  107. to information for a specific user, such as listing nodes that might
  108. be different based on who is logged in.
  109. <h2>DRUSH_BOOTSTRAP_MAX</h2>
  110. <p>
  111. This is not an actual bootstrap phase. Commands that use
  112. DRUSH_BOOTSTRAP_MAX will cause drush to bootstrap as far
  113. as possible, and then run the command regardless of the
  114. bootstrap phase that was reached. This is useful for drush
  115. commands that work without a bootstrapped site, but that
  116. provide additional information or capabilities in the presence
  117. of a bootstrapped site. For example, `drush pm-releases modulename`
  118. works without a bootstrapped Drupal site, but will include
  119. the version number for the installed module if a Drupal site
  120. has been bootstrapped.