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