blob: 1e0cc7df0822fbaeb77933ecfa85b5982fb44d00 [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
Flavio Percoco5fc5b7e2014-03-05 18:49:02 +0100107 if [ "$MARCONI_BACKEND" = 'mysql' ] || [ "$MARCONI_BACKEND" = 'postgresql' ] ; then
108 iniset $MARCONI_CONF drivers storage sqlalchemy
109 iniset $MARCONI_CONF 'drivers:storage:sqlalchemy' uri `database_connection_url marconi`
110 else
Flavio Percoco961328f2014-03-05 18:45:56 +0100111 iniset $MARCONI_CONF drivers storage mongodb
112 iniset $MARCONI_CONF 'drivers:storage:mongodb' uri mongodb://localhost:27017/marconi
Flaper Fesp06b345e2013-09-04 15:35:47 +0200113 configure_mongodb
114 cleanup_marconi
115 fi
116}
117
Ian Wienandaee18c72014-02-21 15:35:08 +1100118function configure_mongodb {
Flaper Fesp06b345e2013-09-04 15:35:47 +0200119 # Set nssize to 2GB. This increases the number of namespaces supported
120 # # per database.
Dean Troyer41d96d72014-02-11 09:08:35 -0600121 if is_ubuntu; then
122 sudo sed -i -e "
123 s|[^ \t]*#[ \t]*\(nssize[ \t]*=.*\$\)|\1|
124 s|^\(nssize[ \t]*=[ \t]*\).*\$|\1 2047|
125 " /etc/mongodb.conf
126 restart_service mongodb
127 elif is_fedora; then
128 sudo sed -i '/--nssize/!s/OPTIONS=\"/OPTIONS=\"--nssize 2047 /' /etc/sysconfig/mongod
129 restart_service mongod
130 fi
Flaper Fesp06b345e2013-09-04 15:35:47 +0200131}
132
133# init_marconi() - Initialize etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100134function init_marconi {
Flaper Fesp06b345e2013-09-04 15:35:47 +0200135 # Create cache dir
136 sudo mkdir -p $MARCONI_AUTH_CACHE_DIR
137 sudo chown $STACK_USER $MARCONI_AUTH_CACHE_DIR
138 rm -f $MARCONI_AUTH_CACHE_DIR/*
139}
140
141# install_marconi() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100142function install_marconi {
Flaper Fesp06b345e2013-09-04 15:35:47 +0200143 git_clone $MARCONI_REPO $MARCONI_DIR $MARCONI_BRANCH
144 setup_develop $MARCONI_DIR
145}
146
147# install_marconiclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100148function install_marconiclient {
Flaper Fesp06b345e2013-09-04 15:35:47 +0200149 git_clone $MARCONICLIENT_REPO $MARCONICLIENT_DIR $MARCONICLIENT_BRANCH
150 setup_develop $MARCONICLIENT_DIR
151}
152
153# start_marconi() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100154function start_marconi {
Flaper Fesp06b345e2013-09-04 15:35:47 +0200155 screen_it marconi-server "marconi-server --config-file $MARCONI_CONF"
Malini Kamalambal67df3b22014-02-20 14:48:59 -0500156 echo "Waiting for Marconi to start..."
157 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
158 die $LINENO "Marconi did not start"
159 fi
Flaper Fesp06b345e2013-09-04 15:35:47 +0200160}
161
162# stop_marconi() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100163function stop_marconi {
Flaper Fesp06b345e2013-09-04 15:35:47 +0200164 # Kill the marconi screen windows
165 for serv in marconi-server; do
166 screen -S $SCREEN_NAME -p $serv -X kill
167 done
168}
169
Ian Wienandaee18c72014-02-21 15:35:08 +1100170function create_marconi_accounts {
Steve Martinelli19685422014-01-24 13:02:26 -0600171 SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
172 ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
Flaper Fesp06b345e2013-09-04 15:35:47 +0200173
Steve Martinelli19685422014-01-24 13:02:26 -0600174 MARCONI_USER=$(openstack user create \
175 marconi \
176 --password "$SERVICE_PASSWORD" \
177 --project $SERVICE_TENANT \
178 --email marconi@example.com \
179 | grep " id " | get_field 2)
180 openstack role add \
181 $ADMIN_ROLE \
182 --project $SERVICE_TENANT \
183 --user $MARCONI_USER
Malini Kamalambal0b3aacc2014-02-13 18:18:51 -0500184
Flaper Fesp06b345e2013-09-04 15:35:47 +0200185 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Steve Martinelli19685422014-01-24 13:02:26 -0600186 MARCONI_SERVICE=$(openstack service create \
187 marconi \
Flaper Fesp06b345e2013-09-04 15:35:47 +0200188 --type=queuing \
Malini Kamalambal0f7ad6b2013-12-13 12:42:31 -0500189 --description="Marconi Service" \
190 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -0600191 openstack endpoint create \
192 $MARCONI_SERVICE \
Flaper Fesp06b345e2013-09-04 15:35:47 +0200193 --region RegionOne \
Malini Kamalambal67df3b22014-02-20 14:48:59 -0500194 --publicurl "$MARCONI_SERVICE_PROTOCOL://$MARCONI_SERVICE_HOST:$MARCONI_SERVICE_PORT" \
195 --adminurl "$MARCONI_SERVICE_PROTOCOL://$MARCONI_SERVICE_HOST:$MARCONI_SERVICE_PORT" \
196 --internalurl "$MARCONI_SERVICE_PROTOCOL://$MARCONI_SERVICE_HOST:$MARCONI_SERVICE_PORT"
Flaper Fesp06b345e2013-09-04 15:35:47 +0200197 fi
198
199}
200
201
202# Restore xtrace
203$XTRACE
204
205# Local variables:
206# mode: shell-script
207# End: