blob: 5b38719a16b7262bc4696920cedb0b10e1ccb58e [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
55 CINDER_API_PASTE_INI=$CINDER_CONF_DIR/api-paste.ini
56 cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
57 iniset $CINDER_API_PASTE_INI filter:authtoken auth_host $KEYSTONE_AUTH_HOST
58 iniset $CINDER_API_PASTE_INI filter:authtoken auth_port $KEYSTONE_AUTH_PORT
59 iniset $CINDER_API_PASTE_INI filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
60 iniset $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
61 iniset $CINDER_API_PASTE_INI filter:authtoken admin_user cinder
62 iniset $CINDER_API_PASTE_INI filter:authtoken admin_password $SERVICE_PASSWORD
63
64 cp $CINDER_DIR/etc/cinder/cinder.conf.sample $CINDER_CONF
65 iniset $CINDER_CONF DEFAULT auth_strategy keystone
66 iniset $CINDER_CONF DEFAULT verbose True
67 iniset $CINDER_CONF DEFAULT volume_group $VOLUME_GROUP
68 iniset $CINDER_CONF DEFAULT volume_name_template ${VOLUME_NAME_PREFIX}%s
69 iniset $CINDER_CONF DEFAULT iscsi_helper tgtadm
70 iniset $CINDER_CONF DEFAULT sql_connection $BASE_SQL_CONN/cinder?charset=utf8
71 iniset $CINDER_CONF DEFAULT rabbit_host $RABBIT_HOST
72 iniset $CINDER_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
73 iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
74}
75
76# init_cinder() - Initialize database and volume group
77function init_cinder() {
78 # Force nova volumes off
79 NOVA_ENABLED_APIS=$(echo $NOVA_ENABLED_APIS | sed "s/osapi_volume,//")
80
81 if is_service_enabled mysql; then
82 # (re)create cinder database
83 mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'DROP DATABASE IF EXISTS cinder;'
84 mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'CREATE DATABASE cinder;'
85
86 # (re)create cinder database
87 $CINDER_DIR/bin/cinder-manage db sync
88 fi
89
90 if is_service_enabled c-vol; then
91 # Configure a default volume group called '`stack-volumes`' for the volume
92 # service if it does not yet exist. If you don't wish to use a file backed
93 # volume group, create your own volume group called ``stack-volumes`` before
94 # invoking ``stack.sh``.
95 #
96 # By default, the backing file is 2G in size, and is stored in ``/opt/stack/data``.
97
98 if ! sudo vgs $VOLUME_GROUP; then
99 VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file}
100 VOLUME_BACKING_FILE_SIZE=${VOLUME_BACKING_FILE_SIZE:-2052M}
101 # Only create if the file doesn't already exists
102 [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE
103 DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE`
104 # Only create if the loopback device doesn't contain $VOLUME_GROUP
105 if ! sudo vgs $VOLUME_GROUP; then sudo vgcreate $VOLUME_GROUP $DEV; fi
106 fi
107
108 if sudo vgs $VOLUME_GROUP; then
Vincent Untz0230aa82012-06-14 08:51:01 +0200109 if [[ "$os_PACKAGE" = "rpm" ]]; then
110 # RPM doesn't start the service
111 start_service tgtd
112 fi
113
Dean Troyer67787e62012-05-02 11:48:15 -0500114 # Remove iscsi targets
115 sudo tgtadm --op show --mode target | grep $VOLUME_NAME_PREFIX | grep Target | cut -f3 -d ' ' | sudo xargs -n1 tgt-admin --delete || true
116 # Clean out existing volumes
117 for lv in `sudo lvs --noheadings -o lv_name $VOLUME_GROUP`; do
118 # VOLUME_NAME_PREFIX prefixes the LVs we want
119 if [[ "${lv#$VOLUME_NAME_PREFIX}" != "$lv" ]]; then
120 sudo lvremove -f $VOLUME_GROUP/$lv
121 fi
122 done
123 fi
124 fi
125}
126
127# install_cinder() - Collect source and prepare
128function install_cinder() {
129 git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
130 git_clone $CINDERCLIENT_REPO $CINDERCLIENT_DIR $CINDERCLIENT_BRANCH
131}
132
133# start_cinder() - Start running processes, including screen
134function start_cinder() {
135 if is_service_enabled c-vol; then
136 if [[ "$os_PACKAGE" = "deb" ]]; then
137 # tgt in oneiric doesn't restart properly if tgtd isn't running
138 # do it in two steps
139 sudo stop tgt || true
140 sudo start tgt
141 else
142 # bypass redirection to systemctl during restart
143 sudo /sbin/service --skip-redirect tgtd restart
144 fi
145 fi
146
147 screen_it c-api "cd $CINDER_DIR && $CINDER_DIR/bin/cinder-api --config-file $CINDER_CONF"
148 screen_it c-vol "cd $CINDER_DIR && $CINDER_DIR/bin/cinder-volume --config-file $CINDER_CONF"
149 screen_it c-sch "cd $CINDER_DIR && $CINDER_DIR/bin/cinder-scheduler --config-file $CINDER_CONF"
150}
151
152# stop_cinder() - Stop running processes (non-screen)
153function stop_cinder() {
154 # FIXME(dtroyer): stop only the cinder screen window?
155
156 if is_service_enabled c-vol; then
157 stop_service tgt
158 fi
159}