blob: d69790c9a976326ab3b9f81626ee6a2ac10621d9 [file] [log] [blame]
Dean Troyer67787e62012-05-02 11:48:15 -05001# lib/cinder
2# Install and start Cinder volume service
3
4# Dependencies:
5# - functions
Dean Troyer50ac7922012-09-13 14:02:01 -05006# - DEST, DATA_DIR must be defined
Dean Troyer67787e62012-05-02 11:48:15 -05007# SERVICE_{TENANT_NAME|PASSWORD} must be defined
Dean Troyerbc071bc2012-10-01 14:06:44 -05008# ``KEYSTONE_TOKEN_FORMAT`` must be defined
Dean Troyer67787e62012-05-02 11:48:15 -05009
10# stack.sh
11# ---------
Attila Fazekasb79574b2012-12-01 10:42:46 +010012# install_cinder
13# configure_cinder
14# init_cinder
15# start_cinder
16# stop_cinder
17# cleanup_cinder
Dean Troyer67787e62012-05-02 11:48:15 -050018
Dean Troyer7903b792012-09-13 17:16:12 -050019# Save trace setting
20XTRACE=$(set +o | grep xtrace)
21set +o xtrace
Dean Troyer67787e62012-05-02 11:48:15 -050022
23
24# Defaults
25# --------
26
Mate Lakatb2fdafe2012-11-20 15:52:21 +000027# set up default driver
28CINDER_DRIVER=${CINDER_DRIVER:-default}
29
Dean Troyer67787e62012-05-02 11:48:15 -050030# set up default directories
31CINDER_DIR=$DEST/cinder
Dean Troyer50ac7922012-09-13 14:02:01 -050032CINDERCLIENT_DIR=$DEST/python-cinderclient
33CINDER_STATE_PATH=${CINDER_STATE_PATH:=$DATA_DIR/cinder}
Dean Troyer671c16e2012-12-13 16:22:38 -060034CINDER_AUTH_CACHE_DIR=${CINDER_AUTH_CACHE_DIR:-/var/cache/cinder}
35
Dean Troyer50ac7922012-09-13 14:02:01 -050036CINDER_CONF_DIR=/etc/cinder
37CINDER_CONF=$CINDER_CONF_DIR/cinder.conf
Dean Troyer671c16e2012-12-13 16:22:38 -060038CINDER_API_PASTE_INI=$CINDER_CONF_DIR/api-paste.ini
Dean Troyer50ac7922012-09-13 14:02:01 -050039
Dean Troyer560346b2012-12-13 17:05:24 -060040# Public facing bits
41CINDER_SERVICE_HOST=${CINDER_SERVICE_HOST:-$SERVICE_HOST}
42CINDER_SERVICE_PORT=${CINDER_SERVICE_PORT:-8776}
43CINDER_SERVICE_PORT_INT=${CINDER_SERVICE_PORT_INT:-18776}
44CINDER_SERVICE_PROTOCOL=${CINDER_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
45
Dean Troyer50ac7922012-09-13 14:02:01 -050046# Support entry points installation of console scripts
47if [[ -d $CINDER_DIR/bin ]]; then
Monty Taylor9fbeedd2012-08-17 12:52:27 -040048 CINDER_BIN_DIR=$CINDER_DIR/bin
49else
50 CINDER_BIN_DIR=/usr/local/bin
51fi
Dean Troyer67787e62012-05-02 11:48:15 -050052
53# Name of the lvm volume group to use/create for iscsi volumes
54VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes}
55VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-}
56
57# cleanup_cinder() - Remove residual data files, anything left over from previous
58# runs that a clean run would need to clean up
59function cleanup_cinder() {
60 # This function intentionally left blank
61 :
62}
63
64# configure_cinder() - Set config files, create data dirs, etc
65function configure_cinder() {
66 setup_develop $CINDER_DIR
67 setup_develop $CINDERCLIENT_DIR
68
69 if [[ ! -d $CINDER_CONF_DIR ]]; then
70 sudo mkdir -p $CINDER_CONF_DIR
71 fi
72 sudo chown `whoami` $CINDER_CONF_DIR
73
74 cp -p $CINDER_DIR/etc/cinder/policy.json $CINDER_CONF_DIR
75
John Griffith4e823ff2012-07-20 13:18:17 -060076 # Set the paths of certain binaries
Vincent Untz856a11e2012-11-21 16:04:12 +010077 CINDER_ROOTWRAP=$(get_rootwrap_location cinder)
John Griffith4e823ff2012-07-20 13:18:17 -060078
79 # If Cinder ships the new rootwrap filters files, deploy them
80 # (owned by root) and add a parameter to $CINDER_ROOTWRAP
81 ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP"
82 if [[ -d $CINDER_DIR/etc/cinder/rootwrap.d ]]; then
83 # Wipe any existing rootwrap.d files first
84 if [[ -d $CINDER_CONF_DIR/rootwrap.d ]]; then
85 sudo rm -rf $CINDER_CONF_DIR/rootwrap.d
86 fi
87 # Deploy filters to /etc/cinder/rootwrap.d
88 sudo mkdir -m 755 $CINDER_CONF_DIR/rootwrap.d
89 sudo cp $CINDER_DIR/etc/cinder/rootwrap.d/*.filters $CINDER_CONF_DIR/rootwrap.d
90 sudo chown -R root:root $CINDER_CONF_DIR/rootwrap.d
91 sudo chmod 644 $CINDER_CONF_DIR/rootwrap.d/*
92 # Set up rootwrap.conf, pointing to /etc/cinder/rootwrap.d
93 sudo cp $CINDER_DIR/etc/cinder/rootwrap.conf $CINDER_CONF_DIR/
94 sudo sed -e "s:^filters_path=.*$:filters_path=$CINDER_CONF_DIR/rootwrap.d:" -i $CINDER_CONF_DIR/rootwrap.conf
95 sudo chown root:root $CINDER_CONF_DIR/rootwrap.conf
96 sudo chmod 0644 $CINDER_CONF_DIR/rootwrap.conf
97 # Specify rootwrap.conf as first parameter to cinder-rootwrap
98 CINDER_ROOTWRAP="$CINDER_ROOTWRAP $CINDER_CONF_DIR/rootwrap.conf"
99 ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP *"
100 fi
101
102 TEMPFILE=`mktemp`
103 echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_CINDER_SUDOER_CMD" >$TEMPFILE
104 chmod 0440 $TEMPFILE
105 sudo chown root:root $TEMPFILE
106 sudo mv $TEMPFILE /etc/sudoers.d/cinder-rootwrap
107
Dean Troyer67787e62012-05-02 11:48:15 -0500108 cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
109 iniset $CINDER_API_PASTE_INI filter:authtoken auth_host $KEYSTONE_AUTH_HOST
110 iniset $CINDER_API_PASTE_INI filter:authtoken auth_port $KEYSTONE_AUTH_PORT
111 iniset $CINDER_API_PASTE_INI filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
112 iniset $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
113 iniset $CINDER_API_PASTE_INI filter:authtoken admin_user cinder
114 iniset $CINDER_API_PASTE_INI filter:authtoken admin_password $SERVICE_PASSWORD
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +0900115 iniset $CINDER_API_PASTE_INI filter:authtoken signing_dir $CINDER_AUTH_CACHE_DIR
Dean Troyerbc071bc2012-10-01 14:06:44 -0500116
Dean Troyer67787e62012-05-02 11:48:15 -0500117 cp $CINDER_DIR/etc/cinder/cinder.conf.sample $CINDER_CONF
118 iniset $CINDER_CONF DEFAULT auth_strategy keystone
119 iniset $CINDER_CONF DEFAULT verbose True
120 iniset $CINDER_CONF DEFAULT volume_group $VOLUME_GROUP
121 iniset $CINDER_CONF DEFAULT volume_name_template ${VOLUME_NAME_PREFIX}%s
122 iniset $CINDER_CONF DEFAULT iscsi_helper tgtadm
Terry Wilson428af5a2012-11-01 16:12:39 -0400123 local dburl
124 database_connection_url dburl cinder
125 iniset $CINDER_CONF DEFAULT sql_connection $dburl
Dean Troyer67787e62012-05-02 11:48:15 -0500126 iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
John Griffith4e823ff2012-07-20 13:18:17 -0600127 iniset $CINDER_CONF DEFAULT root_helper "sudo ${CINDER_ROOTWRAP}"
John Griffith43bedda2012-08-21 15:26:15 -0600128 iniset $CINDER_CONF DEFAULT osapi_volume_extension cinder.api.openstack.volume.contrib.standard_extensions
Dean Troyer50ac7922012-09-13 14:02:01 -0500129 iniset $CINDER_CONF DEFAULT state_path $CINDER_STATE_PATH
John Griffith4e823ff2012-07-20 13:18:17 -0600130
Dean Troyer560346b2012-12-13 17:05:24 -0600131 if is_service_enabled tls-proxy; then
132 # Set the service port for a proxy to take the original
133 iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
134 fi
135
Dean Troyer4d3049e2012-11-06 20:38:14 -0600136 if [ "$SYSLOG" != "False" ]; then
137 iniset $CINDER_CONF DEFAULT use_syslog True
138 fi
139
Gary Kottonf71bf192012-08-06 11:15:36 -0400140 if is_service_enabled qpid ; then
141 iniset $CINDER_CONF DEFAULT rpc_backend cinder.openstack.common.rpc.impl_qpid
ewindisch3bae7c22012-01-18 11:18:35 -0500142 elif is_service_enabled zeromq; then
143 iniset $CINDER_CONF DEFAULT rpc_backend nova.openstack.common.rpc.impl_zmq
Gary Kottonf71bf192012-08-06 11:15:36 -0400144 elif [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; then
145 iniset $CINDER_CONF DEFAULT rabbit_host $RABBIT_HOST
146 iniset $CINDER_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
147 fi
148
James E. Blair213c4162012-11-06 09:38:36 +0100149 if [[ "$CINDER_SECURE_DELETE" == "False" ]]; then
150 iniset $CINDER_CONF DEFAULT secure_delete False
151 fi
152
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000153 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
154 # Add color to logging output
155 iniset $CINDER_CONF DEFAULT logging_context_format_string "%(asctime)s %(color)s%(levelname)s %(name)s [%(request_id)s %(user_id)s %(project_id)s%(color)s] %(instance)s%(color)s%(message)s"
156 iniset $CINDER_CONF DEFAULT logging_default_format_string "%(asctime)s %(color)s%(levelname)s %(name)s [-%(color)s] %(instance)s%(color)s%(message)s"
157 iniset $CINDER_CONF DEFAULT logging_debug_format_suffix "from (pid=%(process)d) %(funcName)s %(pathname)s:%(lineno)d"
158 iniset $CINDER_CONF DEFAULT logging_exception_prefix "%(color)s%(asctime)s TRACE %(name)s %(instance)s"
159 fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000160
161 if [ "$CINDER_DRIVER" == "XenAPINFS" ]; then
162 (
163 set -u
Mate Lakata0ca45f2012-12-06 17:45:49 +0000164 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.xenapi.sm.XenAPINFSDriver"
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000165 iniset $CINDER_CONF DEFAULT xenapi_connection_url "$CINDER_XENAPI_CONNECTION_URL"
166 iniset $CINDER_CONF DEFAULT xenapi_connection_username "$CINDER_XENAPI_CONNECTION_USERNAME"
167 iniset $CINDER_CONF DEFAULT xenapi_connection_password "$CINDER_XENAPI_CONNECTION_PASSWORD"
168 iniset $CINDER_CONF DEFAULT xenapi_nfs_server "$CINDER_XENAPI_NFS_SERVER"
169 iniset $CINDER_CONF DEFAULT xenapi_nfs_serverpath "$CINDER_XENAPI_NFS_SERVERPATH"
170 )
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000171 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500172}
173
Dean Troyer671c16e2012-12-13 16:22:38 -0600174# create_cinder_accounts() - Set up common required cinder accounts
175
176# Tenant User Roles
177# ------------------------------------------------------------------
178# service cinder admin # if enabled
179
180# Migrated from keystone_data.sh
181create_cinder_accounts() {
182
183 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
184 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
185
186 # Cinder
187 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
188 CINDER_USER=$(keystone user-create \
189 --name=cinder \
190 --pass="$SERVICE_PASSWORD" \
191 --tenant_id $SERVICE_TENANT \
192 --email=cinder@example.com \
193 | grep " id " | get_field 2)
194 keystone user-role-add \
195 --tenant_id $SERVICE_TENANT \
196 --user_id $CINDER_USER \
197 --role_id $ADMIN_ROLE
198 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
199 CINDER_SERVICE=$(keystone service-create \
200 --name=cinder \
201 --type=volume \
202 --description="Cinder Volume Service" \
203 | grep " id " | get_field 2)
204 keystone endpoint-create \
205 --region RegionOne \
206 --service_id $CINDER_SERVICE \
Dean Troyer560346b2012-12-13 17:05:24 -0600207 --publicurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
208 --adminurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
209 --internalurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s"
Dean Troyer671c16e2012-12-13 16:22:38 -0600210 fi
211 fi
212}
213
Dean Troyer67787e62012-05-02 11:48:15 -0500214# init_cinder() - Initialize database and volume group
215function init_cinder() {
216 # Force nova volumes off
217 NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/osapi_volume,//")
218
Terry Wilson428af5a2012-11-01 16:12:39 -0400219 if is_service_enabled $DATABASE_BACKENDS; then
Dean Troyer67787e62012-05-02 11:48:15 -0500220 # (re)create cinder database
Terry Wilson428af5a2012-11-01 16:12:39 -0400221 recreate_database cinder utf8
Dean Troyer67787e62012-05-02 11:48:15 -0500222
223 # (re)create cinder database
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400224 $CINDER_BIN_DIR/cinder-manage db sync
Dean Troyer67787e62012-05-02 11:48:15 -0500225 fi
226
227 if is_service_enabled c-vol; then
228 # Configure a default volume group called '`stack-volumes`' for the volume
229 # service if it does not yet exist. If you don't wish to use a file backed
230 # volume group, create your own volume group called ``stack-volumes`` before
231 # invoking ``stack.sh``.
232 #
Eoghan Glynn9cb17762012-07-15 10:22:45 +0100233 # By default, the backing file is 5G in size, and is stored in ``/opt/stack/data``.
Dean Troyer67787e62012-05-02 11:48:15 -0500234
235 if ! sudo vgs $VOLUME_GROUP; then
236 VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file}
Dean Troyer67787e62012-05-02 11:48:15 -0500237 # Only create if the file doesn't already exists
238 [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
239 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE`
240 # Only create if the loopback device doesn't contain $VOLUME_GROUP
241 if ! sudo vgs $VOLUME_GROUP; then sudo vgcreate $VOLUME_GROUP $DEV; fi
242 fi
243
Dean Troyer50ac7922012-09-13 14:02:01 -0500244 mkdir -p $CINDER_STATE_PATH/volumes
Chuck Short3f603d92012-07-28 13:28:33 -0500245
Dean Troyer67787e62012-05-02 11:48:15 -0500246 if sudo vgs $VOLUME_GROUP; then
Vincent Untz00011c02012-12-06 09:56:32 +0100247 if is_fedora || is_suse; then
248 # service is not started by default
Vincent Untz0230aa82012-06-14 08:51:01 +0200249 start_service tgtd
250 fi
251
Dean Troyer67787e62012-05-02 11:48:15 -0500252 # Remove iscsi targets
253 sudo tgtadm --op show --mode target | grep $VOLUME_NAME_PREFIX | grep Target | cut -f3 -d ' ' | sudo xargs -n1 tgt-admin --delete || true
254 # Clean out existing volumes
255 for lv in `sudo lvs --noheadings -o lv_name $VOLUME_GROUP`; do
256 # VOLUME_NAME_PREFIX prefixes the LVs we want
257 if [[ "${lv#$VOLUME_NAME_PREFIX}" != "$lv" ]]; then
258 sudo lvremove -f $VOLUME_GROUP/$lv
259 fi
260 done
261 fi
262 fi
Dean Troyerbc071bc2012-10-01 14:06:44 -0500263
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +0900264 # Create cache dir
265 sudo mkdir -p $CINDER_AUTH_CACHE_DIR
266 sudo chown `whoami` $CINDER_AUTH_CACHE_DIR
Vishvananda Ishaya23431f32012-12-12 15:57:33 -0800267 rm -f $CINDER_AUTH_CACHE_DIR/*
Dean Troyer67787e62012-05-02 11:48:15 -0500268}
269
270# install_cinder() - Collect source and prepare
271function install_cinder() {
272 git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
273 git_clone $CINDERCLIENT_REPO $CINDERCLIENT_DIR $CINDERCLIENT_BRANCH
274}
275
Mate Lakata39caac2012-09-03 15:45:53 +0100276# apply config.d approach (e.g. Oneiric does not have this)
277function _configure_tgt_for_config_d() {
278 if [[ ! -d /etc/tgt/conf.d/ ]]; then
Attila Fazekasb79574b2012-12-01 10:42:46 +0100279 sudo mkdir -p /etc/tgt/conf.d
Mate Lakata39caac2012-09-03 15:45:53 +0100280 echo "include /etc/tgt/conf.d/*.conf" | sudo tee -a /etc/tgt/targets.conf
281 fi
282}
283
Dean Troyer67787e62012-05-02 11:48:15 -0500284# start_cinder() - Start running processes, including screen
285function start_cinder() {
286 if is_service_enabled c-vol; then
Attila Fazekasb79574b2012-12-01 10:42:46 +0100287 _configure_tgt_for_config_d
288 if [[ ! -f /etc/tgt/conf.d/stack.conf ]]; then
289 echo "include $CINDER_STATE_PATH/volumes/*" | sudo tee /etc/tgt/conf.d/stack.conf
290 fi
Vincent Untzc18b9652012-12-04 12:36:34 +0100291 if is_ubuntu; then
Dean Troyer67787e62012-05-02 11:48:15 -0500292 # tgt in oneiric doesn't restart properly if tgtd isn't running
293 # do it in two steps
294 sudo stop tgt || true
295 sudo start tgt
Vincent Untz00011c02012-12-06 09:56:32 +0100296 elif is_fedora; then
Dean Troyer67787e62012-05-02 11:48:15 -0500297 # bypass redirection to systemctl during restart
298 sudo /sbin/service --skip-redirect tgtd restart
Vincent Untz00011c02012-12-06 09:56:32 +0100299 elif is_suse; then
300 restart_service tgtd
301 else
302 # note for other distros: unstack.sh also uses the tgt/tgtd service
303 # name, and would need to be adjusted too
304 exit_distro_not_supported "restarting tgt"
Dean Troyer67787e62012-05-02 11:48:15 -0500305 fi
306 fi
307
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400308 screen_it c-api "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
309 screen_it c-vol "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF"
310 screen_it c-sch "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
Dean Troyer560346b2012-12-13 17:05:24 -0600311
312 # Start proxies if enabled
313 if is_service_enabled c-api && is_service_enabled tls-proxy; then
314 start_tls_proxy '*' $CINDER_SERVICE_PORT $CINDER_SERVICE_HOST $CINDER_SERVICE_PORT_INT &
315 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500316}
317
Dean Troyer699a29f2012-09-10 14:10:27 -0500318# stop_cinder() - Stop running processes
Dean Troyer67787e62012-05-02 11:48:15 -0500319function stop_cinder() {
Dean Troyer699a29f2012-09-10 14:10:27 -0500320 # Kill the cinder screen windows
321 for serv in c-api c-sch c-vol; do
322 screen -S $SCREEN_NAME -p $serv -X kill
323 done
Dean Troyer67787e62012-05-02 11:48:15 -0500324
325 if is_service_enabled c-vol; then
326 stop_service tgt
327 fi
328}
Dean Troyer7903b792012-09-13 17:16:12 -0500329
330# Restore xtrace
331$XTRACE