blob: ec491dda72564778ce9744dcc64f0dad15aa9b7e [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
6# - KEYSTONE_AUTH_* must be defined
7# SERVICE_{TENANT_NAME|PASSWORD} must be defined
8
9# stack.sh
10# ---------
11# install_XXX
12# configure_XXX
13# init_XXX
14# start_XXX
15# stop_XXX
16# cleanup_XXX
17
18# Print the commands being run so that we can see the command that triggers
19# an error. It is also useful for following along as the install occurs.
20set -o xtrace
21
22
23# Defaults
24# --------
25
26# set up default directories
27CINDER_DIR=$DEST/cinder
Monty Taylor9fbeedd2012-08-17 12:52:27 -040028if [ -d $CINDER_DIR/bin ] ; then
29 CINDER_BIN_DIR=$CINDER_DIR/bin
30else
31 CINDER_BIN_DIR=/usr/local/bin
32fi
Dean Troyer67787e62012-05-02 11:48:15 -050033CINDERCLIENT_DIR=$DEST/python-cinderclient
34CINDER_CONF_DIR=/etc/cinder
35CINDER_CONF=$CINDER_CONF_DIR/cinder.conf
36
37# Name of the lvm volume group to use/create for iscsi volumes
38VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes}
39VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-}
40
41# cleanup_cinder() - Remove residual data files, anything left over from previous
42# runs that a clean run would need to clean up
43function cleanup_cinder() {
44 # This function intentionally left blank
45 :
46}
47
48# configure_cinder() - Set config files, create data dirs, etc
49function configure_cinder() {
50 setup_develop $CINDER_DIR
51 setup_develop $CINDERCLIENT_DIR
52
53 if [[ ! -d $CINDER_CONF_DIR ]]; then
54 sudo mkdir -p $CINDER_CONF_DIR
55 fi
56 sudo chown `whoami` $CINDER_CONF_DIR
57
58 cp -p $CINDER_DIR/etc/cinder/policy.json $CINDER_CONF_DIR
59
John Griffith4e823ff2012-07-20 13:18:17 -060060 # Set the paths of certain binaries
61 if [[ "$os_PACKAGE" = "deb" ]]; then
62 CINDER_ROOTWRAP=/usr/local/bin/cinder-rootwrap
63 else
64 CINDER_ROOTWRAP=/usr/bin/cinder-rootwrap
65 fi
66
67 # If Cinder ships the new rootwrap filters files, deploy them
68 # (owned by root) and add a parameter to $CINDER_ROOTWRAP
69 ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP"
70 if [[ -d $CINDER_DIR/etc/cinder/rootwrap.d ]]; then
71 # Wipe any existing rootwrap.d files first
72 if [[ -d $CINDER_CONF_DIR/rootwrap.d ]]; then
73 sudo rm -rf $CINDER_CONF_DIR/rootwrap.d
74 fi
75 # Deploy filters to /etc/cinder/rootwrap.d
76 sudo mkdir -m 755 $CINDER_CONF_DIR/rootwrap.d
77 sudo cp $CINDER_DIR/etc/cinder/rootwrap.d/*.filters $CINDER_CONF_DIR/rootwrap.d
78 sudo chown -R root:root $CINDER_CONF_DIR/rootwrap.d
79 sudo chmod 644 $CINDER_CONF_DIR/rootwrap.d/*
80 # Set up rootwrap.conf, pointing to /etc/cinder/rootwrap.d
81 sudo cp $CINDER_DIR/etc/cinder/rootwrap.conf $CINDER_CONF_DIR/
82 sudo sed -e "s:^filters_path=.*$:filters_path=$CINDER_CONF_DIR/rootwrap.d:" -i $CINDER_CONF_DIR/rootwrap.conf
83 sudo chown root:root $CINDER_CONF_DIR/rootwrap.conf
84 sudo chmod 0644 $CINDER_CONF_DIR/rootwrap.conf
85 # Specify rootwrap.conf as first parameter to cinder-rootwrap
86 CINDER_ROOTWRAP="$CINDER_ROOTWRAP $CINDER_CONF_DIR/rootwrap.conf"
87 ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP *"
88 fi
89
90 TEMPFILE=`mktemp`
91 echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_CINDER_SUDOER_CMD" >$TEMPFILE
92 chmod 0440 $TEMPFILE
93 sudo chown root:root $TEMPFILE
94 sudo mv $TEMPFILE /etc/sudoers.d/cinder-rootwrap
95
Dean Troyer67787e62012-05-02 11:48:15 -050096 CINDER_API_PASTE_INI=$CINDER_CONF_DIR/api-paste.ini
97 cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
98 iniset $CINDER_API_PASTE_INI filter:authtoken auth_host $KEYSTONE_AUTH_HOST
99 iniset $CINDER_API_PASTE_INI filter:authtoken auth_port $KEYSTONE_AUTH_PORT
100 iniset $CINDER_API_PASTE_INI filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
101 iniset $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
102 iniset $CINDER_API_PASTE_INI filter:authtoken admin_user cinder
103 iniset $CINDER_API_PASTE_INI filter:authtoken admin_password $SERVICE_PASSWORD
104
105 cp $CINDER_DIR/etc/cinder/cinder.conf.sample $CINDER_CONF
106 iniset $CINDER_CONF DEFAULT auth_strategy keystone
107 iniset $CINDER_CONF DEFAULT verbose True
108 iniset $CINDER_CONF DEFAULT volume_group $VOLUME_GROUP
109 iniset $CINDER_CONF DEFAULT volume_name_template ${VOLUME_NAME_PREFIX}%s
110 iniset $CINDER_CONF DEFAULT iscsi_helper tgtadm
111 iniset $CINDER_CONF DEFAULT sql_connection $BASE_SQL_CONN/cinder?charset=utf8
Dean Troyer67787e62012-05-02 11:48:15 -0500112 iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
John Griffith4e823ff2012-07-20 13:18:17 -0600113 iniset $CINDER_CONF DEFAULT root_helper "sudo ${CINDER_ROOTWRAP}"
John Griffith43bedda2012-08-21 15:26:15 -0600114 iniset $CINDER_CONF DEFAULT osapi_volume_extension cinder.api.openstack.volume.contrib.standard_extensions
John Griffith4e823ff2012-07-20 13:18:17 -0600115
Gary Kottonf71bf192012-08-06 11:15:36 -0400116 if is_service_enabled qpid ; then
117 iniset $CINDER_CONF DEFAULT rpc_backend cinder.openstack.common.rpc.impl_qpid
ewindisch3bae7c22012-01-18 11:18:35 -0500118 elif is_service_enabled zeromq; then
119 iniset $CINDER_CONF DEFAULT rpc_backend nova.openstack.common.rpc.impl_zmq
Gary Kottonf71bf192012-08-06 11:15:36 -0400120 elif [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; then
121 iniset $CINDER_CONF DEFAULT rabbit_host $RABBIT_HOST
122 iniset $CINDER_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
123 fi
124
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000125 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
126 # Add color to logging output
127 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"
128 iniset $CINDER_CONF DEFAULT logging_default_format_string "%(asctime)s %(color)s%(levelname)s %(name)s [-%(color)s] %(instance)s%(color)s%(message)s"
129 iniset $CINDER_CONF DEFAULT logging_debug_format_suffix "from (pid=%(process)d) %(funcName)s %(pathname)s:%(lineno)d"
130 iniset $CINDER_CONF DEFAULT logging_exception_prefix "%(color)s%(asctime)s TRACE %(name)s %(instance)s"
131 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500132}
133
134# init_cinder() - Initialize database and volume group
135function init_cinder() {
136 # Force nova volumes off
137 NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/osapi_volume,//")
138
139 if is_service_enabled mysql; then
140 # (re)create cinder database
141 mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'DROP DATABASE IF EXISTS cinder;'
142 mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'CREATE DATABASE cinder;'
143
144 # (re)create cinder database
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400145 $CINDER_BIN_DIR/cinder-manage db sync
Dean Troyer67787e62012-05-02 11:48:15 -0500146 fi
147
148 if is_service_enabled c-vol; then
149 # Configure a default volume group called '`stack-volumes`' for the volume
150 # service if it does not yet exist. If you don't wish to use a file backed
151 # volume group, create your own volume group called ``stack-volumes`` before
152 # invoking ``stack.sh``.
153 #
Eoghan Glynn9cb17762012-07-15 10:22:45 +0100154 # By default, the backing file is 5G in size, and is stored in ``/opt/stack/data``.
Dean Troyer67787e62012-05-02 11:48:15 -0500155
156 if ! sudo vgs $VOLUME_GROUP; then
157 VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file}
Dean Troyer67787e62012-05-02 11:48:15 -0500158 # Only create if the file doesn't already exists
159 [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
160 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE`
161 # Only create if the loopback device doesn't contain $VOLUME_GROUP
162 if ! sudo vgs $VOLUME_GROUP; then sudo vgcreate $VOLUME_GROUP $DEV; fi
163 fi
164
Chuck Short3f603d92012-07-28 13:28:33 -0500165 mkdir -p $CINDER_DIR/volumes
166
Dean Troyer67787e62012-05-02 11:48:15 -0500167 if sudo vgs $VOLUME_GROUP; then
Vincent Untz0230aa82012-06-14 08:51:01 +0200168 if [[ "$os_PACKAGE" = "rpm" ]]; then
169 # RPM doesn't start the service
170 start_service tgtd
171 fi
172
Dean Troyer67787e62012-05-02 11:48:15 -0500173 # Remove iscsi targets
174 sudo tgtadm --op show --mode target | grep $VOLUME_NAME_PREFIX | grep Target | cut -f3 -d ' ' | sudo xargs -n1 tgt-admin --delete || true
175 # Clean out existing volumes
176 for lv in `sudo lvs --noheadings -o lv_name $VOLUME_GROUP`; do
177 # VOLUME_NAME_PREFIX prefixes the LVs we want
178 if [[ "${lv#$VOLUME_NAME_PREFIX}" != "$lv" ]]; then
179 sudo lvremove -f $VOLUME_GROUP/$lv
180 fi
181 done
182 fi
183 fi
184}
185
186# install_cinder() - Collect source and prepare
187function install_cinder() {
188 git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
189 git_clone $CINDERCLIENT_REPO $CINDERCLIENT_DIR $CINDERCLIENT_BRANCH
190}
191
Mate Lakata39caac2012-09-03 15:45:53 +0100192# apply config.d approach (e.g. Oneiric does not have this)
193function _configure_tgt_for_config_d() {
194 if [[ ! -d /etc/tgt/conf.d/ ]]; then
195 sudo mkdir /etc/tgt/conf.d
196 echo "include /etc/tgt/conf.d/*.conf" | sudo tee -a /etc/tgt/targets.conf
197 fi
198}
199
Dean Troyer67787e62012-05-02 11:48:15 -0500200# start_cinder() - Start running processes, including screen
201function start_cinder() {
202 if is_service_enabled c-vol; then
203 if [[ "$os_PACKAGE" = "deb" ]]; then
Mate Lakata39caac2012-09-03 15:45:53 +0100204 _configure_tgt_for_config_d
Chuck Short3f603d92012-07-28 13:28:33 -0500205 if [[ ! -f /etc/tgt/conf.d/cinder.conf ]]; then
206 echo "include $CINDER_DIR/volumes/*" | sudo tee /etc/tgt/conf.d/cinder.conf
207 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500208 # tgt in oneiric doesn't restart properly if tgtd isn't running
209 # do it in two steps
210 sudo stop tgt || true
211 sudo start tgt
212 else
213 # bypass redirection to systemctl during restart
214 sudo /sbin/service --skip-redirect tgtd restart
215 fi
216 fi
217
Monty Taylor9fbeedd2012-08-17 12:52:27 -0400218 screen_it c-api "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
219 screen_it c-vol "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF"
220 screen_it c-sch "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
Dean Troyer67787e62012-05-02 11:48:15 -0500221}
222
223# stop_cinder() - Stop running processes (non-screen)
224function stop_cinder() {
225 # FIXME(dtroyer): stop only the cinder screen window?
226
227 if is_service_enabled c-vol; then
228 stop_service tgt
229 fi
230}