An OpenStack project designed to make cloud services easier to consume and integrate into your application development process. See: https://wiki.openstack.org/wiki/Solum
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.

469 lines
17KB

  1. #!/usr/bin/env/ bash
  2. # Plugin file for Solum services
  3. #-------------------------------
  4. # Dependencies:
  5. # ``functions`` file
  6. # ``DEST``, ``DATA_DIR``, ``STACK_USER`` must be defined
  7. # ``ADMIN_{TENANT_NAME|PASSWORD}`` must be defined
  8. # ``stack.sh`` calls the entry points in this order:
  9. #
  10. # install_solum
  11. # install_solumclient
  12. # configure_solum
  13. # start_solum
  14. # stop_solum
  15. # Save trace setting
  16. XTRACE=$(set +o | grep xtrace)
  17. set -o xtrace
  18. # Defaults
  19. # --------
  20. GITREPO["solum-dashboard"]=${SOLUMDASHBOARD_REPO:-${GIT_BASE}/openstack/solum-dashboard.git}
  21. GITBRANCH["solum-dashboard"]=${SOLUMDASHBOARD_BRANCH:-master}
  22. GITDIR["solum-dashboard"]=$DEST/solum-dashboard
  23. # Support entry points installation of console scripts
  24. if [[ -d $SOLUM_DIR/bin ]]; then
  25. SOLUM_BIN_DIR=$SOLUM_DIR/bin
  26. else
  27. SOLUM_BIN_DIR=$(get_python_exec_prefix)
  28. fi
  29. # Toggle for deploying Solum-API under HTTPD + mod_wsgi
  30. SOLUM_USE_MOD_WSGI=${SOLUM_USE_MOD_WSGI:-False}
  31. # Toggle for deploying Solum-API under uwsgi
  32. SOLUM_USE_UWSGI=${SOLUM_USE_UWSGI:-True}
  33. SOLUM_UWSGI=$SOLUM_BIN_DIR/solum-wsgi-api
  34. SOLUM_UWSGI_CONF=$SOLUM_CONF_DIR/solum-api-uwsgi.ini
  35. if [[ "$SOLUM_USE_UWSGI" == "True" ]]; then
  36. SOLUM_API_URL="$SOLUM_SERVICE_PROTOCOL://$SOLUM_SERVICE_HOST/application_deployment"
  37. else
  38. SOLUM_API_URL="$SOLUM_SERVICE_PROTOCOL://$SOLUM_SERVICE_HOST:$SOLUM_SERVICE_PORT"
  39. fi
  40. # Functions
  41. # ---------
  42. # create_solum_service_and_endpoint() - Set up required solum service and endpoint
  43. function create_solum_service_and_endpoint() {
  44. SOLUM_UPDATE_ROLE=$(get_or_create_role "solum_assembly_update")
  45. # Give the role to the demo and admin users so they can use git push
  46. # in either of the projects created by devstack
  47. get_or_add_user_project_role $SOLUM_UPDATE_ROLE demo demo
  48. get_or_add_user_project_role $SOLUM_UPDATE_ROLE admin demo
  49. get_or_add_user_project_role $SOLUM_UPDATE_ROLE admin admin
  50. SOLUM_SERVICE=$(get_or_create_service "solum" "application_deployment" "Solum Service")
  51. get_or_create_endpoint "application_deployment" \
  52. "$REGION_NAME" \
  53. "$SOLUM_API_URL" \
  54. "$SOLUM_API_URL" \
  55. "$SOLUM_API_URL"
  56. SOLUM_BUILDER_SERVICE=$(get_or_create_service "solum" "image_builder" "Solum Image Builder")
  57. get_or_create_endpoint "image_builder" \
  58. "$REGION_NAME" \
  59. "$SOLUM_SERVICE_PROTOCOL://$SOLUM_SERVICE_HOST:$SOLUM_BUILDER_SERVICE_PORT" \
  60. "$SOLUM_SERVICE_PROTOCOL://$SOLUM_SERVICE_HOST:$SOLUM_BUILDER_SERVICE_PORT" \
  61. "$SOLUM_SERVICE_PROTOCOL://$SOLUM_SERVICE_HOST:$SOLUM_BUILDER_SERVICE_PORT"
  62. }
  63. # configure_nova_docker - Set config files, create data dirs, etc
  64. function configure_nova_docker {
  65. iniset $NOVA_CONF DEFAULT compute_driver zun.DockerDriver
  66. # CentOS/RedHat distros don't start the services just after the package
  67. # is installed if it is not explicitily set. So the script fails on
  68. # them in this killall because there is nothing to kill.
  69. sudo killall docker || true
  70. # Enable debug level logging
  71. if [ -f "/etc/default/docker" ]; then
  72. sudo cat /etc/default/docker
  73. sudo sed -i 's/^.*DOCKER_OPTS=.*$/DOCKER_OPTS=\"--debug --storage-opt dm.override_udev_sync_check=true\"/' /etc/default/docker
  74. sudo cat /etc/default/docker
  75. fi
  76. if [ -f "/etc/sysconfig/docker" ]; then
  77. sudo cat /etc/sysconfig/docker
  78. sudo sed -i 's/^.*OPTIONS=.*$/OPTIONS=--debug --selinux-enabled/' /etc/sysconfig/docker
  79. sudo cat /etc/sysconfig/docker
  80. fi
  81. if [ -f "/usr/lib/systemd/system/docker.service" ]; then
  82. sudo cat /usr/lib/systemd/system/docker.service
  83. sudo sed -i 's/docker daemon/docker daemon --debug/' /usr/lib/systemd/system/docker.service
  84. sudo cat /usr/lib/systemd/system/docker.service
  85. sudo systemctl daemon-reload
  86. fi
  87. sudo service docker start || true
  88. # setup rootwrap filters
  89. local rootwrap_conf_src_dir="$ZUN_PROJ_DIR/contrib/nova-docker/etc/nova"
  90. sudo install -o root -g root -m 644 $rootwrap_conf_src_dir/rootwrap.d/*.filters /etc/nova/rootwrap.d
  91. cp -r $ZUN_PROJ_DIR/contrib/nova-docker/nova $SOLUM_DIR
  92. setup_develop $SOLUM_DIR
  93. }
  94. # configure_solum() - Set config files, create data dirs, etc
  95. function configure_solum() {
  96. configure_nova_docker
  97. if [[ ! -d $SOLUM_CONF_DIR ]]; then
  98. sudo mkdir -p $SOLUM_CONF_DIR
  99. fi
  100. sudo chown $STACK_USER $SOLUM_CONF_DIR
  101. # To support private github repos, do not perform host key check for github.com
  102. # Need this change on solum-worker instances
  103. STACK_USER_SSH_DIR=/home/$STACK_USER/.ssh
  104. if [[ ! -d $STACK_USER_SSH_DIR ]]; then
  105. sudo mkdir -p $STACK_USER_SSH_DIR
  106. fi
  107. sudo chown $STACK_USER $STACK_USER_SSH_DIR
  108. echo -e "Host github.com\n\tStrictHostKeyChecking no\n" > $STACK_USER_SSH_DIR/config
  109. # config solum rootwrap
  110. configure_rootwrap solum
  111. # Generate sample config and configure common parameters.
  112. mkdir -p /tmp/solum
  113. pushd $SOLUM_DIR
  114. oslo-config-generator --config-file=${SOLUM_DIR}/etc/solum/config-generator.conf --output-file=/tmp/solum/solum.conf.sample
  115. popd
  116. cp /tmp/solum/solum.conf.sample $SOLUM_CONF_DIR/$SOLUM_CONF_FILE
  117. iniset $SOLUM_CONF_DIR/$SOLUM_CONF_FILE DEFAULT debug $SOLUM_DEBUG
  118. iniset $SOLUM_CONF_DIR/$SOLUM_CONF_FILE DEFAULT use_syslog $SYSLOG
  119. # make trace visible
  120. iniset $SOLUM_CONF_DIR/$SOLUM_CONF_FILE DEFAULT logging_context_format_string "%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s [%(request_id)s %(user_identity)s] %(instance)s%(message)s"
  121. # Setup keystone_authtoken section
  122. configure_auth_token_middleware $SOLUM_CONF_DIR/$SOLUM_CONF_FILE $SOLUM_USER $SOLUM_AUTH_CACHE_DIR
  123. iniset $SOLUM_CONF_DIR/$SOLUM_CONF_FILE keystone_authtoken www_authenticate_uri $KEYSTONE_AUTH_URI
  124. # configure the database.
  125. iniset $SOLUM_CONF_DIR/$SOLUM_CONF_FILE database connection `database_connection_url solum`
  126. # configure worker lp operator user/password
  127. iniset $SOLUM_CONF_DIR/$SOLUM_CONF_FILE worker lp_operator_user $SOLUM_USER
  128. iniset $SOLUM_CONF_DIR/$SOLUM_CONF_FILE worker lp_operator_password $SERVICE_PASSWORD
  129. iniset $SOLUM_CONF_DIR/$SOLUM_CONF_FILE worker lp_operator_tenant_name service
  130. # configure the api servers to listen on
  131. iniset $SOLUM_CONF_DIR/$SOLUM_CONF_FILE api host $(ipv6_unquote $SOLUM_SERVICE_HOST)
  132. iniset $SOLUM_CONF_DIR/$SOLUM_CONF_FILE api port $SOLUM_SERVICE_PORT
  133. iniset $SOLUM_CONF_DIR/$SOLUM_CONF_FILE builder host $(ipv6_unquote $SOLUM_SERVICE_HOST)
  134. iniset $SOLUM_CONF_DIR/$SOLUM_CONF_FILE builder port $SOLUM_BUILDER_SERVICE_PORT
  135. # configure assembly handler to create appropriate image format
  136. iniset $SOLUM_CONF_DIR/$SOLUM_CONF_FILE api image_format $SOLUM_IMAGE_FORMAT
  137. # common rpc settings
  138. iniset_rpc_backend solum $SOLUM_CONF_DIR/$SOLUM_CONF_FILE DEFAULT
  139. # service rpc settings
  140. iniset $SOLUM_CONF_DIR/$SOLUM_CONF_FILE conductor topic solum-conductor
  141. iniset $SOLUM_CONF_DIR/$SOLUM_CONF_FILE deployer topic solum-deployer
  142. iniset $SOLUM_CONF_DIR/$SOLUM_CONF_FILE deployer handler heat
  143. iniset $SOLUM_CONF_DIR/$SOLUM_CONF_FILE worker topic solum-worker
  144. iniset $SOLUM_CONF_DIR/$SOLUM_CONF_FILE worker handler shell
  145. iniset $SOLUM_CONF_DIR/$SOLUM_CONF_FILE worker proj_dir $SOLUM_PROJ_DIR
  146. iniset $SOLUM_CONF_DIR/$SOLUM_CONF_FILE deployer max_attempts $SOLUM_MAX_ATTEMPTS
  147. iniset $SOLUM_CONF_DIR/$SOLUM_CONF_FILE deployer wait_interval $SOLUM_WAIT_INTERVAL
  148. iniset $SOLUM_CONF_DIR/$SOLUM_CONF_FILE deployer growth_factor $SOLUM_GROWTH_FACTOR
  149. # configure AllHostsFilter in /etc/nova/nova.conf
  150. iniset $NOVA_CONF_DIR/$NOVA_CONF_FILE DEFAULT scheduler_default_filters AllHostsFilter
  151. if [[ $SOLUM_IMAGE_FORMAT == 'vm' ]]; then
  152. # configure Virtdriver in /etc/nova/nova.conf
  153. iniset $NOVA_CONF_DIR/$NOVA_CONF_FILE DEFAULT compute_driver libvirt.LibvirtDriver
  154. #solum_install_start_docker_registry
  155. solum_install_core_os
  156. else
  157. echo "SOLUM_IMAGE_FORMAT docker or vm"
  158. fi
  159. if [[ "$USE_PYTHON3" = "True" ]]; then
  160. # Switch off glance->swift communication as swift fails under py3.x
  161. iniset /etc/glance/glance-api.conf glance_store default_store file
  162. fi
  163. if [ "$SOLUM_USE_MOD_WSGI" == "True" ]; then
  164. _config_solum_apache_wsgi
  165. fi
  166. if [ "$SOLUM_USE_UWSGI" == "True" ]; then
  167. write_uwsgi_config "$SOLUM_UWSGI_CONF" "$SOLUM_UWSGI" "/application_deployment"
  168. fi
  169. }
  170. #register solum user in Keystone
  171. function add_solum_user() {
  172. create_service_user "solum" "admin"
  173. }
  174. function add_additional_solum_users() {
  175. SOLUM_UPDATE_ROLE=$(get_or_create_role "solum_assembly_update")
  176. for _LETTER in a b c; do
  177. local TENANTNAME=solum_tenant_$_LETTER
  178. get_or_create_project "$TENANTNAME" "default"
  179. local USERNAME=solum_user_$_LETTER
  180. get_or_create_user "$USERNAME" "solum" "default"
  181. get_or_add_user_project_role "$SOLUM_UPDATE_ROLE" "$USERNAME" "$TENANTNAME"
  182. get_or_add_user_project_role "$SOLUM_UPDATE_ROLE" "admin" "$TENANTNAME"
  183. done
  184. }
  185. #create_solum_cache_dir() - Setup keystone signing folder
  186. function create_solum_cache_dir() {
  187. sudo mkdir -p $SOLUM_AUTH_CACHE_DIR
  188. sudo chown $STACK_USER $SOLUM_AUTH_CACHE_DIR
  189. sudo chmod 700 $SOLUM_AUTH_CACHE_DIR
  190. rm -f $SOLUM_AUTH_CACHE_DIR/*
  191. }
  192. # init_solum() - Initialize databases, etc.
  193. function init_solum() {
  194. recreate_database solum utf8
  195. # Run Solum db migrations
  196. solum-db-manage --config-file $SOLUM_CONF_DIR/$SOLUM_CONF_FILE upgrade head
  197. create_solum_cache_dir
  198. # NOTE (devkulkarni): Barbican is causing failures such as below
  199. # http://logs.openstack.org/33/206633/2/check/gate-solum-devstack-dsvm/933cbc3/logs/devstacklog.txt.gz#_2015-08-03_17_13_40_858
  200. # So temorarily commenting out barbican related code below.
  201. # if is_service_enabled barbican; then
  202. # # Fix barbican configuration
  203. # BARBICAN_API_CONF="/etc/barbican/barbican.conf"
  204. # BARBICAN_HOST_HREF=$(iniget $BARBICAN_API_CONF DEFAULT host_href)
  205. # BARBICAN_HOST_HREF=${BARBICAN_HOST_HREF/localhost/$SERVICE_HOST}
  206. # iniset $BARBICAN_API_CONF DEFAULT host_href $BARBICAN_HOST_HREF
  207. # if is_running barbican; then
  208. # # NOTE(ravips): barbican.{pid,failure} is removed to overcome current
  209. # # limitations of stop_barbican. stop_barbican calls screen_stop() only
  210. # # to remove the pid but not to kill the process and this causes pkill
  211. # # in screen_stop to return non-zero exit code which is trapped by
  212. # # devstack/stack.sh
  213. # if [ -f $SERVICE_DIR/$SCREEN_NAME/barbican.pid ]; then
  214. # rm $SERVICE_DIR/$SCREEN_NAME/barbican.pid
  215. # fi
  216. # stop_barbican
  217. # if [ -f $SERVICE_DIR/$SCREEN_NAME/barbican.failure ]; then
  218. # rm $SERVICE_DIR/$SCREEN_NAME/barbican.failure
  219. # fi
  220. # start_barbican
  221. # fi
  222. # fi
  223. }
  224. # install_solumclient() - Collect source and prepare
  225. function install_solumclient {
  226. if use_library_from_git "python-solumclient"; then
  227. git_clone_by_name "python-solumclient"
  228. setup_dev_lib "python-solumclient"
  229. else
  230. pip_install_gr python-solumclient
  231. fi
  232. }
  233. # install_solum() - Collect source and prepare
  234. function install_solum() {
  235. # Install package requirements
  236. install_package expect
  237. git_clone $SOLUM_REPO $SOLUM_DIR $SOLUM_BRANCH
  238. setup_develop $SOLUM_DIR
  239. if [ "$SOLUM_USE_MOD_WSGI" == "True" ]; then
  240. install_apache_wsgi
  241. fi
  242. }
  243. function install_solum_dashboard() {
  244. git_clone_by_name "solum-dashboard"
  245. setup_dev_lib "solum-dashboard"
  246. if [ ! -f $HORIZON_DIR/openstack_dashboard/local/enabled/_50_solum.py ] ; then
  247. ln -s $DEST/solum-dashboard/solumdashboard/local/enabled/_50_solum.py $HORIZON_DIR/openstack_dashboard/local/enabled/_50_solum.py
  248. fi
  249. restart_apache_server
  250. }
  251. function cleanup_solum_dashboard() {
  252. rm $HORIZON_DIR/openstack_dashboard/local/enabled/_50_solum.py
  253. }
  254. # cleanup_solum_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
  255. function cleanup_solum_apache_wsgi {
  256. sudo rm -f $(apache_site_config_for solum-api)
  257. }
  258. # _config_solum_apache_wsgi() - Set WSGI config files of Solum
  259. function _config_solum_apache_wsgi {
  260. local solum_apache_conf=$(apache_site_config_for solum-api)
  261. local solum_api_port=$SOLUM_SERVICE_PORT
  262. local venv_path=""
  263. sudo cp $SOLUM_FILES_DIR/apache-solum-api.template $solum_apache_conf
  264. sudo sed -e "
  265. s|%PUBLICPORT%|$solum_api_port|g;
  266. s|%APACHE_NAME%|$APACHE_NAME|g;
  267. s|%SOLUM_BIN_DIR%|$SOLUM_BIN_DIR|g;
  268. s|%API_WORKERS%|$API_WORKERS|g;
  269. s|%USER%|$STACK_USER|g;
  270. s|%VIRTUALENV%|$venv_path|g
  271. " -i $solum_apache_conf
  272. }
  273. # start_solum() - Start running processes, including screen
  274. function start_solum() {
  275. local enabled_site_file=$(apache_site_config_for solum-api)
  276. if [ -f ${enabled_site_file} ] && [ "$SOLUM_USE_MOD_WSGI" == "True" ]; then
  277. enable_apache_site solum-api
  278. restart_apache_server
  279. tail_log solum-api /var/log/$APACHE_NAME/solum-api.log
  280. elif [ "$SOLUM_USE_UWSGI" == "True" ]; then
  281. run_process solum-api "$SOLUM_BIN_DIR/uwsgi --ini $SOLUM_UWSGI_CONF"
  282. else
  283. run_process solum-api "$SOLUM_BIN_DIR/solum-api --config-file $SOLUM_CONF_DIR/$SOLUM_CONF_FILE"
  284. fi
  285. run_process solum-conductor "$SOLUM_BIN_DIR/solum-conductor --config-file $SOLUM_CONF_DIR/$SOLUM_CONF_FILE"
  286. run_process solum-deployer "$SOLUM_BIN_DIR/solum-deployer --config-file $SOLUM_CONF_DIR/$SOLUM_CONF_FILE"
  287. run_process solum-worker "$SOLUM_BIN_DIR/solum-worker --config-file $SOLUM_CONF_DIR/$SOLUM_CONF_FILE"
  288. }
  289. # stop_solum() - Stop running processes
  290. function stop_solum() {
  291. # Kill the solum screen windows
  292. if [ "$SOLUM_USE_UWSGI" == "True" ]; then
  293. disable_apache_site solum-api
  294. restart_apache_server
  295. else
  296. stop_process solum-api
  297. fi
  298. stop_process solum-conductor
  299. stop_process solum-deployer
  300. stop_process solum-worker
  301. if [[ $SOLUM_IMAGE_FORMAT == 'vm' ]]; then
  302. solum_stop_docker_registry
  303. fi
  304. }
  305. # install_docker_registry() - Install and Start Docker Registry
  306. # -------------------------------------------------------------
  307. solum_install_start_docker_registry() {
  308. # install dependencies
  309. sudo apt-get update
  310. sudo apt-get -y install build-essential python-dev libevent-dev python-pip liblzma-dev git libssl-dev python-m2crypto swig
  311. # clone docker registry
  312. if [ ! -d /opt/docker-registry ] ; then
  313. sudo git clone https://github.com/dotcloud/docker-registry.git /opt/docker-registry
  314. fi
  315. pushd /opt/docker-registry
  316. sudo pip install -r requirements/main.txt
  317. popd
  318. # install docker registry
  319. pip_command=`which pip`
  320. pip_build_tmp=$(mktemp --tmpdir -d pip-build.XXXXX)
  321. sudo $pip_command install /opt/docker-registry --build=${pip_build_tmp}
  322. # initialize config file
  323. sudo cp /opt/docker-registry/docker_registry/lib/../../config/config_sample.yml /opt/docker-registry/docker_registry/lib/../../config/config.yml
  324. # start docker registry
  325. gunicorn --access-logfile - --debug -k gevent -b 0.0.0.0:5042 -w 1 docker_registry.wsgi:application &
  326. }
  327. solum_stop_docker_registry() {
  328. stop_process docker-registry
  329. rm -rf ${PIP_BUILD_TMP}
  330. }
  331. solum_install_core_os() {
  332. wget https://stable.release.core-os.net/amd64-usr/current/coreos_production_openstack_image.img.bz2
  333. bunzip2 coreos_production_openstack_image.img.bz2
  334. glance image-create --name coreos --container-format bare --disk-format qcow2 --file coreos_production_openstack_image.img
  335. }
  336. # Main dispatcher
  337. #----------------
  338. if is_service_enabled solum-api solum-conductor solum-deployer solum-worker; then
  339. if [[ "$1" == "stack" && "$2" == "install" ]]; then
  340. echo_summary "Installing Solum"
  341. install_solum
  342. install_solumclient
  343. if is_service_enabled horizon; then
  344. echo_summary "Installing Solum Dashboard"
  345. install_solum_dashboard
  346. fi
  347. elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then
  348. echo_summary "Configuring Solum"
  349. add_solum_user
  350. configure_solum
  351. if is_service_enabled key; then
  352. create_solum_service_and_endpoint
  353. fi
  354. add_additional_solum_users
  355. elif [[ "$1" == "stack" && "$2" == "extra" ]]; then
  356. echo_summary "Initializing Solum"
  357. init_solum
  358. start_solum
  359. fi
  360. if [[ "$1" == "unstack" ]]; then
  361. stop_solum
  362. if [ "$SOLUM_USE_MOD_WSGI" == "True" ]; then
  363. cleanup_solum_apache_wsgi
  364. fi
  365. if [[ "$SOLUM_USE_UWSGI" == "True" ]]; then
  366. remove_uwsgi_config "$SOLUM_UWSGI_CONF" "$SOLUM_UWSGI"
  367. fi
  368. if is_service_enabled horizon; then
  369. echo_summary "Cleaning Solum Dashboard up"
  370. cleanup_solum_dashboard
  371. fi
  372. fi
  373. fi
  374. # Restore xtrace
  375. $XTRACE
  376. # Local variables:
  377. # mode: shell-script
  378. # End: