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.

306 lines
9.5 KiB

  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. if is_fedora; then
  100. if python3_enabled; then
  101. real_install_package python3-nose
  102. else
  103. real_install_package python2-nose
  104. fi
  105. else
  106. real_install_package python-nose
  107. fi
  108. if is_service_enabled horizon; then
  109. _install_mistraldashboard
  110. fi
  111. if [ "$MISTRAL_USE_MOD_WSGI" == "True" ]; then
  112. install_apache_wsgi
  113. fi
  114. }
  115. function _install_mistraldashboard {
  116. git_clone $MISTRAL_DASHBOARD_REPO $MISTRAL_DASHBOARD_DIR $MISTRAL_DASHBOARD_BRANCH
  117. setup_develop $MISTRAL_DASHBOARD_DIR
  118. ln -fs $MISTRAL_DASHBOARD_DIR/mistraldashboard/enabled/_50_mistral.py $HORIZON_DIR/openstack_dashboard/local/enabled/_50_mistral.py
  119. }
  120. function install_mistral_pythonclient {
  121. if use_library_from_git "python-mistralclient"; then
  122. git_clone_by_name "python-mistralclient"
  123. setup_dev_lib "python-mistralclient"
  124. sudo install -D -m 0644 -o $STACK_USER {${GITDIR["python-mistralclient"]}/tools/,/etc/bash_completion.d/}mistral.bash_completion
  125. fi
  126. }
  127. function install_mistral_lib {
  128. if use_library_from_git "mistral-lib"; then
  129. git_clone $MISTRAL_LIB_REPO $MISTRAL_LIB_DIR $MISTRAL_LIB_BRANCH
  130. setup_develop $MISTRAL_LIB_DIR
  131. fi
  132. }
  133. function install_mistral_extra {
  134. if use_library_from_git "mistral-extra"; then
  135. git_clone $MISTRAL_EXTRA_REPO $MISTRAL_EXTRA_DIR $MISTRAL_EXTRA_BRANCH
  136. setup_develop $MISTRAL_EXTRA_DIR
  137. fi
  138. }
  139. # start_mistral - Start running processes
  140. function start_mistral {
  141. # If the site is not enabled then we are in a grenade scenario
  142. local enabled_site_file
  143. enabled_site_file=$(apache_site_config_for mistral-api)
  144. if is_service_enabled mistral-api && is_service_enabled mistral-engine && is_service_enabled mistral-executor && is_service_enabled mistral-event-engine ; then
  145. echo_summary "Installing all mistral services in separate processes"
  146. if [ -f ${enabled_site_file} ] && [ "$MISTRAL_USE_MOD_WSGI" == "True" ]; then
  147. enable_apache_site mistral-api
  148. restart_apache_server
  149. else
  150. run_process mistral-api "$MISTRAL_BIN_DIR/mistral-server --server api --config-file $MISTRAL_CONF_DIR/mistral.conf"
  151. fi
  152. run_process mistral-engine "$MISTRAL_BIN_DIR/mistral-server --server engine --config-file $MISTRAL_CONF_DIR/mistral.conf"
  153. run_process mistral-executor "$MISTRAL_BIN_DIR/mistral-server --server executor --config-file $MISTRAL_CONF_DIR/mistral.conf"
  154. run_process mistral-event-engine "$MISTRAL_BIN_DIR/mistral-server --server event-engine --config-file $MISTRAL_CONF_DIR/mistral.conf"
  155. else
  156. echo_summary "Installing all mistral services in one process"
  157. run_process mistral "$MISTRAL_BIN_DIR/mistral-server --server all --config-file $MISTRAL_CONF_DIR/mistral.conf"
  158. fi
  159. }
  160. # stop_mistral - Stop running processes
  161. function stop_mistral {
  162. local serv
  163. for serv in mistral mistral-engine mistral-executor mistral-event-engine; do
  164. stop_process $serv
  165. done
  166. if [ "$MISTRAL_USE_MOD_WSGI" == "True" ]; then
  167. disable_apache_site mistral-api
  168. restart_apache_server
  169. else
  170. stop_process mistral-api
  171. fi
  172. }
  173. function configure_tempest_for_mistral {
  174. if is_service_enabled tempest; then
  175. iniset $TEMPEST_CONFIG mistral_api service_api_supported True
  176. fi
  177. }
  178. function cleanup_mistral {
  179. if is_service_enabled horizon; then
  180. _mistral_cleanup_mistraldashboard
  181. fi
  182. if [ "$MISTRAL_USE_MOD_WSGI" == "True" ]; then
  183. _mistral_cleanup_apache_wsgi
  184. fi
  185. sudo rm -rf $MISTRAL_CONF_DIR
  186. }
  187. function _mistral_cleanup_mistraldashboard {
  188. rm -f $HORIZON_DIR/openstack_dashboard/local/enabled/_50_mistral.py
  189. }
  190. function _mistral_cleanup_apache_wsgi {
  191. sudo rm -f $(apache_site_config_for mistral-api)
  192. }
  193. # _config_mistral_apache_wsgi() - Set WSGI config files for Mistral
  194. function _config_mistral_apache_wsgi {
  195. local mistral_apache_conf
  196. mistral_apache_conf=$(apache_site_config_for mistral-api)
  197. local mistral_ssl=""
  198. local mistral_certfile=""
  199. local mistral_keyfile=""
  200. local mistral_api_port=$MISTRAL_SERVICE_PORT
  201. local venv_path=""
  202. sudo cp $MISTRAL_FILES_DIR/apache-mistral-api.template $mistral_apache_conf
  203. sudo sed -e "
  204. s|%PUBLICPORT%|$mistral_api_port|g;
  205. s|%APACHE_NAME%|$APACHE_NAME|g;
  206. s|%MISTRAL_BIN_DIR%|$MISTRAL_BIN_DIR|g;
  207. s|%API_WORKERS%|$API_WORKERS|g;
  208. s|%SSLENGINE%|$mistral_ssl|g;
  209. s|%SSLCERTFILE%|$mistral_certfile|g;
  210. s|%SSLKEYFILE%|$mistral_keyfile|g;
  211. s|%USER%|$STACK_USER|g;
  212. s|%VIRTUALENV%|$venv_path|g
  213. " -i $mistral_apache_conf
  214. }
  215. if is_service_enabled mistral; then
  216. if [[ "$1" == "stack" && "$2" == "install" ]]; then
  217. echo_summary "Installing mistral"
  218. install_mistral
  219. install_mistral_lib
  220. install_mistral_extra
  221. install_mistral_pythonclient
  222. elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then
  223. echo_summary "Configuring mistral"
  224. create_mistral_accounts
  225. configure_mistral
  226. elif [[ "$1" == "stack" && "$2" == "extra" ]]; then
  227. echo_summary "Initializing mistral"
  228. init_mistral
  229. start_mistral
  230. elif [[ "$1" == "stack" && "$2" == "test-config" ]]; then
  231. echo_summary "Configuring Tempest for Mistral"
  232. configure_tempest_for_mistral
  233. fi
  234. if [[ "$1" == "unstack" ]]; then
  235. echo_summary "Shutting down mistral"
  236. stop_mistral
  237. fi
  238. if [[ "$1" == "clean" ]]; then
  239. echo_summary "Cleaning mistral"
  240. cleanup_mistral
  241. fi
  242. fi
  243. # Restore xtrace
  244. $XTRACE
  245. # Local variables:
  246. # mode: shell-script
  247. # End: