blob: b3e1904de00124601dc490f81857d9958782edc9 [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
56# Name of the lvm volume groups to use/create for iscsi volumes
57# VOLUME_GROUP2 is used only if CINDER_MULTI_LVM_BACKEND = True
Dean Troyer67787e62012-05-02 11:48:15 -050058VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes}
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +010059VOLUME_GROUP2=${VOLUME_GROUP2:-stack-volumes2}
Dean Troyer67787e62012-05-02 11:48:15 -050060VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-}
61
Dean Troyer22853c12013-01-07 15:18:12 -060062# _clean_volume_group removes all cinder volumes from the specified volume group
63# _clean_volume_group $VOLUME_GROUP $VOLUME_NAME_PREFIX
64function _clean_volume_group() {
65 local vg=$1
66 local vg_prefix=$2
67 # Clean out existing volumes
68 for lv in `sudo lvs --noheadings -o lv_name $vg`; do
69 # vg_prefix prefixes the LVs we want
70 if [[ "${lv#$vg_prefix}" != "$lv" ]]; then
71 sudo lvremove -f $vg/$lv
72 fi
73 done
74}
75
Dean Troyer67787e62012-05-02 11:48:15 -050076# cleanup_cinder() - Remove residual data files, anything left over from previous
77# runs that a clean run would need to clean up
78function cleanup_cinder() {
Sean Dague252f2f52012-12-20 16:41:57 -050079 # ensure the volume group is cleared up because fails might
80 # leave dead volumes in the group
81 TARGETS=$(sudo tgtadm --op show --mode target)
82 if [ $? -ne 0 ]; then
83 # If tgt driver isn't running this won't work obviously
84 # So check the response and restart if need be
85 echo "tgtd seems to be in a bad state, restarting..."
86 if is_ubuntu; then
87 restart_service tgt
88 else
89 restart_service tgtd
90 fi
91 TARGETS=$(sudo tgtadm --op show --mode target)
92 fi
93
94 if [[ -n "$TARGETS" ]]; then
95 iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
96 for i in "${iqn_list[@]}"; do
97 echo removing iSCSI target: $i
98 sudo tgt-admin --delete $i
99 done
100 fi
101
102 if is_service_enabled cinder; then
103 sudo rm -rf $CINDER_STATE_PATH/volumes/*
104 fi
105
106 if is_ubuntu; then
107 stop_service tgt
108 else
109 stop_service tgtd
110 fi
111
Dean Troyer22853c12013-01-07 15:18:12 -0600112 # Campsite rule: leave behind a volume group at least as clean as we found it
113 _clean_volume_group $VOLUME_GROUP $VOLUME_NAME_PREFIX
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100114 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
115 _clean_volume_group $VOLUME_GROUP2 $VOLUME_NAME_PREFIX
116 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500117}
118
119# configure_cinder() - Set config files, create data dirs, etc
120function configure_cinder() {
121 setup_develop $CINDER_DIR
122 setup_develop $CINDERCLIENT_DIR
123
124 if [[ ! -d $CINDER_CONF_DIR ]]; then
125 sudo mkdir -p $CINDER_CONF_DIR
126 fi
Attila Fazekas91b8d132013-01-06 22:40:09 +0100127 sudo chown $STACK_USER $CINDER_CONF_DIR
Dean Troyer67787e62012-05-02 11:48:15 -0500128
129 cp -p $CINDER_DIR/etc/cinder/policy.json $CINDER_CONF_DIR
130
John Griffith4e823ff2012-07-20 13:18:17 -0600131 # Set the paths of certain binaries
Vincent Untz856a11e2012-11-21 16:04:12 +0100132 CINDER_ROOTWRAP=$(get_rootwrap_location cinder)
John Griffith4e823ff2012-07-20 13:18:17 -0600133
134 # If Cinder ships the new rootwrap filters files, deploy them
135 # (owned by root) and add a parameter to $CINDER_ROOTWRAP
136 ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP"
137 if [[ -d $CINDER_DIR/etc/cinder/rootwrap.d ]]; then
138 # Wipe any existing rootwrap.d files first
139 if [[ -d $CINDER_CONF_DIR/rootwrap.d ]]; then
140 sudo rm -rf $CINDER_CONF_DIR/rootwrap.d
141 fi
142 # Deploy filters to /etc/cinder/rootwrap.d
143 sudo mkdir -m 755 $CINDER_CONF_DIR/rootwrap.d
144 sudo cp $CINDER_DIR/etc/cinder/rootwrap.d/*.filters $CINDER_CONF_DIR/rootwrap.d
145 sudo chown -R root:root $CINDER_CONF_DIR/rootwrap.d
146 sudo chmod 644 $CINDER_CONF_DIR/rootwrap.d/*
147 # Set up rootwrap.conf, pointing to /etc/cinder/rootwrap.d
148 sudo cp $CINDER_DIR/etc/cinder/rootwrap.conf $CINDER_CONF_DIR/
149 sudo sed -e "s:^filters_path=.*$:filters_path=$CINDER_CONF_DIR/rootwrap.d:" -i $CINDER_CONF_DIR/rootwrap.conf
150 sudo chown root:root $CINDER_CONF_DIR/rootwrap.conf
151 sudo chmod 0644 $CINDER_CONF_DIR/rootwrap.conf
152 # Specify rootwrap.conf as first parameter to cinder-rootwrap
153 CINDER_ROOTWRAP="$CINDER_ROOTWRAP $CINDER_CONF_DIR/rootwrap.conf"
154 ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP *"
155 fi
156
157 TEMPFILE=`mktemp`
158 echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_CINDER_SUDOER_CMD" >$TEMPFILE
159 chmod 0440 $TEMPFILE
160 sudo chown root:root $TEMPFILE
161 sudo mv $TEMPFILE /etc/sudoers.d/cinder-rootwrap
162
Dean Troyer67787e62012-05-02 11:48:15 -0500163 cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
164 iniset $CINDER_API_PASTE_INI filter:authtoken auth_host $KEYSTONE_AUTH_HOST
165 iniset $CINDER_API_PASTE_INI filter:authtoken auth_port $KEYSTONE_AUTH_PORT
166 iniset $CINDER_API_PASTE_INI filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
167 iniset $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
168 iniset $CINDER_API_PASTE_INI filter:authtoken admin_user cinder
169 iniset $CINDER_API_PASTE_INI filter:authtoken admin_password $SERVICE_PASSWORD
Akihiro MOTOKI5e3deb62012-12-11 17:09:02 +0900170 iniset $CINDER_API_PASTE_INI filter:authtoken signing_dir $CINDER_AUTH_CACHE_DIR
Dean Troyerbc071bc2012-10-01 14:06:44 -0500171
Dean Troyer67787e62012-05-02 11:48:15 -0500172 cp $CINDER_DIR/etc/cinder/cinder.conf.sample $CINDER_CONF
173 iniset $CINDER_CONF DEFAULT auth_strategy keystone
John Griffith997c1032013-03-05 23:01:38 +0000174 iniset $CINDER_CONF DEFAULT debug True
Dean Troyer67787e62012-05-02 11:48:15 -0500175 iniset $CINDER_CONF DEFAULT verbose True
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100176 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
177 iniset $CINDER_CONF DEFAULT enabled_backends lvmdriver-1,lvmdriver-2
178 iniset $CINDER_CONF lvmdriver-1 volume_group $VOLUME_GROUP
179 iniset $CINDER_CONF lvmdriver-1 volume_driver cinder.volume.drivers.lvm.LVMISCSIDriver
180 iniset $CINDER_CONF lvmdriver-1 volume_backend_name LVM_iSCSI
181 iniset $CINDER_CONF lvmdriver-2 volume_group $VOLUME_GROUP2
182 iniset $CINDER_CONF lvmdriver-2 volume_driver cinder.volume.drivers.lvm.LVMISCSIDriver
183 iniset $CINDER_CONF lvmdriver-2 volume_backend_name LVM_iSCSI
184 else
185 iniset $CINDER_CONF DEFAULT volume_group $VOLUME_GROUP
186 iniset $CINDER_CONF DEFAULT volume_name_template ${VOLUME_NAME_PREFIX}%s
187 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500188 iniset $CINDER_CONF DEFAULT iscsi_helper tgtadm
Attila Fazekas7e79d912013-03-03 12:23:04 +0100189 iniset $CINDER_CONF DEFAULT sql_connection `database_connection_url cinder`
Dean Troyer67787e62012-05-02 11:48:15 -0500190 iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
Joe Gordona58382a2013-02-20 12:45:02 -0800191 iniset $CINDER_CONF DEFAULT rootwrap_config "$CINDER_CONF_DIR/rootwrap.conf"
Dan Prince9f22f072013-01-28 09:53:38 -0500192 iniset $CINDER_CONF DEFAULT osapi_volume_extension cinder.api.contrib.standard_extensions
Dean Troyer50ac7922012-09-13 14:02:01 -0500193 iniset $CINDER_CONF DEFAULT state_path $CINDER_STATE_PATH
John Griffith4e823ff2012-07-20 13:18:17 -0600194
Dean Troyer560346b2012-12-13 17:05:24 -0600195 if is_service_enabled tls-proxy; then
196 # Set the service port for a proxy to take the original
197 iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
198 fi
199
Dean Troyer4d3049e2012-11-06 20:38:14 -0600200 if [ "$SYSLOG" != "False" ]; then
201 iniset $CINDER_CONF DEFAULT use_syslog True
202 fi
203
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900204 iniset_rpc_backend cinder $CINDER_CONF DEFAULT
Gary Kottonf71bf192012-08-06 11:15:36 -0400205
James E. Blair213c4162012-11-06 09:38:36 +0100206 if [[ "$CINDER_SECURE_DELETE" == "False" ]]; then
207 iniset $CINDER_CONF DEFAULT secure_delete False
Pádraig Bradyeac93702013-01-02 16:02:54 +0000208 iniset $CINDER_CONF DEFAULT volume_clear none
James E. Blair213c4162012-11-06 09:38:36 +0100209 fi
210
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000211 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
212 # Add color to logging output
Joe Gordon07db7132013-01-30 13:07:25 -0800213 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"
214 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 +0000215 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 -0800216 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 +0000217 fi
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000218
219 if [ "$CINDER_DRIVER" == "XenAPINFS" ]; then
220 (
221 set -u
Mate Lakata0ca45f2012-12-06 17:45:49 +0000222 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.xenapi.sm.XenAPINFSDriver"
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000223 iniset $CINDER_CONF DEFAULT xenapi_connection_url "$CINDER_XENAPI_CONNECTION_URL"
224 iniset $CINDER_CONF DEFAULT xenapi_connection_username "$CINDER_XENAPI_CONNECTION_USERNAME"
225 iniset $CINDER_CONF DEFAULT xenapi_connection_password "$CINDER_XENAPI_CONNECTION_PASSWORD"
226 iniset $CINDER_CONF DEFAULT xenapi_nfs_server "$CINDER_XENAPI_NFS_SERVER"
227 iniset $CINDER_CONF DEFAULT xenapi_nfs_serverpath "$CINDER_XENAPI_NFS_SERVERPATH"
228 )
MORITA Kazutakaaf22a472013-01-17 16:16:25 +0900229 elif [ "$CINDER_DRIVER" == "sheepdog" ]; then
230 iniset $CINDER_CONF DEFAULT volume_driver "cinder.volume.drivers.sheepdog.SheepdogDriver"
Mate Lakatb2fdafe2012-11-20 15:52:21 +0000231 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500232}
233
Dean Troyer671c16e2012-12-13 16:22:38 -0600234# create_cinder_accounts() - Set up common required cinder accounts
235
236# Tenant User Roles
237# ------------------------------------------------------------------
238# service cinder admin # if enabled
239
240# Migrated from keystone_data.sh
241create_cinder_accounts() {
242
243 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
244 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
245
246 # Cinder
247 if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
248 CINDER_USER=$(keystone user-create \
249 --name=cinder \
250 --pass="$SERVICE_PASSWORD" \
251 --tenant_id $SERVICE_TENANT \
252 --email=cinder@example.com \
253 | grep " id " | get_field 2)
254 keystone user-role-add \
255 --tenant_id $SERVICE_TENANT \
256 --user_id $CINDER_USER \
257 --role_id $ADMIN_ROLE
258 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
259 CINDER_SERVICE=$(keystone service-create \
260 --name=cinder \
261 --type=volume \
262 --description="Cinder Volume Service" \
263 | grep " id " | get_field 2)
264 keystone endpoint-create \
265 --region RegionOne \
266 --service_id $CINDER_SERVICE \
Dean Troyer560346b2012-12-13 17:05:24 -0600267 --publicurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
268 --adminurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s" \
269 --internalurl "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v1/\$(tenant_id)s"
Dean Troyer671c16e2012-12-13 16:22:38 -0600270 fi
271 fi
272}
273
Dean Troyerf03bafe2013-02-12 10:58:28 -0600274# create_cinder_cache_dir() - Part of the init_cinder() process
275function create_cinder_cache_dir() {
276 # Create cache dir
277 sudo mkdir -p $CINDER_AUTH_CACHE_DIR
278 sudo chown $STACK_USER $CINDER_AUTH_CACHE_DIR
279 rm -f $CINDER_AUTH_CACHE_DIR/*
280}
281
282create_cinder_volume_group() {
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100283 # According to the CINDER_MULTI_LVM_BACKEND value, configure one or two default volumes
284 # group called ``stack-volumes`` (and ``stack-volumes2``) for the volume
285 # service if it (they) does (do) not yet exist. If you don't wish to use a
286 # file backed volume group, create your own volume group called ``stack-volumes``
287 # and ``stack-volumes2`` before invoking ``stack.sh``.
Dean Troyerf03bafe2013-02-12 10:58:28 -0600288 #
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100289 # By default, the two backing files are 5G in size, and are stored in
290 # ``/opt/stack/data``.
Dean Troyerf03bafe2013-02-12 10:58:28 -0600291
292 if ! sudo vgs $VOLUME_GROUP; then
293 VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file}
294
295 # Only create if the file doesn't already exists
296 [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
297
298 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE`
299
300 # Only create if the loopback device doesn't contain $VOLUME_GROUP
301 if ! sudo vgs $VOLUME_GROUP; then
302 sudo vgcreate $VOLUME_GROUP $DEV
303 fi
304 fi
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100305 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
306 #set up the second volume if CINDER_MULTI_LVM_BACKEND is enabled
307
308 if ! sudo vgs $VOLUME_GROUP2; then
309 VOLUME_BACKING_FILE2=${VOLUME_BACKING_FILE2:-$DATA_DIR/${VOLUME_GROUP2}-backing-file}
310
311 # Only create if the file doesn't already exists
312 [[ -f $VOLUME_BACKING_FILE2 ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE2
313
314 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE2`
315
316 # Only create if the loopback device doesn't contain $VOLUME_GROUP
317 if ! sudo vgs $VOLUME_GROUP2; then
318 sudo vgcreate $VOLUME_GROUP2 $DEV
319 fi
320 fi
321 fi
Dean Troyerf03bafe2013-02-12 10:58:28 -0600322
323 mkdir -p $CINDER_STATE_PATH/volumes
324}
325
Dean Troyer67787e62012-05-02 11:48:15 -0500326# init_cinder() - Initialize database and volume group
327function init_cinder() {
328 # Force nova volumes off
329 NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/osapi_volume,//")
330
Terry Wilson428af5a2012-11-01 16:12:39 -0400331 if is_service_enabled $DATABASE_BACKENDS; then
Dean Troyerf03bafe2013-02-12 10:58:28 -0600332 # (Re)create cinder database
Terry Wilson428af5a2012-11-01 16:12:39 -0400333 recreate_database cinder utf8
Dean Troyer67787e62012-05-02 11:48:15 -0500334
Dean Troyerf03bafe2013-02-12 10:58:28 -0600335 # Migrate cinder database
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400336 $CINDER_BIN_DIR/cinder-manage db sync
Dean Troyer67787e62012-05-02 11:48:15 -0500337 fi
338
339 if is_service_enabled c-vol; then
Dean Troyer67787e62012-05-02 11:48:15 -0500340
Dean Troyerf03bafe2013-02-12 10:58:28 -0600341 create_cinder_volume_group
Chuck Short3f603d92012-07-28 13:28:33 -0500342
Dean Troyer67787e62012-05-02 11:48:15 -0500343 if sudo vgs $VOLUME_GROUP; then
Vincent Untz00011c02012-12-06 09:56:32 +0100344 if is_fedora || is_suse; then
345 # service is not started by default
Vincent Untz0230aa82012-06-14 08:51:01 +0200346 start_service tgtd
347 fi
348
Dean Troyer67787e62012-05-02 11:48:15 -0500349 # Remove iscsi targets
350 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 -0600351 # Start with a clean volume group
352 _clean_volume_group $VOLUME_GROUP $VOLUME_NAME_PREFIX
Jérôme Gallarddda2b7a2013-02-22 17:28:10 +0100353 if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then
354 _clean_volume_group $VOLUME_GROUP2 $VOLUME_NAME_PREFIX
355 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500356 fi
357 fi
Dean Troyerbc071bc2012-10-01 14:06:44 -0500358
Dean Troyerf03bafe2013-02-12 10:58:28 -0600359 create_cinder_cache_dir
Dean Troyer67787e62012-05-02 11:48:15 -0500360}
361
362# install_cinder() - Collect source and prepare
363function install_cinder() {
364 git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
365 git_clone $CINDERCLIENT_REPO $CINDERCLIENT_DIR $CINDERCLIENT_BRANCH
366}
367
Mate Lakata39caac2012-09-03 15:45:53 +0100368# apply config.d approach (e.g. Oneiric does not have this)
369function _configure_tgt_for_config_d() {
370 if [[ ! -d /etc/tgt/conf.d/ ]]; then
Attila Fazekasb79574b2012-12-01 10:42:46 +0100371 sudo mkdir -p /etc/tgt/conf.d
Mate Lakata39caac2012-09-03 15:45:53 +0100372 echo "include /etc/tgt/conf.d/*.conf" | sudo tee -a /etc/tgt/targets.conf
373 fi
374}
375
Dean Troyer67787e62012-05-02 11:48:15 -0500376# start_cinder() - Start running processes, including screen
377function start_cinder() {
378 if is_service_enabled c-vol; then
Attila Fazekasb79574b2012-12-01 10:42:46 +0100379 _configure_tgt_for_config_d
380 if [[ ! -f /etc/tgt/conf.d/stack.conf ]]; then
381 echo "include $CINDER_STATE_PATH/volumes/*" | sudo tee /etc/tgt/conf.d/stack.conf
382 fi
Vincent Untzc18b9652012-12-04 12:36:34 +0100383 if is_ubuntu; then
Dean Troyer67787e62012-05-02 11:48:15 -0500384 # tgt in oneiric doesn't restart properly if tgtd isn't running
385 # do it in two steps
386 sudo stop tgt || true
387 sudo start tgt
Vincent Untz00011c02012-12-06 09:56:32 +0100388 elif is_fedora; then
Dean Troyer67787e62012-05-02 11:48:15 -0500389 # bypass redirection to systemctl during restart
390 sudo /sbin/service --skip-redirect tgtd restart
Vincent Untz00011c02012-12-06 09:56:32 +0100391 elif is_suse; then
392 restart_service tgtd
393 else
394 # note for other distros: unstack.sh also uses the tgt/tgtd service
395 # name, and would need to be adjusted too
396 exit_distro_not_supported "restarting tgt"
Dean Troyer67787e62012-05-02 11:48:15 -0500397 fi
398 fi
399
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400400 screen_it c-api "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
401 screen_it c-vol "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF"
402 screen_it c-sch "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
Stephen Mulcahy67068ef2013-02-21 11:20:58 +0000403 screen_it c-bak "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-backup --config-file $CINDER_CONF"
Dean Troyer560346b2012-12-13 17:05:24 -0600404
405 # Start proxies if enabled
406 if is_service_enabled c-api && is_service_enabled tls-proxy; then
407 start_tls_proxy '*' $CINDER_SERVICE_PORT $CINDER_SERVICE_HOST $CINDER_SERVICE_PORT_INT &
408 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500409}
410
Dean Troyer699a29f2012-09-10 14:10:27 -0500411# stop_cinder() - Stop running processes
Dean Troyer67787e62012-05-02 11:48:15 -0500412function stop_cinder() {
Dean Troyer699a29f2012-09-10 14:10:27 -0500413 # Kill the cinder screen windows
Stephen Mulcahy67068ef2013-02-21 11:20:58 +0000414 for serv in c-api c-bak c-sch c-vol; do
Dean Troyer699a29f2012-09-10 14:10:27 -0500415 screen -S $SCREEN_NAME -p $serv -X kill
416 done
Dean Troyer67787e62012-05-02 11:48:15 -0500417
418 if is_service_enabled c-vol; then
Vincent Untz90dd96d2012-12-13 08:59:57 +0100419 if is_ubuntu; then
420 stop_service tgt
421 else
422 stop_service tgtd
423 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500424 fi
425}
Dean Troyer7903b792012-09-13 17:16:12 -0500426
427# Restore xtrace
428$XTRACE