blob: 8f4f3c6bbc484d248ee4d6a64258ad7b187026ef [file] [log] [blame]
Flaper Fesp06b345e2013-09-04 15:35:47 +02001# lib/marconi
2# Install and start **Marconi** service
3
4# To enable a minimal set of Marconi services, add the following to localrc:
Dean Troyerd8864fe2014-02-17 11:00:42 -06005#
6# enable_service marconi-server
Flaper Fesp06b345e2013-09-04 15:35:47 +02007#
8# Dependencies:
9# - functions
10# - OS_AUTH_URL for auth in api
11# - DEST set to the destination directory
12# - SERVICE_PASSWORD, SERVICE_TENANT_NAME for auth in api
13# - STACK_USER service user
14
15# stack.sh
16# ---------
17# install_marconi
18# configure_marconi
19# init_marconi
20# start_marconi
21# stop_marconi
22# cleanup_marconi
23
24# Save trace setting
25XTRACE=$(set +o | grep xtrace)
26set +o xtrace
27
28
29# Defaults
30# --------
31
32# Set up default directories
33MARCONI_DIR=$DEST/marconi
34MARCONICLIENT_DIR=$DEST/python-marconiclient
35MARCONI_CONF_DIR=/etc/marconi
36MARCONI_CONF=$MARCONI_CONF_DIR/marconi.conf
37MARCONI_API_LOG_DIR=/var/log/marconi-api
38MARCONI_AUTH_CACHE_DIR=${MARCONI_AUTH_CACHE_DIR:-/var/cache/marconi}
39
40# Support potential entry-points console scripts
41MARCONI_BIN_DIR=$(get_python_exec_prefix)
42
43# Set up database backend
44MARCONI_BACKEND=${MARCONI_BACKEND:-mongodb}
45
46
47# Set Marconi repository
48MARCONI_REPO=${MARCONI_REPO:-${GIT_BASE}/openstack/marconi.git}
49MARCONI_BRANCH=${MARCONI_BRANCH:-master}
50
51# Set client library repository
52MARCONICLIENT_REPO=${MARCONICLIENT_REPO:-${GIT_BASE}/openstack/python-marconiclient.git}
53MARCONICLIENT_BRANCH=${MARCONICLIENT_BRANCH:-master}
54
Malini Kamalambal67df3b22014-02-20 14:48:59 -050055# Set Marconi Connection Info
56MARCONI_SERVICE_HOST=${MARCONI_SERVICE_HOST:-$SERVICE_HOST}
57MARCONI_SERVICE_PORT=${MARCONI_SERVICE_PORT:-8888}
58MARCONI_SERVICE_PROTOCOL=${MARCONI_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
59
Dean Troyer4237f592014-01-29 16:22:11 -060060# Tell Tempest this project is present
Malini Kamalambal1e4e3ac2014-02-14 11:29:26 -050061TEMPEST_SERVICES+=,marconi
Dean Troyer4237f592014-01-29 16:22:11 -060062
63
Flaper Fesp06b345e2013-09-04 15:35:47 +020064# Functions
65# ---------
66
Malini Kamalambal9972ec22014-02-10 11:22:39 -050067# Test if any Marconi services are enabled
68# is_marconi_enabled
69function is_marconi_enabled {
70 [[ ,${ENABLED_SERVICES} =~ ,"marconi-" ]] && return 0
71 return 1
72}
73
Flaper Fesp06b345e2013-09-04 15:35:47 +020074# cleanup_marconi() - Remove residual data files, anything left over from previous
75# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +110076function cleanup_marconi {
Malini Kamalambal2dcc7742014-02-18 13:45:18 -050077 if ! timeout $SERVICE_TIMEOUT sh -c "while ! mongo marconi --eval 'db.dropDatabase();'; do sleep 1; done"; then
78 die $LINENO "Mongo DB did not start"
79 fi
Flaper Fesp06b345e2013-09-04 15:35:47 +020080}
81
82# configure_marconiclient() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +110083function configure_marconiclient {
Flaper Fesp06b345e2013-09-04 15:35:47 +020084 setup_develop $MARCONICLIENT_DIR
85}
86
87# configure_marconi() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +110088function configure_marconi {
Flaper Fesp06b345e2013-09-04 15:35:47 +020089 setup_develop $MARCONI_DIR
90
91 [ ! -d $MARCONI_CONF_DIR ] && sudo mkdir -m 755 -p $MARCONI_CONF_DIR
92 sudo chown $USER $MARCONI_CONF_DIR
93
94 [ ! -d $MARCONI_API_LOG_DIR ] && sudo mkdir -m 755 -p $MARCONI_API_LOG_DIR
95 sudo chown $USER $MARCONI_API_LOG_DIR
96
97 iniset $MARCONI_CONF DEFAULT verbose True
Malini Kamalambal2e978dd2014-02-28 14:06:59 -050098 iniset $MARCONI_CONF DEFAULT use_syslog $SYSLOG
Malini Kamalambal67df3b22014-02-20 14:48:59 -050099 iniset $MARCONI_CONF 'drivers:transport:wsgi' bind $MARCONI_SERVICE_HOST
Flaper Fesp06b345e2013-09-04 15:35:47 +0200100
Flaper Fesp06b345e2013-09-04 15:35:47 +0200101 iniset $MARCONI_CONF keystone_authtoken auth_protocol http
102 iniset $MARCONI_CONF keystone_authtoken admin_user marconi
103 iniset $MARCONI_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
104 iniset $MARCONI_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
105 iniset $MARCONI_CONF keystone_authtoken signing_dir $MARCONI_AUTH_CACHE_DIR
106
107 if [[ "$MARCONI_BACKEND" = 'mongodb' ]]; then
Flavio Percoco961328f2014-03-05 18:45:56 +0100108 iniset $MARCONI_CONF drivers storage mongodb
109 iniset $MARCONI_CONF 'drivers:storage:mongodb' uri mongodb://localhost:27017/marconi
Flaper Fesp06b345e2013-09-04 15:35:47 +0200110 configure_mongodb
111 cleanup_marconi
112 fi
113}
114
Ian Wienandaee18c72014-02-21 15:35:08 +1100115function configure_mongodb {
Flaper Fesp06b345e2013-09-04 15:35:47 +0200116 # Set nssize to 2GB. This increases the number of namespaces supported
117 # # per database.
Dean Troyer41d96d72014-02-11 09:08:35 -0600118 if is_ubuntu; then
119 sudo sed -i -e "
120 s|[^ \t]*#[ \t]*\(nssize[ \t]*=.*\$\)|\1|
121 s|^\(nssize[ \t]*=[ \t]*\).*\$|\1 2047|
122 " /etc/mongodb.conf
123 restart_service mongodb
124 elif is_fedora; then
125 sudo sed -i '/--nssize/!s/OPTIONS=\"/OPTIONS=\"--nssize 2047 /' /etc/sysconfig/mongod
126 restart_service mongod
127 fi
Flaper Fesp06b345e2013-09-04 15:35:47 +0200128}
129
130# init_marconi() - Initialize etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100131function init_marconi {
Flaper Fesp06b345e2013-09-04 15:35:47 +0200132 # Create cache dir
133 sudo mkdir -p $MARCONI_AUTH_CACHE_DIR
134 sudo chown $STACK_USER $MARCONI_AUTH_CACHE_DIR
135 rm -f $MARCONI_AUTH_CACHE_DIR/*
136}
137
138# install_marconi() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100139function install_marconi {
Flaper Fesp06b345e2013-09-04 15:35:47 +0200140 git_clone $MARCONI_REPO $MARCONI_DIR $MARCONI_BRANCH
141 setup_develop $MARCONI_DIR
142}
143
144# install_marconiclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100145function install_marconiclient {
Flaper Fesp06b345e2013-09-04 15:35:47 +0200146 git_clone $MARCONICLIENT_REPO $MARCONICLIENT_DIR $MARCONICLIENT_BRANCH
147 setup_develop $MARCONICLIENT_DIR
148}
149
150# start_marconi() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100151function start_marconi {
Flaper Fesp06b345e2013-09-04 15:35:47 +0200152 screen_it marconi-server "marconi-server --config-file $MARCONI_CONF"
Malini Kamalambal67df3b22014-02-20 14:48:59 -0500153 echo "Waiting for Marconi to start..."
154 if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget --no-proxy -q -O- $MARCONI_SERVICE_PROTOCOL://$MARCONI_SERVICE_HOST:$MARCONI_SERVICE_PORT/v1/health; do sleep 1; done"; then
155 die $LINENO "Marconi did not start"
156 fi
Flaper Fesp06b345e2013-09-04 15:35:47 +0200157}
158
159# stop_marconi() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100160function stop_marconi {
Flaper Fesp06b345e2013-09-04 15:35:47 +0200161 # Kill the marconi screen windows
162 for serv in marconi-server; do
163 screen -S $SCREEN_NAME -p $serv -X kill
164 done
165}
166
Ian Wienandaee18c72014-02-21 15:35:08 +1100167function create_marconi_accounts {
Steve Martinelli19685422014-01-24 13:02:26 -0600168 SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
169 ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
Flaper Fesp06b345e2013-09-04 15:35:47 +0200170
Steve Martinelli19685422014-01-24 13:02:26 -0600171 MARCONI_USER=$(openstack user create \
172 marconi \
173 --password "$SERVICE_PASSWORD" \
174 --project $SERVICE_TENANT \
175 --email marconi@example.com \
176 | grep " id " | get_field 2)
177 openstack role add \
178 $ADMIN_ROLE \
179 --project $SERVICE_TENANT \
180 --user $MARCONI_USER
Malini Kamalambal0b3aacc2014-02-13 18:18:51 -0500181
Flaper Fesp06b345e2013-09-04 15:35:47 +0200182 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Steve Martinelli19685422014-01-24 13:02:26 -0600183 MARCONI_SERVICE=$(openstack service create \
184 marconi \
Flaper Fesp06b345e2013-09-04 15:35:47 +0200185 --type=queuing \
Malini Kamalambal0f7ad6b2013-12-13 12:42:31 -0500186 --description="Marconi Service" \
187 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -0600188 openstack endpoint create \
189 $MARCONI_SERVICE \
Flaper Fesp06b345e2013-09-04 15:35:47 +0200190 --region RegionOne \
Malini Kamalambal67df3b22014-02-20 14:48:59 -0500191 --publicurl "$MARCONI_SERVICE_PROTOCOL://$MARCONI_SERVICE_HOST:$MARCONI_SERVICE_PORT" \
192 --adminurl "$MARCONI_SERVICE_PROTOCOL://$MARCONI_SERVICE_HOST:$MARCONI_SERVICE_PORT" \
193 --internalurl "$MARCONI_SERVICE_PROTOCOL://$MARCONI_SERVICE_HOST:$MARCONI_SERVICE_PORT"
Flaper Fesp06b345e2013-09-04 15:35:47 +0200194 fi
195
196}
197
198
199# Restore xtrace
200$XTRACE
201
202# Local variables:
203# mode: shell-script
204# End: