Clustering service for managing homogeneous objects in 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.

327 lines
11KB

  1. #!/bin/bash
  2. #
  3. # lib/senlin
  4. # Install and start **Senlin** service
  5. # To enable, add the following to local.conf
  6. #
  7. # [[local|localrc]]
  8. # enable_plugin senlin https://git.openstack.org/openstack/senlin
  9. # Dependencies:
  10. #
  11. # - functions
  12. # - HORIZON_DIR
  13. # stack.sh
  14. # ---------
  15. # - config_senlin_dashboard
  16. # - configure_senlin
  17. # - cleanup_senlin
  18. # - cleanup_senlin_dashboard
  19. # - create_senlin_cache_dir
  20. # - create_senlin_accounts
  21. # - init_senlin
  22. # - install_senlinclient
  23. # - install_senlin
  24. # - install_senlin_dashboard
  25. # - is_senlin_enabled
  26. # - start_senlin
  27. # - stop_senlin
  28. # Save trace setting
  29. XTRACE=$(set +o | grep xtrace)
  30. set +o xtrace
  31. # Defaults
  32. # --------
  33. # set up default
  34. SENLIN_AUTH_CACHE_DIR=${SENLIN_AUTH_CACHE_DIR:-/var/cache/senlin}
  35. SENLIN_CONF_DIR=/etc/senlin
  36. SENLIN_CONF=$SENLIN_CONF_DIR/senlin.conf
  37. SENLIN_API_HOST=${SENLIN_API_HOST:-$SERVICE_HOST}
  38. SENLIN_WSGI_MODE=${SENLIN_WSGI_MODE:-"uwsgi"}
  39. SENLIN_DIR=$DEST/senlin
  40. if [[ ${USE_VENV} = True ]]; then
  41. PROJECT_VENV["senlin"]=${SENLIN_DIR}.venv
  42. SENLIN_BIN_DIR=${PROJECT_VENV["senlin"]}/bin
  43. else
  44. SENLIN_BIN_DIR=$(get_python_exec_prefix)
  45. fi
  46. SENLIN_REPO=${SENLIN_REPO:-${GIT_BASE}/openstack/senlin.git}
  47. SENLIN_BRANCH=${SENLIN_BRANCH:-master}
  48. SENLINCLIENT_DIR=$DEST/python-senlinclient
  49. SENLINCLIENT_REPO=${SENLINCLIENT_REPO:-${GIT_BASE}/openstack/python-senlinclient.git}
  50. SENLINCLIENT_BRANCH=${SENLINCLIENT_BRANCH:-master}
  51. SENLIN_DASHBOARD_DIR=$DEST/senlin-dashboard
  52. SENLIN_DASHBOARD_REPO=${SENLIN_DASHBOARD_REPO:-${GIT_BASE}/openstack/senlin-dashboard.git}
  53. SENLIN_DASHBOARD_BRANCH=${SENLIN_DASHBOARD_BRANCH:-master}
  54. SENLIN_UWSGI=$SENLIN_BIN_DIR/senlin-wsgi-api
  55. SENLIN_UWSGI_CONF=$SENLIN_CONF_DIR/senlin-api-uwsgi.ini
  56. if is_service_enabled tls-proxy; then
  57. SENLIN_SERVICE_PROTOCOL="https"
  58. fi
  59. SENLIN_SERVICE_PROTOCOL=${SENLIN_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
  60. # Functions
  61. # ---------
  62. # Test if any Senlin services are enabled
  63. function is_senlin_enabled {
  64. [[ ,${ENABLED_SERVICES} =~ ,"sl-" ]] && return 0
  65. return 1
  66. }
  67. # cleanup_senlin() - Remove residual data files, anything left over from previous
  68. # runs that a clean run would need to clean up
  69. function cleanup_senlin {
  70. sudo rm -f $(apache_site_config_for senlin-api)
  71. remove_uwsgi_config "$SENLIN_UWSGI_CONF" "$SENLIN_UWSGI"
  72. sudo rm -rf $SENLIN_AUTH_CACHE_DIR
  73. sudo rm -rf $SENLIN_CONF_DIR
  74. }
  75. # configure_senlin() - Set config files, create data dirs, etc
  76. function configure_senlin {
  77. if [[ ! -d $SENLIN_CONF_DIR ]]; then
  78. sudo mkdir -p $SENLIN_CONF_DIR
  79. fi
  80. sudo chown $STACK_USER $SENLIN_CONF_DIR
  81. sudo install -d -o $STACK_USER $SENLIN_CONF_DIR
  82. SENLIN_API_PASTE_FILE=$SENLIN_CONF_DIR/api-paste.ini
  83. cp $SENLIN_DIR/etc/senlin/api-paste.ini $SENLIN_API_PASTE_FILE
  84. # common options
  85. iniset $SENLIN_CONF DEFAULT debug "$ENABLE_DEBUG_LOG_LEVEL"
  86. iniset $SENLIN_CONF DEFAULT auth_encryption_key $(generate_hex_string 16)
  87. iniset $SENLIN_CONF DEFAULT default_region_name "$REGION_NAME"
  88. if [ "$USE_SYSTEMD" != "False" ]; then
  89. setup_systemd_logging $SENLIN_CONF
  90. fi
  91. if [ "$LOG_COLOR" == "True" ] && [ "$USE_SYSTEMD" == "False" ]; then
  92. # Add color to logging output
  93. setup_colorized_logging $SENLIN_CONF DEFAULT
  94. fi
  95. # rpc
  96. iniset_rpc_backend senlin $SENLIN_CONF
  97. # Database connection
  98. iniset $SENLIN_CONF database connection `database_connection_url senlin`
  99. # Keystone authtoken middleware
  100. #configure_auth_token_middleware $SENLIN_CONF senlin $SENLIN_AUTH_CACHE_DIR
  101. iniset $SENLIN_CONF keystone_authtoken cafile $SSL_BUNDLE_FILE
  102. iniset $SENLIN_CONF keystone_authtoken auth_url $KEYSTONE_AUTH_URI
  103. iniset $SENLIN_CONF keystone_authtoken www_authenticate_uri $KEYSTONE_SERVICE_URI_V3
  104. iniset $SENLIN_CONF keystone_authtoken username senlin
  105. iniset $SENLIN_CONF keystone_authtoken password $SERVICE_PASSWORD
  106. iniset $SENLIN_CONF keystone_authtoken project_name $SERVICE_TENANT_NAME
  107. iniset $SENLIN_CONF keystone_authtoken project_domain_name Default
  108. iniset $SENLIN_CONF keystone_authtoken user_domain_name Default
  109. iniset $SENLIN_CONF keystone_authtoken auth_type password
  110. iniset $SENLIN_CONF keystone_authtoken service_token_roles_required True
  111. # Senlin service credentials
  112. iniset $SENLIN_CONF authentication auth_url $KEYSTONE_AUTH_URI/v3
  113. iniset $SENLIN_CONF authentication service_username senlin
  114. iniset $SENLIN_CONF authentication service_password $SERVICE_PASSWORD
  115. iniset $SENLIN_CONF authentication service_project_name $SERVICE_TENANT_NAME
  116. # Senlin Conductor options
  117. iniset $SENLIN_CONF conductor workers $API_WORKERS
  118. # Senlin Conductor options
  119. iniset $SENLIN_CONF engine workers $API_WORKERS
  120. # Senlin Health-Manager options
  121. iniset $SENLIN_CONF health_manager workers $API_WORKERS
  122. # Zaqar options for message receiver
  123. iniset $SENLIN_CONF zaqar auth_type password
  124. iniset $SENLIN_CONF zaqar username zaqar
  125. iniset $SENLIN_CONF zaqar password $SERVICE_PASSWORD
  126. iniset $SENLIN_CONF zaqar project_name $SERVICE_TENANT_NAME
  127. iniset $SENLIN_CONF zaqar auth_url $KEYSTONE_AUTH_URI/v3
  128. iniset $SENLIN_CONF zaqar user_domain_name Default
  129. iniset $SENLIN_CONF zaqar project_domain_name Default
  130. if [[ "$SENLIN_WSGI_MODE" == "uwsgi" ]]; then
  131. write_uwsgi_config "$SENLIN_UWSGI_CONF" "$SENLIN_UWSGI" "/cluster"
  132. else
  133. _config_senlin_apache_wsgi
  134. fi
  135. }
  136. # _config_senlin_apache_wsgi() - Configure mod_wsgi
  137. function _config_senlin_apache_wsgi {
  138. local senlin_api_apache_conf
  139. local venv_path=""
  140. local senlin_bin_dir=""
  141. senlin_bin_dir=$(get_python_exec_prefix)
  142. senlin_api_apache_conf=$(apache_site_config_for senlin-api)
  143. if [[ ${USE_VENV} = True ]]; then
  144. venv_path="python-path=${PROJECT_VENV["senlin"]}/lib/$(python_version)/site-packages"
  145. senlin_bin_dir=${PROJECT_VENV["senlin"]}/bin
  146. fi
  147. sudo cp $SENLIN_DIR/devstack/files/apache-senlin-api.template $senlin_api_apache_conf
  148. sudo sed -e "
  149. s|%APACHE_NAME%|$APACHE_NAME|g;
  150. s|%SENLIN_BIN_DIR%|$SENLIN_BIN_DIR|g;
  151. s|%SSLENGINE%|$senlin_ssl|g;
  152. s|%SSLCERTFILE%|$senlin_certfile|g;
  153. s|%SSLKEYFILE%|$senlin_keyfile|g;
  154. s|%USER%|$STACK_USER|g;
  155. s|%VIRTUALENV%|$venv_path|g;
  156. s|%APIWORKERS%|$API_WORKERS|g;
  157. " -i $senlin_api_apache_conf
  158. }
  159. # init_senlin() - Initialize database
  160. function init_senlin {
  161. # (re)create senlin database
  162. recreate_database senlin utf8
  163. $SENLIN_BIN_DIR/senlin-manage db_sync
  164. create_senlin_cache_dir
  165. }
  166. # create_senlin_cache_dir() - Part of the init_senlin() process
  167. function create_senlin_cache_dir {
  168. # Create cache dirs
  169. sudo mkdir -p $SENLIN_AUTH_CACHE_DIR
  170. sudo install -d -o $STACK_USER $SENLIN_AUTH_CACHE_DIR
  171. }
  172. # install_senlinclient() - Collect source and prepare
  173. function install_senlinclient {
  174. if use_library_from_git "python-senlinclient"; then
  175. git_clone $SENLINCLIENT_REPO $SENLINCLIENT_DIR $SENLINCLIENT_BRANCH
  176. setup_develop $SENLINCLIENT_DIR
  177. else
  178. pip_install --upgrade python-senlinclient
  179. fi
  180. }
  181. # install_senlin_dashboard() - Collect source and prepare
  182. function install_senlin_dashboard {
  183. # NOTE(Liuqing): workaround for devstack bug: 1540328
  184. # https://bugs.launchpad.net/devstack/+bug/1540328
  185. # where devstack install 'test-requirements' but should not do it
  186. # for senlin-dashboard project as it installs Horizon from url.
  187. # Remove following two 'mv' commands when mentioned bug is fixed.
  188. if use_library_from_git "senlin-dashboard"; then
  189. git_clone $SENLIN_DASHBOARD_REPO $SENLIN_DASHBOARD_DIR $SENLIN_DASHBOARD_BRANCH
  190. mv $SENLIN_DASHBOARD_DIR/test-requirements.txt $SENLIN_DASHBOARD_DIR/_test-requirements.txt
  191. setup_develop $SENLIN_DASHBOARD_DIR
  192. mv $SENLIN_DASHBOARD_DIR/_test-requirements.txt $SENLIN_DASHBOARD_DIR/test-requirements.txt
  193. else
  194. pip_install --upgrade senlin-dashboard
  195. fi
  196. }
  197. # configure_senlin_dashboard() - Set config files
  198. function config_senlin_dashboard {
  199. # Install Senlin Dashboard as plugin for Horizon
  200. ln -sf $SENLIN_DASHBOARD_DIR/senlin_dashboard/enabled/_50_senlin.py $HORIZON_DIR/openstack_dashboard/local/enabled/_50_senlin.py
  201. # Enable senlin policy
  202. ln -sf $SENLIN_DASHBOARD_DIR/senlin_dashboard/conf/senlin_policy.json $HORIZON_DIR/openstack_dashboard/conf/senlin_policy.json
  203. }
  204. # cleanup_senlin_dashboard() - Remove residual data files, anything left over from previous
  205. # runs that a clean run would need to clean up
  206. function cleanup_senlin_dashboard {
  207. sudo rm -rf $HORIZON_DIR/openstack_dashboard/local/enabled/_50_senlin.py
  208. sudo rm -rf $HORIZON_DIR/openstack_dashboard/conf/senlin_policy.json
  209. }
  210. # install_senlin() - Collect source and prepare
  211. function install_senlin {
  212. if [[ "$SENLIN_WSGI_MODE" == "uwsgi" ]]; then
  213. install_apache_uwsgi
  214. else
  215. install_apache_wsgi
  216. fi
  217. git_clone $SENLIN_REPO $SENLIN_DIR $SENLIN_BRANCH
  218. setup_develop $SENLIN_DIR
  219. }
  220. # start_senlin() - Start running processes, including screen
  221. function start_senlin {
  222. run_process sl-eng "$SENLIN_BIN_DIR/senlin-engine --config-file=$SENLIN_CONF"
  223. run_process sl-conductor "$SENLIN_BIN_DIR/senlin-conductor --config-file=$SENLIN_CONF"
  224. run_process sl-health-manager "$SENLIN_BIN_DIR/senlin-health-manager --config-file=$SENLIN_CONF"
  225. if [[ "$SENLIN_WSGI_MODE" == "uwsgi" ]]; then
  226. run_process sl-api "$SENLIN_BIN_DIR/uwsgi --procname-prefix senlin-api --ini $SENLIN_UWSGI_CONF"
  227. else
  228. enable_apache_site senlin-api
  229. restart_apache_server
  230. tail_log senlin-api /var/log/$APACHE_NAME/senlin-api.log
  231. fi
  232. echo "Waiting for senlin-api to start..."
  233. if ! wait_for_service $SERVICE_TIMEOUT $SENLIN_SERVICE_PROTOCOL://$SENLIN_API_HOST/cluster; then
  234. die $LINENO "senlin-api did not start"
  235. fi
  236. }
  237. # stop_senlin() - Stop running processes
  238. function stop_senlin {
  239. # Kill the screen windows
  240. stop_process sl-eng
  241. stop_process sl-conductor
  242. stop_process sl-health-manager
  243. if [[ "$SENLIN_WSGI_MODE" == "uwsgi" ]]; then
  244. stop_process sl-api
  245. else
  246. disable_apache_site senlin-api
  247. restart_apache_server
  248. fi
  249. }
  250. # create_senlin_accounts() - Set up common required senlin accounts
  251. function create_senlin_accounts {
  252. create_service_user "senlin"
  253. local senlin_api_url="$SENLIN_SERVICE_PROTOCOL://$SENLIN_API_HOST/cluster"
  254. get_or_create_service "senlin" "clustering" "Senlin Clustering Service"
  255. get_or_create_endpoint "clustering" \
  256. "$REGION_NAME" \
  257. "$senlin_api_url" \
  258. "$senlin_api_url" \
  259. "$senlin_api_url"
  260. # get or add 'service' role to 'senlin' on 'demo' project
  261. get_or_add_user_project_role "service" "senlin" "demo"
  262. }
  263. # Restore xtrace
  264. $XTRACE
  265. # Tell emacs to use shell-script-mode
  266. ## Local variables:
  267. ## mode: shell-script
  268. ## End: