blob: 796c107160d4102fc59d46f7c269be0205a33f77 [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
28CINDERCLIENT_DIR=$DEST/python-cinderclient
29CINDER_CONF_DIR=/etc/cinder
30CINDER_CONF=$CINDER_CONF_DIR/cinder.conf
31
32# Name of the lvm volume group to use/create for iscsi volumes
33VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes}
34VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-}
35
36# cleanup_cinder() - Remove residual data files, anything left over from previous
37# runs that a clean run would need to clean up
38function cleanup_cinder() {
39 # This function intentionally left blank
40 :
41}
42
43# configure_cinder() - Set config files, create data dirs, etc
44function configure_cinder() {
45 setup_develop $CINDER_DIR
46 setup_develop $CINDERCLIENT_DIR
47
48 if [[ ! -d $CINDER_CONF_DIR ]]; then
49 sudo mkdir -p $CINDER_CONF_DIR
50 fi
51 sudo chown `whoami` $CINDER_CONF_DIR
52
53 cp -p $CINDER_DIR/etc/cinder/policy.json $CINDER_CONF_DIR
54
John Griffith4e823ff2012-07-20 13:18:17 -060055 # Set the paths of certain binaries
56 if [[ "$os_PACKAGE" = "deb" ]]; then
57 CINDER_ROOTWRAP=/usr/local/bin/cinder-rootwrap
58 else
59 CINDER_ROOTWRAP=/usr/bin/cinder-rootwrap
60 fi
61
62 # If Cinder ships the new rootwrap filters files, deploy them
63 # (owned by root) and add a parameter to $CINDER_ROOTWRAP
64 ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP"
65 if [[ -d $CINDER_DIR/etc/cinder/rootwrap.d ]]; then
66 # Wipe any existing rootwrap.d files first
67 if [[ -d $CINDER_CONF_DIR/rootwrap.d ]]; then
68 sudo rm -rf $CINDER_CONF_DIR/rootwrap.d
69 fi
70 # Deploy filters to /etc/cinder/rootwrap.d
71 sudo mkdir -m 755 $CINDER_CONF_DIR/rootwrap.d
72 sudo cp $CINDER_DIR/etc/cinder/rootwrap.d/*.filters $CINDER_CONF_DIR/rootwrap.d
73 sudo chown -R root:root $CINDER_CONF_DIR/rootwrap.d
74 sudo chmod 644 $CINDER_CONF_DIR/rootwrap.d/*
75 # Set up rootwrap.conf, pointing to /etc/cinder/rootwrap.d
76 sudo cp $CINDER_DIR/etc/cinder/rootwrap.conf $CINDER_CONF_DIR/
77 sudo sed -e "s:^filters_path=.*$:filters_path=$CINDER_CONF_DIR/rootwrap.d:" -i $CINDER_CONF_DIR/rootwrap.conf
78 sudo chown root:root $CINDER_CONF_DIR/rootwrap.conf
79 sudo chmod 0644 $CINDER_CONF_DIR/rootwrap.conf
80 # Specify rootwrap.conf as first parameter to cinder-rootwrap
81 CINDER_ROOTWRAP="$CINDER_ROOTWRAP $CINDER_CONF_DIR/rootwrap.conf"
82 ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP *"
83 fi
84
85 TEMPFILE=`mktemp`
86 echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_CINDER_SUDOER_CMD" >$TEMPFILE
87 chmod 0440 $TEMPFILE
88 sudo chown root:root $TEMPFILE
89 sudo mv $TEMPFILE /etc/sudoers.d/cinder-rootwrap
90
Dean Troyer67787e62012-05-02 11:48:15 -050091 CINDER_API_PASTE_INI=$CINDER_CONF_DIR/api-paste.ini
92 cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
93 iniset $CINDER_API_PASTE_INI filter:authtoken auth_host $KEYSTONE_AUTH_HOST
94 iniset $CINDER_API_PASTE_INI filter:authtoken auth_port $KEYSTONE_AUTH_PORT
95 iniset $CINDER_API_PASTE_INI filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
96 iniset $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
97 iniset $CINDER_API_PASTE_INI filter:authtoken admin_user cinder
98 iniset $CINDER_API_PASTE_INI filter:authtoken admin_password $SERVICE_PASSWORD
99
100 cp $CINDER_DIR/etc/cinder/cinder.conf.sample $CINDER_CONF
101 iniset $CINDER_CONF DEFAULT auth_strategy keystone
102 iniset $CINDER_CONF DEFAULT verbose True
103 iniset $CINDER_CONF DEFAULT volume_group $VOLUME_GROUP
104 iniset $CINDER_CONF DEFAULT volume_name_template ${VOLUME_NAME_PREFIX}%s
105 iniset $CINDER_CONF DEFAULT iscsi_helper tgtadm
106 iniset $CINDER_CONF DEFAULT sql_connection $BASE_SQL_CONN/cinder?charset=utf8
Dean Troyer67787e62012-05-02 11:48:15 -0500107 iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
John Griffith4e823ff2012-07-20 13:18:17 -0600108 iniset $CINDER_CONF DEFAULT root_helper "sudo ${CINDER_ROOTWRAP}"
109
Gary Kottonf71bf192012-08-06 11:15:36 -0400110 if is_service_enabled qpid ; then
111 iniset $CINDER_CONF DEFAULT rpc_backend cinder.openstack.common.rpc.impl_qpid
112 elif [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; then
113 iniset $CINDER_CONF DEFAULT rabbit_host $RABBIT_HOST
114 iniset $CINDER_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
115 fi
116
Chmouel Boudjnah1057bff2012-08-03 11:42:51 +0000117 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
118 # Add color to logging output
119 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"
120 iniset $CINDER_CONF DEFAULT logging_default_format_string "%(asctime)s %(color)s%(levelname)s %(name)s [-%(color)s] %(instance)s%(color)s%(message)s"
121 iniset $CINDER_CONF DEFAULT logging_debug_format_suffix "from (pid=%(process)d) %(funcName)s %(pathname)s:%(lineno)d"
122 iniset $CINDER_CONF DEFAULT logging_exception_prefix "%(color)s%(asctime)s TRACE %(name)s %(instance)s"
123 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500124}
125
126# init_cinder() - Initialize database and volume group
127function init_cinder() {
128 # Force nova volumes off
129 NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/osapi_volume,//")
130
131 if is_service_enabled mysql; then
132 # (re)create cinder database
133 mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'DROP DATABASE IF EXISTS cinder;'
134 mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'CREATE DATABASE cinder;'
135
136 # (re)create cinder database
137 $CINDER_DIR/bin/cinder-manage db sync
138 fi
139
140 if is_service_enabled c-vol; then
141 # Configure a default volume group called '`stack-volumes`' for the volume
142 # service if it does not yet exist. If you don't wish to use a file backed
143 # volume group, create your own volume group called ``stack-volumes`` before
144 # invoking ``stack.sh``.
145 #
Eoghan Glynn9cb17762012-07-15 10:22:45 +0100146 # By default, the backing file is 5G in size, and is stored in ``/opt/stack/data``.
Dean Troyer67787e62012-05-02 11:48:15 -0500147
148 if ! sudo vgs $VOLUME_GROUP; then
149 VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file}
Dean Troyer67787e62012-05-02 11:48:15 -0500150 # Only create if the file doesn't already exists
151 [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
152 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE`
153 # Only create if the loopback device doesn't contain $VOLUME_GROUP
154 if ! sudo vgs $VOLUME_GROUP; then sudo vgcreate $VOLUME_GROUP $DEV; fi
155 fi
156
Chuck Short3f603d92012-07-28 13:28:33 -0500157 mkdir -p $CINDER_DIR/volumes
158
Dean Troyer67787e62012-05-02 11:48:15 -0500159 if sudo vgs $VOLUME_GROUP; then
Vincent Untz0230aa82012-06-14 08:51:01 +0200160 if [[ "$os_PACKAGE" = "rpm" ]]; then
161 # RPM doesn't start the service
162 start_service tgtd
163 fi
164
Dean Troyer67787e62012-05-02 11:48:15 -0500165 # Remove iscsi targets
166 sudo tgtadm --op show --mode target | grep $VOLUME_NAME_PREFIX | grep Target | cut -f3 -d ' ' | sudo xargs -n1 tgt-admin --delete || true
167 # Clean out existing volumes
168 for lv in `sudo lvs --noheadings -o lv_name $VOLUME_GROUP`; do
169 # VOLUME_NAME_PREFIX prefixes the LVs we want
170 if [[ "${lv#$VOLUME_NAME_PREFIX}" != "$lv" ]]; then
171 sudo lvremove -f $VOLUME_GROUP/$lv
172 fi
173 done
174 fi
175 fi
176}
177
178# install_cinder() - Collect source and prepare
179function install_cinder() {
180 git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
181 git_clone $CINDERCLIENT_REPO $CINDERCLIENT_DIR $CINDERCLIENT_BRANCH
182}
183
184# start_cinder() - Start running processes, including screen
185function start_cinder() {
186 if is_service_enabled c-vol; then
187 if [[ "$os_PACKAGE" = "deb" ]]; then
Chuck Short3f603d92012-07-28 13:28:33 -0500188 if [[ ! -f /etc/tgt/conf.d/cinder.conf ]]; then
189 echo "include $CINDER_DIR/volumes/*" | sudo tee /etc/tgt/conf.d/cinder.conf
190 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500191 # tgt in oneiric doesn't restart properly if tgtd isn't running
192 # do it in two steps
193 sudo stop tgt || true
194 sudo start tgt
195 else
196 # bypass redirection to systemctl during restart
197 sudo /sbin/service --skip-redirect tgtd restart
198 fi
199 fi
200
201 screen_it c-api "cd $CINDER_DIR && $CINDER_DIR/bin/cinder-api --config-file $CINDER_CONF"
202 screen_it c-vol "cd $CINDER_DIR && $CINDER_DIR/bin/cinder-volume --config-file $CINDER_CONF"
203 screen_it c-sch "cd $CINDER_DIR && $CINDER_DIR/bin/cinder-scheduler --config-file $CINDER_CONF"
204}
205
206# stop_cinder() - Stop running processes (non-screen)
207function stop_cinder() {
208 # FIXME(dtroyer): stop only the cinder screen window?
209
210 if is_service_enabled c-vol; then
211 stop_service tgt
212 fi
213}