Workflow Service for OpenStack.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

290 lines
9.0KB

  1. # ``stack.sh`` calls the entry points in this order:
  2. #
  3. # install_mistral
  4. # install_python_mistralclient
  5. # configure_mistral
  6. # start_mistral
  7. # stop_mistral
  8. # cleanup_mistral
  9. # Save trace setting
  10. XTRACE=$(set +o | grep xtrace)
  11. set -o xtrace
  12. # Defaults
  13. # --------
  14. # Support entry points installation of console scripts
  15. if [[ -d $MISTRAL_DIR/bin ]]; then
  16. MISTRAL_BIN_DIR=$MISTRAL_DIR/bin
  17. else
  18. MISTRAL_BIN_DIR=$(get_python_exec_prefix)
  19. fi
  20. # Toggle for deploying Mistral API under HTTPD + mod_wsgi
  21. MISTRAL_USE_MOD_WSGI=${MISTRAL_USE_MOD_WSGI:-True}
  22. MISTRAL_FILES_DIR=$MISTRAL_DIR/devstack/files
  23. # create_mistral_accounts - Set up common required mistral accounts
  24. #
  25. # Tenant User Roles
  26. # ------------------------------
  27. # service mistral admin
  28. function create_mistral_accounts {
  29. if ! is_service_enabled key; then
  30. return
  31. fi
  32. create_service_user "mistral" "admin"
  33. get_or_create_service "mistral" "workflowv2" "Workflow Service v2"
  34. get_or_create_endpoint "workflowv2" \
  35. "$REGION_NAME" \
  36. "$MISTRAL_SERVICE_PROTOCOL://$MISTRAL_SERVICE_HOST:$MISTRAL_SERVICE_PORT/v2" \
  37. "$MISTRAL_SERVICE_PROTOCOL://$MISTRAL_SERVICE_HOST:$MISTRAL_SERVICE_PORT/v2" \
  38. "$MISTRAL_SERVICE_PROTOCOL://$MISTRAL_SERVICE_HOST:$MISTRAL_SERVICE_PORT/v2"
  39. }
  40. function mkdir_chown_stack {
  41. if [[ ! -d "$1" ]]; then
  42. sudo mkdir -p "$1"
  43. fi
  44. sudo chown $STACK_USER "$1"
  45. }
  46. # Entry points
  47. # ------------
  48. # configure_mistral - Set config files, create data dirs, etc
  49. function configure_mistral {
  50. # create and clean up auth cache dir
  51. mkdir_chown_stack "$MISTRAL_AUTH_CACHE_DIR"
  52. rm -f "$MISTRAL_AUTH_CACHE_DIR"/*
  53. mkdir_chown_stack "$MISTRAL_CONF_DIR"
  54. # Generate Mistral configuration file and configure common parameters.
  55. oslo-config-generator --config-file $MISTRAL_DIR/tools/config/config-generator.mistral.conf --output-file $MISTRAL_CONF_FILE
  56. iniset $MISTRAL_CONF_FILE DEFAULT debug $MISTRAL_DEBUG
  57. # Run all Mistral processes as a single process
  58. iniset $MISTRAL_CONF_FILE DEFAULT server all
  59. # Mistral Configuration
  60. #-------------------------
  61. # Setup keystone_authtoken section
  62. configure_auth_token_middleware $MISTRAL_CONF_FILE mistral $MISTRAL_AUTH_CACHE_DIR
  63. iniset $MISTRAL_CONF_FILE keystone_authtoken www_authenticate_uri $KEYSTONE_AUTH_URI_V3
  64. # Setup RabbitMQ credentials
  65. iniset_rpc_backend mistral $MISTRAL_CONF_FILE
  66. # Configure the database.
  67. iniset $MISTRAL_CONF_FILE database connection `database_connection_url mistral`
  68. iniset $MISTRAL_CONF_FILE database max_overflow -1
  69. iniset $MISTRAL_CONF_FILE database max_pool_size 1000
  70. # Configure action execution deletion policy
  71. iniset $MISTRAL_CONF_FILE api allow_action_execution_deletion True
  72. # Don't use the default 0.0.0.0 it's good only for ipv4
  73. iniset $MISTRAL_CONF_FILE api host $(ipv6_unquote $MISTRAL_SERVICE_HOST)
  74. if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
  75. setup_colorized_logging $MISTRAL_CONF_FILE DEFAULT tenant user
  76. fi
  77. if [ "$MISTRAL_RPC_IMPLEMENTATION" ]; then
  78. iniset $MISTRAL_CONF_FILE DEFAULT rpc_implementation $MISTRAL_RPC_IMPLEMENTATION
  79. fi
  80. if [ "$MISTRAL_USE_MOD_WSGI" == "True" ]; then
  81. _config_mistral_apache_wsgi
  82. fi
  83. if [[ ! -z "$MISTRAL_COORDINATION_URL" ]]; then
  84. iniset $MISTRAL_CONF_FILE coordination backend_url "$MISTRAL_COORDINATION_URL"
  85. elif is_service_enabled etcd3; then
  86. iniset $MISTRAL_CONF_FILE coordination backend_url "etcd3+http://${SERVICE_HOST}:$ETCD_PORT"
  87. fi
  88. }
  89. # init_mistral - Initialize the database
  90. function init_mistral {
  91. # (re)create Mistral database
  92. recreate_database mistral utf8
  93. $PYTHON $MISTRAL_DIR/tools/sync_db.py --config-file $MISTRAL_CONF_FILE
  94. }
  95. # install_mistral - Collect source and prepare
  96. function install_mistral {
  97. setup_develop $MISTRAL_DIR
  98. # installing python-nose.
  99. real_install_package python-nose
  100. if is_service_enabled horizon; then
  101. _install_mistraldashboard
  102. fi
  103. if [ "$MISTRAL_USE_MOD_WSGI" == "True" ]; then
  104. install_apache_wsgi
  105. fi
  106. }
  107. function _install_mistraldashboard {
  108. git_clone $MISTRAL_DASHBOARD_REPO $MISTRAL_DASHBOARD_DIR $MISTRAL_DASHBOARD_BRANCH
  109. setup_develop $MISTRAL_DASHBOARD_DIR
  110. ln -fs $MISTRAL_DASHBOARD_DIR/mistraldashboard/enabled/_50_mistral.py $HORIZON_DIR/openstack_dashboard/local/enabled/_50_mistral.py
  111. }
  112. function install_mistral_pythonclient {
  113. if use_library_from_git "python-mistralclient"; then
  114. git_clone_by_name "python-mistralclient"
  115. setup_dev_lib "python-mistralclient"
  116. sudo install -D -m 0644 -o $STACK_USER {${GITDIR["python-mistralclient"]}/tools/,/etc/bash_completion.d/}mistral.bash_completion
  117. fi
  118. }
  119. function install_mistral_lib {
  120. if use_library_from_git "mistral-lib"; then
  121. git_clone $MISTRAL_LIB_REPO $MISTRAL_LIB_DIR $MISTRAL_LIB_BRANCH
  122. setup_develop $MISTRAL_LIB_DIR
  123. fi
  124. }
  125. # start_mistral - Start running processes
  126. function start_mistral {
  127. # If the site is not enabled then we are in a grenade scenario
  128. local enabled_site_file
  129. enabled_site_file=$(apache_site_config_for mistral-api)
  130. if is_service_enabled mistral-api && is_service_enabled mistral-engine && is_service_enabled mistral-executor && is_service_enabled mistral-event-engine ; then
  131. echo_summary "Installing all mistral services in separate processes"
  132. if [ -f ${enabled_site_file} ] && [ "$MISTRAL_USE_MOD_WSGI" == "True" ]; then
  133. enable_apache_site mistral-api
  134. restart_apache_server
  135. else
  136. run_process mistral-api "$MISTRAL_BIN_DIR/mistral-server --server api --config-file $MISTRAL_CONF_DIR/mistral.conf"
  137. fi
  138. run_process mistral-engine "$MISTRAL_BIN_DIR/mistral-server --server engine --config-file $MISTRAL_CONF_DIR/mistral.conf"
  139. run_process mistral-executor "$MISTRAL_BIN_DIR/mistral-server --server executor --config-file $MISTRAL_CONF_DIR/mistral.conf"
  140. run_process mistral-event-engine "$MISTRAL_BIN_DIR/mistral-server --server event-engine --config-file $MISTRAL_CONF_DIR/mistral.conf"
  141. else
  142. echo_summary "Installing all mistral services in one process"
  143. run_process mistral "$MISTRAL_BIN_DIR/mistral-server --server all --config-file $MISTRAL_CONF_DIR/mistral.conf"
  144. fi
  145. }
  146. # stop_mistral - Stop running processes
  147. function stop_mistral {
  148. local serv
  149. for serv in mistral mistral-engine mistral-executor mistral-event-engine; do
  150. stop_process $serv
  151. done
  152. if [ "$MISTRAL_USE_MOD_WSGI" == "True" ]; then
  153. disable_apache_site mistral-api
  154. restart_apache_server
  155. else
  156. stop_process mistral-api
  157. fi
  158. }
  159. function configure_tempest_for_mistral {
  160. if is_service_enabled tempest; then
  161. iniset $TEMPEST_CONFIG mistral_api service_api_supported True
  162. fi
  163. }
  164. function cleanup_mistral {
  165. if is_service_enabled horizon; then
  166. _mistral_cleanup_mistraldashboard
  167. fi
  168. if [ "$MISTRAL_USE_MOD_WSGI" == "True" ]; then
  169. _mistral_cleanup_apache_wsgi
  170. fi
  171. sudo rm -rf $MISTRAL_CONF_DIR
  172. }
  173. function _mistral_cleanup_mistraldashboard {
  174. rm -f $HORIZON_DIR/openstack_dashboard/local/enabled/_50_mistral.py
  175. }
  176. function _mistral_cleanup_apache_wsgi {
  177. sudo rm -f $(apache_site_config_for mistral-api)
  178. }
  179. # _config_mistral_apache_wsgi() - Set WSGI config files for Mistral
  180. function _config_mistral_apache_wsgi {
  181. local mistral_apache_conf
  182. mistral_apache_conf=$(apache_site_config_for mistral-api)
  183. local mistral_ssl=""
  184. local mistral_certfile=""
  185. local mistral_keyfile=""
  186. local mistral_api_port=$MISTRAL_SERVICE_PORT
  187. local venv_path=""
  188. sudo cp $MISTRAL_FILES_DIR/apache-mistral-api.template $mistral_apache_conf
  189. sudo sed -e "
  190. s|%PUBLICPORT%|$mistral_api_port|g;
  191. s|%APACHE_NAME%|$APACHE_NAME|g;
  192. s|%MISTRAL_BIN_DIR%|$MISTRAL_BIN_DIR|g;
  193. s|%API_WORKERS%|$API_WORKERS|g;
  194. s|%SSLENGINE%|$mistral_ssl|g;
  195. s|%SSLCERTFILE%|$mistral_certfile|g;
  196. s|%SSLKEYFILE%|$mistral_keyfile|g;
  197. s|%USER%|$STACK_USER|g;
  198. s|%VIRTUALENV%|$venv_path|g
  199. " -i $mistral_apache_conf
  200. }
  201. if is_service_enabled mistral; then
  202. if [[ "$1" == "stack" && "$2" == "install" ]]; then
  203. echo_summary "Installing mistral"
  204. install_mistral
  205. install_mistral_lib
  206. install_mistral_pythonclient
  207. elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then
  208. echo_summary "Configuring mistral"
  209. create_mistral_accounts
  210. configure_mistral
  211. elif [[ "$1" == "stack" && "$2" == "extra" ]]; then
  212. echo_summary "Initializing mistral"
  213. init_mistral
  214. start_mistral
  215. elif [[ "$1" == "stack" && "$2" == "test-config" ]]; then
  216. echo_summary "Configuring Tempest for Mistral"
  217. configure_tempest_for_mistral
  218. fi
  219. if [[ "$1" == "unstack" ]]; then
  220. echo_summary "Shutting down mistral"
  221. stop_mistral
  222. fi
  223. if [[ "$1" == "clean" ]]; then
  224. echo_summary "Cleaning mistral"
  225. cleanup_mistral
  226. fi
  227. fi
  228. # Restore xtrace
  229. $XTRACE
  230. # Local variables:
  231. # mode: shell-script
  232. # End: