blob: 93cbc1704bfeddccbd83735f05e925a8cb0aca78 [file] [log] [blame]
Dean Troyer67787e62012-05-02 11:48:15 -05001# lib/cinder
Dean Troyer6d04fd72012-12-21 11:03:37 -06002# Install and start **Cinder** volume service
Dean Troyer67787e62012-05-02 11:48:15 -05003
4# Dependencies:
5# - functions
Attila Fazekas91b8d132013-01-06 22:40:09 +01006# - DEST, DATA_DIR, STACK_USER 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
Jakub Ruzicka4196d552013-01-30 15:35:54 +010050 CINDER_BIN_DIR=$(get_python_exec_prefix)
Monty Taylor9fbeedd2012-08-17 12:52:27 -040051fi
Dean Troyer67787e62012-05-02 11:48:15 -050052
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +010053# Support for multi lvm backend configuration (default is no support)
54CINDER_MULTI_LVM_BACKEND=$(trueorfalse False $CINDER_MULTI_LVM_BACKEND)
55
Dean Troyerb7490da2013-03-18 16:07:56 -050056# Should cinder perform secure deletion of volumes?
57# Defaults to true, can be set to False to avoid this bug when testing:
58# https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1023755
59CINDER_SECURE_DELETE=`trueorfalse True $CINDER_SECURE_DELETE`
60
Sean Daguef35ff722013-05-16 16:31:12 -040061# Cinder reports allocations back to the scheduler on periodic intervals
62# it turns out we can get an "out of space" issue when we run tests too
63# quickly just because cinder didn't realize we'd freed up resources.
64# Make this configurable so that devstack-gate/tempest can set it to
65# less than the 60 second default
66# https://bugs.launchpad.net/cinder/+bug/1180976
67CINDER_PERIODIC_INTERVAL=${CINDER_PERIODIC_INTERVAL:-60}
68
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +010069# Name of the lvm volume groups to use/create for iscsi volumes
Dean Troyer67787e62012-05-02 11:48:15 -050070VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes}
JordanP51c90b82013-05-23 10:27:51 +020071VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file}
72
73# VOLUME_GROUP2 is used only if CINDER_MULTI_LVM_BACKEND = True
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +010074VOLUME_GROUP2=${VOLUME_GROUP2:-stack-volumes2}
JordanP51c90b82013-05-23 10:27:51 +020075VOLUME_BACKING_FILE2=${VOLUME_BACKING_FILE2:-$DATA_DIR/${VOLUME_GROUP2}-backing-file}
76
Dean Troyer67787e62012-05-02 11:48:15 -050077VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-}
78
Dean Troyercc6b4432013-04-08 15:38:03 -050079
80# Functions
81# ---------
JordanP51c90b82013-05-23 10:27:51 +020082# _cleanup_lvm removes all cinder volumes and the backing file of the
83# volume group used by cinder
84# _cleanup_lvm $VOLUME_GROUP $VOLUME_NAME_PREFIX
85function _cleanup_lvm() {
Dean Troyer22853c12013-01-07 15:18:12 -060086 local vg=$1
JordanP51c90b82013-05-23 10:27:51 +020087 local lv_prefix=$2
88
Dean Troyer22853c12013-01-07 15:18:12 -060089 # Clean out existing volumes
90 for lv in `sudo lvs --noheadings -o lv_name $vg`; do
JordanP51c90b82013-05-23 10:27:51 +020091 # lv_prefix prefixes the LVs we want
92 if [[ "${lv#$lv_prefix}" != "$lv" ]]; then
Dean Troyer22853c12013-01-07 15:18:12 -060093 sudo lvremove -f $vg/$lv
94 fi
95 done
JordanP51c90b82013-05-23 10:27:51 +020096
97 # if there is no logical volume left, it's safe to attempt a cleanup
98 # of the backing file
99 if [ -z "`sudo lvs --noheadings -o lv_name $vg`" ]; then
100 # if the backing physical device is a loop device, it was probably setup by devstack
101 VG_DEV=$(sudo losetup -j $DATA_DIR/${vg}-backing-file | awk -F':' '/backing-file/ { print $1}')
102 if [[ -n "$VG_DEV" ]]; then
103 sudo losetup -d $VG_DEV
104 rm -f $DATA_DIR/${vg}-backing-file
105 fi
106 fi
Dean Troyer22853c12013-01-07 15:18:12 -0600107}
108
Dean Troyer67787e62012-05-02 11:48:15 -0500109# cleanup_cinder() - Remove residual data files, anything left over from previous
110# runs that a clean run would need to clean up
111function cleanup_cinder() {
Sean Dague252f2f52012-12-20 16:41:57 -0500112 # ensure the volume group is cleared up because fails might
113 # leave dead volumes in the group
114 TARGETS=$(sudo tgtadm --op show --mode target)
115 if [ $? -ne 0 ]; then
116 # If tgt driver isn't running this won't work obviously
117 # So check the response and restart if need be
118 echo "tgtd seems to be in a bad state, restarting..."
119 if is_ubuntu; then
120 restart_service tgt
121 else
122 restart_service tgtd
123 fi
124 TARGETS=$(sudo tgtadm --op show --mode target)
125 fi
126
127 if [[ -n "$TARGETS" ]]; then
128 iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
129 for i in "${iqn_list[@]}"; do
130 echo removing iSCSI target: $i
131 sudo tgt-admin --delete $i
132 done
133 fi
134
135 if is_service_enabled cinder; then
136 sudo rm -rf $CINDER_STATE_PATH/volumes/*
137 fi
138
139 if is_ubuntu; then
140 stop_service tgt
141 else
142 stop_service tgtd
143 fi
144
Dean Troyer22853c12013-01-07 15:18:12 -0600145 # Campsite rule: leave behind a volume group at least as clean as we found it
JordanP51c90b82013-05-23 10:27:51 +0200146 _cleanup_lvm $VOLUME_GROUP $VOLUME_NAME_PREFIX
147
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100148 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
JordanP51c90b82013-05-23 10:27:51 +0200149 _cleanup_lvm $VOLUME_GROUP2 $VOLUME_NAME_PREFIX
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100150 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500151}
152
153# configure_cinder() - Set config files, create data dirs, etc
154function configure_cinder() {
Dean Troyer67787e62012-05-02 11:48:15 -0500155 if [[ ! -d $CINDER_CONF_DIR ]]; then
156 sudo mkdir -p $CINDER_CONF_DIR
157 fi
Attila Fazekas91b8d132013-01-06 22:40:09 +0100158 sudo chown $STACK_USER $CINDER_CONF_DIR
Dean Troyer67787e62012-05-02 11:48:15 -0500159
160 cp -p $CINDER_DIR/etc/cinder/policy.json $CINDER_CONF_DIR
161
John Griffith4e823ff2012-07-20 13:18:17 -0600162 # Set the paths of certain binaries
Vincent Untz856a11e2012-11-21 16:04:12 +0100163 CINDER_ROOTWRAP=$(get_rootwrap_location cinder)
John Griffith4e823ff2012-07-20 13:18:17 -0600164
165 # If Cinder ships the new rootwrap filters files, deploy them
166 # (owned by root) and add a parameter to $CINDER_ROOTWRAP
167 ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP"
168 if [[ -d $CINDER_DIR/etc/cinder/rootwrap.d ]]; then
169 # Wipe any existing rootwrap.d files first
170 if [[ -d $CINDER_CONF_DIR/rootwrap.d ]]; then
171 sudo rm -rf $CINDER_CONF_DIR/rootwrap.d
172 fi
173 # Deploy filters to /etc/cinder/rootwrap.d
174 sudo mkdir -m 755 $CINDER_CONF_DIR/rootwrap.d
175 sudo cp $CINDER_DIR/etc/cinder/rootwrap.d/*.filters $CINDER_CONF_DIR/rootwrap.d
176 sudo chown -R root:root $CINDER_CONF_DIR/rootwrap.d
177 sudo chmod 644 $CINDER_CONF_DIR/rootwrap.d/*
178 # Set up rootwrap.conf, pointing to /etc/cinder/rootwrap.d
179 sudo cp $CINDER_DIR/etc/cinder/rootwrap.conf $CINDER_CONF_DIR/
180 sudo sed -e "s:^filters_path=.*$:filters_path=$CINDER_CONF_DIR/rootwrap.d:" -i $CINDER_CONF_DIR/rootwrap.conf
181 sudo chown root:root $CINDER_CONF_DIR/rootwrap.conf
182 sudo chmod 0644 $CINDER_CONF_DIR/rootwrap.conf
183 # Specify rootwrap.conf as first parameter to cinder-rootwrap
184 CINDER_ROOTWRAP="$CINDER_ROOTWRAP $CINDER_CONF_DIR/rootwrap.conf"
185 ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP *"
186 fi
187
188 TEMPFILE=`mktemp`
189 echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_CINDER_SUDOER_CMD" >$TEMPFILE
190 chmod 0440 $TEMPFILE
191 sudo chown root:root $TEMPFILE
192 sudo mv $TEMPFILE /etc/sudoers.d/cinder-rootwrap
193
Dean Troyer67787e62012-05-02 11:48:15 -0500194 cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
195 iniset $CINDER_API_PASTE_INI filter:authtoken auth_host $KEYSTONE_AUTH_HOST
196 iniset $CINDER_API_PASTE_INI filter:authtoken auth_port $KEYSTONE_AUTH_PORT
197 iniset $CINDER_API_PASTE_INI filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
198 iniset $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
199 iniset $CINDER_API_PASTE_INI filter:authtoken admin_user cinder
200 iniset $CINDER_API_PASTE_INI filter:authtoken admin_password $SERVICE_PASSWORD
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +0900201 iniset $CINDER_API_PASTE_INI filter:authtoken signing_dir $CINDER_AUTH_CACHE_DIR
Dean Troyerbc071bc2012-10-01 14:06:44 -0500202
Dean Troyer67787e62012-05-02 11:48:15 -0500203 cp $CINDER_DIR/etc/cinder/cinder.conf.sample $CINDER_CONF
204 iniset $CINDER_CONF DEFAULT auth_strategy keystone
John Griffith997c1032013-03-05 23:01:38 +0000205 iniset $CINDER_CONF DEFAULT debug True
Dean Troyer67787e62012-05-02 11:48:15 -0500206 iniset $CINDER_CONF DEFAULT verbose True
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100207 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
208 iniset $CINDER_CONF DEFAULT enabled_backends lvmdriver-1,lvmdriver-2
209 iniset $CINDER_CONF lvmdriver-1 volume_group $VOLUME_GROUP
210 iniset $CINDER_CONF lvmdriver-1 volume_driver cinder.volume.drivers.lvm.LVMISCSIDriver
211 iniset $CINDER_CONF lvmdriver-1 volume_backend_name LVM_iSCSI
212 iniset $CINDER_CONF lvmdriver-2 volume_group $VOLUME_GROUP2
213 iniset $CINDER_CONF lvmdriver-2 volume_driver cinder.volume.drivers.lvm.LVMISCSIDriver
214 iniset $CINDER_CONF lvmdriver-2 volume_backend_name LVM_iSCSI
215 else
216 iniset $CINDER_CONF DEFAULT volume_group $VOLUME_GROUP
217 iniset $CINDER_CONF DEFAULT volume_name_template ${VOLUME_NAME_PREFIX}%s
218 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500219 iniset $CINDER_CONF DEFAULT iscsi_helper tgtadm
Attila Fazekas7e79d912013-03-03 12:23:04 +0100220 iniset $CINDER_CONF DEFAULT sql_connection `database_connection_url cinder`
Dean Troyer67787e62012-05-02 11:48:15 -0500221 iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
Joe Gordona58382a2013-02-20 12:45:02 -0800222 iniset $CINDER_CONF DEFAULT rootwrap_config "$CINDER_CONF_DIR/rootwrap.conf"
Dan Prince9f22f072013-01-28 09:53:38 -0500223 iniset $CINDER_CONF DEFAULT osapi_volume_extension cinder.api.contrib.standard_extensions
Dean Troyer50ac7922012-09-13 14:02:01 -0500224 iniset $CINDER_CONF DEFAULT state_path $CINDER_STATE_PATH
Sean Daguef35ff722013-05-16 16:31:12 -0400225 iniset $CINDER_CONF DEFAULT periodic_interval $CINDER_PERIODIC_INTERVAL
John Griffith4e823ff2012-07-20 13:18:17 -0600226
Dean Troyer560346b2012-12-13 17:05:24 -0600227 if is_service_enabled tls-proxy; then
228 # Set the service port for a proxy to take the original
229 iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
230 fi
231
Dean Troyer4d3049e2012-11-06 20:38:14 -0600232 if [ "$SYSLOG" != "False" ]; then
233 iniset $CINDER_CONF DEFAULT use_syslog True
234 fi
235
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900236 iniset_rpc_backend cinder $CINDER_CONF DEFAULT
Gary Kottonf71bf192012-08-06 11:15:36 -0400237
James E. Blair213c4162012-11-06 09:38:36 +0100238 if [[ "$CINDER_SECURE_DELETE" == "False" ]]; then
239 iniset $CINDER_CONF DEFAULT secure_delete False
Pádraig Bradyeac93702013-01-02 16:02:54 +0000240 iniset $CINDER_CONF DEFAULT volume_clear none
James E. Blair213c4162012-11-06 09:38:36 +0100241 fi
242
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000243 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
244 # Add color to logging output
Joe Gordon07db7132013-01-30 13:07:25 -0800245 iniset $CINDER_CONF DEFAULT logging_context_format_string "%(asctime)s.%(msecs)03d %(color)s%(levelname)s %(name)s [%(request_id)s %(user_id)s %(project_id)s%(color)s] %(instance)s%(color)s%(message)s"
246 iniset $CINDER_CONF DEFAULT logging_default_format_string "%(asctime)s.%(msecs)03d %(color)s%(levelname)s %(name)s [-%(color)s] %(instance)s%(color)s%(message)s"
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000247 iniset $CINDER_CONF DEFAULT logging_debug_format_suffix "from (pid=%(process)d) %(funcName)s %(pathname)s:%(lineno)d"
Joe Gordon07db7132013-01-30 13:07:25 -0800248 iniset $CINDER_CONF DEFAULT logging_exception_prefix "%(color)s%(asctime)s.%(msecs)03d TRACE %(name)s %(instance)s"
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000249 fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000250
251 if [ "$CINDER_DRIVER" == "XenAPINFS" ]; then
252 (
253 set -u
Mate Lakata0ca45f2012-12-06 17:45:49 +0000254 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.xenapi.sm.XenAPINFSDriver"
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000255 iniset $CINDER_CONF DEFAULT xenapi_connection_url "$CINDER_XENAPI_CONNECTION_URL"
256 iniset $CINDER_CONF DEFAULT xenapi_connection_username "$CINDER_XENAPI_CONNECTION_USERNAME"
257 iniset $CINDER_CONF DEFAULT xenapi_connection_password "$CINDER_XENAPI_CONNECTION_PASSWORD"
258 iniset $CINDER_CONF DEFAULT xenapi_nfs_server "$CINDER_XENAPI_NFS_SERVER"
259 iniset $CINDER_CONF DEFAULT xenapi_nfs_serverpath "$CINDER_XENAPI_NFS_SERVERPATH"
260 )
MORITA Kazutakaaf22a472013-01-17 16:16:25 +0900261 elif [ "$CINDER_DRIVER" == "sheepdog" ]; then
262 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.sheepdog.SheepdogDriver"
Eric Harneycd261512013-04-10 12:48:09 -0400263 elif [ "$CINDER_DRIVER" == "glusterfs" ]; then
264 # To use glusterfs, set the following in localrc:
265 # CINDER_DRIVER=glusterfs
266 # CINDER_GLUSTERFS_SHARES="127.0.0.1:/vol1;127.0.0.1:/vol2"
267 # Shares are <host>:<volume> and separated by semicolons.
268
269 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.glusterfs.GlusterfsDriver"
270 iniset $CINDER_CONF DEFAULT glusterfs_shares_config "$CINDER_CONF_DIR/glusterfs_shares"
271 touch $CINDER_CONF_DIR/glusterfs_shares
272 if [ ! -z "$CINDER_GLUSTERFS_SHARES" ]; then
273 CINDER_GLUSTERFS_SHARES=$(echo $CINDER_GLUSTERFS_SHARES | tr ";" "\n")
274 echo "$CINDER_GLUSTERFS_SHARES" > $CINDER_CONF_DIR/glusterfs_shares
275 fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000276 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500277}
278
Dean Troyer671c16e2012-12-13 16:22:38 -0600279# create_cinder_accounts() - Set up common required cinder accounts
280
281# Tenant User Roles
282# ------------------------------------------------------------------
283# service cinder admin # if enabled
284
285# Migrated from keystone_data.sh
286create_cinder_accounts() {
287
288 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
289 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
290
291 # Cinder
292 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
293 CINDER_USER=$(keystone user-create \
294 --name=cinder \
295 --pass="$SERVICE_PASSWORD" \
296 --tenant_id $SERVICE_TENANT \
297 --email=cinder@example.com \
298 | grep " id " | get_field 2)
299 keystone user-role-add \
300 --tenant_id $SERVICE_TENANT \
301 --user_id $CINDER_USER \
302 --role_id $ADMIN_ROLE
303 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
304 CINDER_SERVICE=$(keystone service-create \
305 --name=cinder \
306 --type=volume \
307 --description="Cinder Volume Service" \
308 | grep " id " | get_field 2)
309 keystone endpoint-create \
310 --region RegionOne \
311 --service_id $CINDER_SERVICE \
Dean Troyer560346b2012-12-13 17:05:24 -0600312 --publicurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
313 --adminurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
314 --internalurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s"
Dean Troyer671c16e2012-12-13 16:22:38 -0600315 fi
316 fi
317}
318
Dean Troyerf03bafe2013-02-12 10:58:28 -0600319# create_cinder_cache_dir() - Part of the init_cinder() process
320function create_cinder_cache_dir() {
321 # Create cache dir
322 sudo mkdir -p $CINDER_AUTH_CACHE_DIR
323 sudo chown $STACK_USER $CINDER_AUTH_CACHE_DIR
324 rm -f $CINDER_AUTH_CACHE_DIR/*
325}
326
327create_cinder_volume_group() {
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100328 # According to the CINDER_MULTI_LVM_BACKEND value, configure one or two default volumes
329 # group called ``stack-volumes`` (and ``stack-volumes2``) for the volume
330 # service if it (they) does (do) not yet exist. If you don't wish to use a
331 # file backed volume group, create your own volume group called ``stack-volumes``
332 # and ``stack-volumes2`` before invoking ``stack.sh``.
Dean Troyerf03bafe2013-02-12 10:58:28 -0600333 #
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100334 # By default, the two backing files are 5G in size, and are stored in
335 # ``/opt/stack/data``.
Dean Troyerf03bafe2013-02-12 10:58:28 -0600336
337 if ! sudo vgs $VOLUME_GROUP; then
Dean Troyerf03bafe2013-02-12 10:58:28 -0600338 # Only create if the file doesn't already exists
339 [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
340
341 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE`
342
343 # Only create if the loopback device doesn't contain $VOLUME_GROUP
344 if ! sudo vgs $VOLUME_GROUP; then
345 sudo vgcreate $VOLUME_GROUP $DEV
346 fi
347 fi
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100348 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
349 #set up the second volume if CINDER_MULTI_LVM_BACKEND is enabled
350
351 if ! sudo vgs $VOLUME_GROUP2; then
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100352 # Only create if the file doesn't already exists
353 [[ -f $VOLUME_BACKING_FILE2 ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE2
354
355 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE2`
356
357 # Only create if the loopback device doesn't contain $VOLUME_GROUP
358 if ! sudo vgs $VOLUME_GROUP2; then
359 sudo vgcreate $VOLUME_GROUP2 $DEV
360 fi
361 fi
362 fi
Dean Troyerf03bafe2013-02-12 10:58:28 -0600363
364 mkdir -p $CINDER_STATE_PATH/volumes
365}
366
Dean Troyer67787e62012-05-02 11:48:15 -0500367# init_cinder() - Initialize database and volume group
368function init_cinder() {
369 # Force nova volumes off
370 NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/osapi_volume,//")
371
Terry Wilson428af5a2012-11-01 16:12:39 -0400372 if is_service_enabled $DATABASE_BACKENDS; then
Dean Troyerf03bafe2013-02-12 10:58:28 -0600373 # (Re)create cinder database
Terry Wilson428af5a2012-11-01 16:12:39 -0400374 recreate_database cinder utf8
Dean Troyer67787e62012-05-02 11:48:15 -0500375
Dean Troyerf03bafe2013-02-12 10:58:28 -0600376 # Migrate cinder database
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400377 $CINDER_BIN_DIR/cinder-manage db sync
Dean Troyer67787e62012-05-02 11:48:15 -0500378 fi
379
380 if is_service_enabled c-vol; then
Dean Troyer67787e62012-05-02 11:48:15 -0500381
Dean Troyerf03bafe2013-02-12 10:58:28 -0600382 create_cinder_volume_group
Chuck Short3f603d92012-07-28 13:28:33 -0500383
Dean Troyer67787e62012-05-02 11:48:15 -0500384 if sudo vgs $VOLUME_GROUP; then
Vincent Untz00011c02012-12-06 09:56:32 +0100385 if is_fedora || is_suse; then
386 # service is not started by default
Vincent Untz0230aa82012-06-14 08:51:01 +0200387 start_service tgtd
388 fi
389
Dean Troyer67787e62012-05-02 11:48:15 -0500390 # Remove iscsi targets
391 sudo tgtadm --op show --mode target | grep $VOLUME_NAME_PREFIX | grep Target | cut -f3 -d ' ' | sudo xargs -n1 tgt-admin --delete || true
Dean Troyer22853c12013-01-07 15:18:12 -0600392 # Start with a clean volume group
393 _clean_volume_group $VOLUME_GROUP $VOLUME_NAME_PREFIX
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100394 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
395 _clean_volume_group $VOLUME_GROUP2 $VOLUME_NAME_PREFIX
396 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500397 fi
398 fi
Dean Troyerbc071bc2012-10-01 14:06:44 -0500399
Dean Troyerf03bafe2013-02-12 10:58:28 -0600400 create_cinder_cache_dir
Dean Troyer67787e62012-05-02 11:48:15 -0500401}
402
403# install_cinder() - Collect source and prepare
404function install_cinder() {
405 git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400406 setup_develop $CINDER_DIR
Dean Troyer253a1a32013-04-01 18:23:22 -0500407}
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400408
Dean Troyer253a1a32013-04-01 18:23:22 -0500409# install_cinderclient() - Collect source and prepare
410function install_cinderclient() {
Dean Troyer67787e62012-05-02 11:48:15 -0500411 git_clone $CINDERCLIENT_REPO $CINDERCLIENT_DIR $CINDERCLIENT_BRANCH
Sean Dague4bf9d7a2013-04-01 16:41:39 -0400412 setup_develop $CINDERCLIENT_DIR
Dean Troyer67787e62012-05-02 11:48:15 -0500413}
414
Steve Baker18225d92013-04-14 12:48:41 -0700415# apply config.d approach for cinder volumes directory
Mate Lakata39caac2012-09-03 15:45:53 +0100416function _configure_tgt_for_config_d() {
Steve Baker18225d92013-04-14 12:48:41 -0700417 if [[ ! -d /etc/tgt/stack.d/ ]]; then
418 sudo ln -sf $CINDER_STATE_PATH/volumes /etc/tgt/stack.d
419 echo "include /etc/tgt/stack.d/*" | sudo tee -a /etc/tgt/targets.conf
Mate Lakata39caac2012-09-03 15:45:53 +0100420 fi
421}
422
Dean Troyer67787e62012-05-02 11:48:15 -0500423# start_cinder() - Start running processes, including screen
424function start_cinder() {
425 if is_service_enabled c-vol; then
Steve Baker18225d92013-04-14 12:48:41 -0700426 # Delete any old stack.conf
427 sudo rm -f /etc/tgt/conf.d/stack.conf
Attila Fazekasb79574b2012-12-01 10:42:46 +0100428 _configure_tgt_for_config_d
Vincent Untzc18b9652012-12-04 12:36:34 +0100429 if is_ubuntu; then
Dean Troyer67787e62012-05-02 11:48:15 -0500430 # tgt in oneiric doesn't restart properly if tgtd isn't running
431 # do it in two steps
432 sudo stop tgt || true
433 sudo start tgt
Vincent Untz00011c02012-12-06 09:56:32 +0100434 elif is_fedora; then
Dean Troyer67787e62012-05-02 11:48:15 -0500435 # bypass redirection to systemctl during restart
436 sudo /sbin/service --skip-redirect tgtd restart
Vincent Untz00011c02012-12-06 09:56:32 +0100437 elif is_suse; then
438 restart_service tgtd
439 else
440 # note for other distros: unstack.sh also uses the tgt/tgtd service
441 # name, and would need to be adjusted too
442 exit_distro_not_supported "restarting tgt"
Dean Troyer67787e62012-05-02 11:48:15 -0500443 fi
444 fi
445
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400446 screen_it c-api "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
447 screen_it c-vol "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF"
448 screen_it c-sch "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
Stephen Mulcahy67068ef2013-02-21 11:20:58 +0000449 screen_it c-bak "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-backup --config-file $CINDER_CONF"
Dean Troyer560346b2012-12-13 17:05:24 -0600450
451 # Start proxies if enabled
452 if is_service_enabled c-api && is_service_enabled tls-proxy; then
453 start_tls_proxy '*' $CINDER_SERVICE_PORT $CINDER_SERVICE_HOST $CINDER_SERVICE_PORT_INT &
454 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500455}
456
Dean Troyer699a29f2012-09-10 14:10:27 -0500457# stop_cinder() - Stop running processes
Dean Troyer67787e62012-05-02 11:48:15 -0500458function stop_cinder() {
Dean Troyer699a29f2012-09-10 14:10:27 -0500459 # Kill the cinder screen windows
Stephen Mulcahy67068ef2013-02-21 11:20:58 +0000460 for serv in c-api c-bak c-sch c-vol; do
Dean Troyer699a29f2012-09-10 14:10:27 -0500461 screen -S $SCREEN_NAME -p $serv -X kill
462 done
Dean Troyer67787e62012-05-02 11:48:15 -0500463
464 if is_service_enabled c-vol; then
Vincent Untz90dd96d2012-12-13 08:59:57 +0100465 if is_ubuntu; then
466 stop_service tgt
467 else
468 stop_service tgtd
469 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500470 fi
471}
Dean Troyer7903b792012-09-13 17:16:12 -0500472
Dean Troyercc6b4432013-04-08 15:38:03 -0500473
Dean Troyer7903b792012-09-13 17:16:12 -0500474# Restore xtrace
475$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400476
477# Local variables:
478# mode: shell-script
479# End: