blob: 7afd69bdc8b367a6f97434c473e543c94d5f4478 [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
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +010061# Name of the lvm volume groups to use/create for iscsi volumes
62# VOLUME_GROUP2 is used only if CINDER_MULTI_LVM_BACKEND = True
Dean Troyer67787e62012-05-02 11:48:15 -050063VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes}
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +010064VOLUME_GROUP2=${VOLUME_GROUP2:-stack-volumes2}
Dean Troyer67787e62012-05-02 11:48:15 -050065VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-}
66
Dean Troyer22853c12013-01-07 15:18:12 -060067# _clean_volume_group removes all cinder volumes from the specified volume group
68# _clean_volume_group $VOLUME_GROUP $VOLUME_NAME_PREFIX
69function _clean_volume_group() {
70 local vg=$1
71 local vg_prefix=$2
72 # Clean out existing volumes
73 for lv in `sudo lvs --noheadings -o lv_name $vg`; do
74 # vg_prefix prefixes the LVs we want
75 if [[ "${lv#$vg_prefix}" != "$lv" ]]; then
76 sudo lvremove -f $vg/$lv
77 fi
78 done
79}
80
Dean Troyer67787e62012-05-02 11:48:15 -050081# cleanup_cinder() - Remove residual data files, anything left over from previous
82# runs that a clean run would need to clean up
83function cleanup_cinder() {
Sean Dague252f2f52012-12-20 16:41:57 -050084 # ensure the volume group is cleared up because fails might
85 # leave dead volumes in the group
86 TARGETS=$(sudo tgtadm --op show --mode target)
87 if [ $? -ne 0 ]; then
88 # If tgt driver isn't running this won't work obviously
89 # So check the response and restart if need be
90 echo "tgtd seems to be in a bad state, restarting..."
91 if is_ubuntu; then
92 restart_service tgt
93 else
94 restart_service tgtd
95 fi
96 TARGETS=$(sudo tgtadm --op show --mode target)
97 fi
98
99 if [[ -n "$TARGETS" ]]; then
100 iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
101 for i in "${iqn_list[@]}"; do
102 echo removing iSCSI target: $i
103 sudo tgt-admin --delete $i
104 done
105 fi
106
107 if is_service_enabled cinder; then
108 sudo rm -rf $CINDER_STATE_PATH/volumes/*
109 fi
110
111 if is_ubuntu; then
112 stop_service tgt
113 else
114 stop_service tgtd
115 fi
116
Dean Troyer22853c12013-01-07 15:18:12 -0600117 # Campsite rule: leave behind a volume group at least as clean as we found it
118 _clean_volume_group $VOLUME_GROUP $VOLUME_NAME_PREFIX
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100119 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
120 _clean_volume_group $VOLUME_GROUP2 $VOLUME_NAME_PREFIX
121 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500122}
123
124# configure_cinder() - Set config files, create data dirs, etc
125function configure_cinder() {
126 setup_develop $CINDER_DIR
127 setup_develop $CINDERCLIENT_DIR
128
129 if [[ ! -d $CINDER_CONF_DIR ]]; then
130 sudo mkdir -p $CINDER_CONF_DIR
131 fi
Attila Fazekas91b8d132013-01-06 22:40:09 +0100132 sudo chown $STACK_USER $CINDER_CONF_DIR
Dean Troyer67787e62012-05-02 11:48:15 -0500133
134 cp -p $CINDER_DIR/etc/cinder/policy.json $CINDER_CONF_DIR
135
John Griffith4e823ff2012-07-20 13:18:17 -0600136 # Set the paths of certain binaries
Vincent Untz856a11e2012-11-21 16:04:12 +0100137 CINDER_ROOTWRAP=$(get_rootwrap_location cinder)
John Griffith4e823ff2012-07-20 13:18:17 -0600138
139 # If Cinder ships the new rootwrap filters files, deploy them
140 # (owned by root) and add a parameter to $CINDER_ROOTWRAP
141 ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP"
142 if [[ -d $CINDER_DIR/etc/cinder/rootwrap.d ]]; then
143 # Wipe any existing rootwrap.d files first
144 if [[ -d $CINDER_CONF_DIR/rootwrap.d ]]; then
145 sudo rm -rf $CINDER_CONF_DIR/rootwrap.d
146 fi
147 # Deploy filters to /etc/cinder/rootwrap.d
148 sudo mkdir -m 755 $CINDER_CONF_DIR/rootwrap.d
149 sudo cp $CINDER_DIR/etc/cinder/rootwrap.d/*.filters $CINDER_CONF_DIR/rootwrap.d
150 sudo chown -R root:root $CINDER_CONF_DIR/rootwrap.d
151 sudo chmod 644 $CINDER_CONF_DIR/rootwrap.d/*
152 # Set up rootwrap.conf, pointing to /etc/cinder/rootwrap.d
153 sudo cp $CINDER_DIR/etc/cinder/rootwrap.conf $CINDER_CONF_DIR/
154 sudo sed -e "s:^filters_path=.*$:filters_path=$CINDER_CONF_DIR/rootwrap.d:" -i $CINDER_CONF_DIR/rootwrap.conf
155 sudo chown root:root $CINDER_CONF_DIR/rootwrap.conf
156 sudo chmod 0644 $CINDER_CONF_DIR/rootwrap.conf
157 # Specify rootwrap.conf as first parameter to cinder-rootwrap
158 CINDER_ROOTWRAP="$CINDER_ROOTWRAP $CINDER_CONF_DIR/rootwrap.conf"
159 ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP *"
160 fi
161
162 TEMPFILE=`mktemp`
163 echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_CINDER_SUDOER_CMD" >$TEMPFILE
164 chmod 0440 $TEMPFILE
165 sudo chown root:root $TEMPFILE
166 sudo mv $TEMPFILE /etc/sudoers.d/cinder-rootwrap
167
Dean Troyer67787e62012-05-02 11:48:15 -0500168 cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
169 iniset $CINDER_API_PASTE_INI filter:authtoken auth_host $KEYSTONE_AUTH_HOST
170 iniset $CINDER_API_PASTE_INI filter:authtoken auth_port $KEYSTONE_AUTH_PORT
171 iniset $CINDER_API_PASTE_INI filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
172 iniset $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
173 iniset $CINDER_API_PASTE_INI filter:authtoken admin_user cinder
174 iniset $CINDER_API_PASTE_INI filter:authtoken admin_password $SERVICE_PASSWORD
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +0900175 iniset $CINDER_API_PASTE_INI filter:authtoken signing_dir $CINDER_AUTH_CACHE_DIR
Dean Troyerbc071bc2012-10-01 14:06:44 -0500176
Dean Troyer67787e62012-05-02 11:48:15 -0500177 cp $CINDER_DIR/etc/cinder/cinder.conf.sample $CINDER_CONF
178 iniset $CINDER_CONF DEFAULT auth_strategy keystone
John Griffith997c1032013-03-05 23:01:38 +0000179 iniset $CINDER_CONF DEFAULT debug True
Dean Troyer67787e62012-05-02 11:48:15 -0500180 iniset $CINDER_CONF DEFAULT verbose True
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100181 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
182 iniset $CINDER_CONF DEFAULT enabled_backends lvmdriver-1,lvmdriver-2
183 iniset $CINDER_CONF lvmdriver-1 volume_group $VOLUME_GROUP
184 iniset $CINDER_CONF lvmdriver-1 volume_driver cinder.volume.drivers.lvm.LVMISCSIDriver
185 iniset $CINDER_CONF lvmdriver-1 volume_backend_name LVM_iSCSI
186 iniset $CINDER_CONF lvmdriver-2 volume_group $VOLUME_GROUP2
187 iniset $CINDER_CONF lvmdriver-2 volume_driver cinder.volume.drivers.lvm.LVMISCSIDriver
188 iniset $CINDER_CONF lvmdriver-2 volume_backend_name LVM_iSCSI
189 else
190 iniset $CINDER_CONF DEFAULT volume_group $VOLUME_GROUP
191 iniset $CINDER_CONF DEFAULT volume_name_template ${VOLUME_NAME_PREFIX}%s
192 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500193 iniset $CINDER_CONF DEFAULT iscsi_helper tgtadm
Attila Fazekas7e79d912013-03-03 12:23:04 +0100194 iniset $CINDER_CONF DEFAULT sql_connection `database_connection_url cinder`
Dean Troyer67787e62012-05-02 11:48:15 -0500195 iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
Joe Gordona58382a2013-02-20 12:45:02 -0800196 iniset $CINDER_CONF DEFAULT rootwrap_config "$CINDER_CONF_DIR/rootwrap.conf"
Dan Prince9f22f072013-01-28 09:53:38 -0500197 iniset $CINDER_CONF DEFAULT osapi_volume_extension cinder.api.contrib.standard_extensions
Dean Troyer50ac7922012-09-13 14:02:01 -0500198 iniset $CINDER_CONF DEFAULT state_path $CINDER_STATE_PATH
John Griffith4e823ff2012-07-20 13:18:17 -0600199
Dean Troyer560346b2012-12-13 17:05:24 -0600200 if is_service_enabled tls-proxy; then
201 # Set the service port for a proxy to take the original
202 iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
203 fi
204
Dean Troyer4d3049e2012-11-06 20:38:14 -0600205 if [ "$SYSLOG" != "False" ]; then
206 iniset $CINDER_CONF DEFAULT use_syslog True
207 fi
208
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900209 iniset_rpc_backend cinder $CINDER_CONF DEFAULT
Gary Kottonf71bf192012-08-06 11:15:36 -0400210
James E. Blair213c4162012-11-06 09:38:36 +0100211 if [[ "$CINDER_SECURE_DELETE" == "False" ]]; then
212 iniset $CINDER_CONF DEFAULT secure_delete False
Pádraig Bradyeac93702013-01-02 16:02:54 +0000213 iniset $CINDER_CONF DEFAULT volume_clear none
James E. Blair213c4162012-11-06 09:38:36 +0100214 fi
215
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000216 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
217 # Add color to logging output
Joe Gordon07db7132013-01-30 13:07:25 -0800218 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"
219 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 +0000220 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 -0800221 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 +0000222 fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000223
224 if [ "$CINDER_DRIVER" == "XenAPINFS" ]; then
225 (
226 set -u
Mate Lakata0ca45f2012-12-06 17:45:49 +0000227 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.xenapi.sm.XenAPINFSDriver"
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000228 iniset $CINDER_CONF DEFAULT xenapi_connection_url "$CINDER_XENAPI_CONNECTION_URL"
229 iniset $CINDER_CONF DEFAULT xenapi_connection_username "$CINDER_XENAPI_CONNECTION_USERNAME"
230 iniset $CINDER_CONF DEFAULT xenapi_connection_password "$CINDER_XENAPI_CONNECTION_PASSWORD"
231 iniset $CINDER_CONF DEFAULT xenapi_nfs_server "$CINDER_XENAPI_NFS_SERVER"
232 iniset $CINDER_CONF DEFAULT xenapi_nfs_serverpath "$CINDER_XENAPI_NFS_SERVERPATH"
233 )
MORITA Kazutakaaf22a472013-01-17 16:16:25 +0900234 elif [ "$CINDER_DRIVER" == "sheepdog" ]; then
235 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.sheepdog.SheepdogDriver"
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000236 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500237}
238
Dean Troyer671c16e2012-12-13 16:22:38 -0600239# create_cinder_accounts() - Set up common required cinder accounts
240
241# Tenant User Roles
242# ------------------------------------------------------------------
243# service cinder admin # if enabled
244
245# Migrated from keystone_data.sh
246create_cinder_accounts() {
247
248 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
249 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
250
251 # Cinder
252 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
253 CINDER_USER=$(keystone user-create \
254 --name=cinder \
255 --pass="$SERVICE_PASSWORD" \
256 --tenant_id $SERVICE_TENANT \
257 --email=cinder@example.com \
258 | grep " id " | get_field 2)
259 keystone user-role-add \
260 --tenant_id $SERVICE_TENANT \
261 --user_id $CINDER_USER \
262 --role_id $ADMIN_ROLE
263 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
264 CINDER_SERVICE=$(keystone service-create \
265 --name=cinder \
266 --type=volume \
267 --description="Cinder Volume Service" \
268 | grep " id " | get_field 2)
269 keystone endpoint-create \
270 --region RegionOne \
271 --service_id $CINDER_SERVICE \
Dean Troyer560346b2012-12-13 17:05:24 -0600272 --publicurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
273 --adminurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
274 --internalurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s"
Dean Troyer671c16e2012-12-13 16:22:38 -0600275 fi
276 fi
277}
278
Dean Troyerf03bafe2013-02-12 10:58:28 -0600279# create_cinder_cache_dir() - Part of the init_cinder() process
280function create_cinder_cache_dir() {
281 # Create cache dir
282 sudo mkdir -p $CINDER_AUTH_CACHE_DIR
283 sudo chown $STACK_USER $CINDER_AUTH_CACHE_DIR
284 rm -f $CINDER_AUTH_CACHE_DIR/*
285}
286
287create_cinder_volume_group() {
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100288 # According to the CINDER_MULTI_LVM_BACKEND value, configure one or two default volumes
289 # group called ``stack-volumes`` (and ``stack-volumes2``) for the volume
290 # service if it (they) does (do) not yet exist. If you don't wish to use a
291 # file backed volume group, create your own volume group called ``stack-volumes``
292 # and ``stack-volumes2`` before invoking ``stack.sh``.
Dean Troyerf03bafe2013-02-12 10:58:28 -0600293 #
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100294 # By default, the two backing files are 5G in size, and are stored in
295 # ``/opt/stack/data``.
Dean Troyerf03bafe2013-02-12 10:58:28 -0600296
297 if ! sudo vgs $VOLUME_GROUP; then
298 VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file}
299
300 # Only create if the file doesn't already exists
301 [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
302
303 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE`
304
305 # Only create if the loopback device doesn't contain $VOLUME_GROUP
306 if ! sudo vgs $VOLUME_GROUP; then
307 sudo vgcreate $VOLUME_GROUP $DEV
308 fi
309 fi
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100310 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
311 #set up the second volume if CINDER_MULTI_LVM_BACKEND is enabled
312
313 if ! sudo vgs $VOLUME_GROUP2; then
314 VOLUME_BACKING_FILE2=${VOLUME_BACKING_FILE2:-$DATA_DIR/${VOLUME_GROUP2}-backing-file}
315
316 # Only create if the file doesn't already exists
317 [[ -f $VOLUME_BACKING_FILE2 ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE2
318
319 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE2`
320
321 # Only create if the loopback device doesn't contain $VOLUME_GROUP
322 if ! sudo vgs $VOLUME_GROUP2; then
323 sudo vgcreate $VOLUME_GROUP2 $DEV
324 fi
325 fi
326 fi
Dean Troyerf03bafe2013-02-12 10:58:28 -0600327
328 mkdir -p $CINDER_STATE_PATH/volumes
329}
330
Dean Troyer67787e62012-05-02 11:48:15 -0500331# init_cinder() - Initialize database and volume group
332function init_cinder() {
333 # Force nova volumes off
334 NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/osapi_volume,//")
335
Terry Wilson428af5a2012-11-01 16:12:39 -0400336 if is_service_enabled $DATABASE_BACKENDS; then
Dean Troyerf03bafe2013-02-12 10:58:28 -0600337 # (Re)create cinder database
Terry Wilson428af5a2012-11-01 16:12:39 -0400338 recreate_database cinder utf8
Dean Troyer67787e62012-05-02 11:48:15 -0500339
Dean Troyerf03bafe2013-02-12 10:58:28 -0600340 # Migrate cinder database
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400341 $CINDER_BIN_DIR/cinder-manage db sync
Dean Troyer67787e62012-05-02 11:48:15 -0500342 fi
343
344 if is_service_enabled c-vol; then
Dean Troyer67787e62012-05-02 11:48:15 -0500345
Dean Troyerf03bafe2013-02-12 10:58:28 -0600346 create_cinder_volume_group
Chuck Short3f603d92012-07-28 13:28:33 -0500347
Dean Troyer67787e62012-05-02 11:48:15 -0500348 if sudo vgs $VOLUME_GROUP; then
Vincent Untz00011c02012-12-06 09:56:32 +0100349 if is_fedora || is_suse; then
350 # service is not started by default
Vincent Untz0230aa82012-06-14 08:51:01 +0200351 start_service tgtd
352 fi
353
Dean Troyer67787e62012-05-02 11:48:15 -0500354 # Remove iscsi targets
355 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 -0600356 # Start with a clean volume group
357 _clean_volume_group $VOLUME_GROUP $VOLUME_NAME_PREFIX
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100358 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
359 _clean_volume_group $VOLUME_GROUP2 $VOLUME_NAME_PREFIX
360 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500361 fi
362 fi
Dean Troyerbc071bc2012-10-01 14:06:44 -0500363
Dean Troyerf03bafe2013-02-12 10:58:28 -0600364 create_cinder_cache_dir
Dean Troyer67787e62012-05-02 11:48:15 -0500365}
366
367# install_cinder() - Collect source and prepare
368function install_cinder() {
369 git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
370 git_clone $CINDERCLIENT_REPO $CINDERCLIENT_DIR $CINDERCLIENT_BRANCH
371}
372
Mate Lakata39caac2012-09-03 15:45:53 +0100373# apply config.d approach (e.g. Oneiric does not have this)
374function _configure_tgt_for_config_d() {
375 if [[ ! -d /etc/tgt/conf.d/ ]]; then
Attila Fazekasb79574b2012-12-01 10:42:46 +0100376 sudo mkdir -p /etc/tgt/conf.d
Mate Lakata39caac2012-09-03 15:45:53 +0100377 echo "include /etc/tgt/conf.d/*.conf" | sudo tee -a /etc/tgt/targets.conf
378 fi
379}
380
Dean Troyer67787e62012-05-02 11:48:15 -0500381# start_cinder() - Start running processes, including screen
382function start_cinder() {
383 if is_service_enabled c-vol; then
Attila Fazekasb79574b2012-12-01 10:42:46 +0100384 _configure_tgt_for_config_d
385 if [[ ! -f /etc/tgt/conf.d/stack.conf ]]; then
386 echo "include $CINDER_STATE_PATH/volumes/*" | sudo tee /etc/tgt/conf.d/stack.conf
387 fi
Vincent Untzc18b9652012-12-04 12:36:34 +0100388 if is_ubuntu; then
Dean Troyer67787e62012-05-02 11:48:15 -0500389 # tgt in oneiric doesn't restart properly if tgtd isn't running
390 # do it in two steps
391 sudo stop tgt || true
392 sudo start tgt
Vincent Untz00011c02012-12-06 09:56:32 +0100393 elif is_fedora; then
Dean Troyer67787e62012-05-02 11:48:15 -0500394 # bypass redirection to systemctl during restart
395 sudo /sbin/service --skip-redirect tgtd restart
Vincent Untz00011c02012-12-06 09:56:32 +0100396 elif is_suse; then
397 restart_service tgtd
398 else
399 # note for other distros: unstack.sh also uses the tgt/tgtd service
400 # name, and would need to be adjusted too
401 exit_distro_not_supported "restarting tgt"
Dean Troyer67787e62012-05-02 11:48:15 -0500402 fi
403 fi
404
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400405 screen_it c-api "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
406 screen_it c-vol "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF"
407 screen_it c-sch "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
Stephen Mulcahy67068ef2013-02-21 11:20:58 +0000408 screen_it c-bak "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-backup --config-file $CINDER_CONF"
Dean Troyer560346b2012-12-13 17:05:24 -0600409
410 # Start proxies if enabled
411 if is_service_enabled c-api && is_service_enabled tls-proxy; then
412 start_tls_proxy '*' $CINDER_SERVICE_PORT $CINDER_SERVICE_HOST $CINDER_SERVICE_PORT_INT &
413 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500414}
415
Dean Troyer699a29f2012-09-10 14:10:27 -0500416# stop_cinder() - Stop running processes
Dean Troyer67787e62012-05-02 11:48:15 -0500417function stop_cinder() {
Dean Troyer699a29f2012-09-10 14:10:27 -0500418 # Kill the cinder screen windows
Stephen Mulcahy67068ef2013-02-21 11:20:58 +0000419 for serv in c-api c-bak c-sch c-vol; do
Dean Troyer699a29f2012-09-10 14:10:27 -0500420 screen -S $SCREEN_NAME -p $serv -X kill
421 done
Dean Troyer67787e62012-05-02 11:48:15 -0500422
423 if is_service_enabled c-vol; then
Vincent Untz90dd96d2012-12-13 08:59:57 +0100424 if is_ubuntu; then
425 stop_service tgt
426 else
427 stop_service tgtd
428 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500429 fi
430}
Dean Troyer7903b792012-09-13 17:16:12 -0500431
432# Restore xtrace
433$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400434
435# Local variables:
436# mode: shell-script
437# End: