| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 1 | # lib/swift | 
| Dean Troyer | 6d04fd7 | 2012-12-21 11:03:37 -0600 | [diff] [blame] | 2 | # Functions to control the configuration and operation of the **Swift** service | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 3 |  | 
|  | 4 | # Dependencies: | 
|  | 5 | # ``functions`` file | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 6 | # ``apache`` file | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 7 | # ``DEST``, ``SCREEN_NAME``, `SWIFT_HASH` must be defined | 
| Attila Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 8 | # ``STACK_USER`` must be defined | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 9 | # ``SWIFT_DATA_DIR`` or ``DATA_DIR`` must be defined | 
|  | 10 | # ``lib/keystone`` file | 
|  | 11 | # ``stack.sh`` calls the entry points in this order: | 
|  | 12 | # | 
|  | 13 | # install_swift | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 14 | # _config_swift_apache_wsgi | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 15 | # configure_swift | 
|  | 16 | # init_swift | 
|  | 17 | # start_swift | 
|  | 18 | # stop_swift | 
|  | 19 | # cleanup_swift | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 20 | # _cleanup_swift_apache_wsgi | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 21 |  | 
|  | 22 | # Save trace setting | 
|  | 23 | XTRACE=$(set +o | grep xtrace) | 
|  | 24 | set +o xtrace | 
|  | 25 |  | 
|  | 26 |  | 
|  | 27 | # Defaults | 
|  | 28 | # -------- | 
|  | 29 |  | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 30 | # Set up default directories | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 31 | SWIFT_DIR=$DEST/swift | 
|  | 32 | SWIFTCLIENT_DIR=$DEST/python-swiftclient | 
| Dean Troyer | 64ab774 | 2012-12-28 15:38:28 -0600 | [diff] [blame] | 33 | SWIFT_AUTH_CACHE_DIR=${SWIFT_AUTH_CACHE_DIR:-/var/cache/swift} | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 34 | SWIFT_APACHE_WSGI_DIR=${SWIFT_APACHE_WSGI_DIR:-/var/www/swift} | 
| Dean Troyer | b7490da | 2013-03-18 16:07:56 -0500 | [diff] [blame] | 35 | SWIFT3_DIR=$DEST/swift3 | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 36 |  | 
|  | 37 | # TODO: add logging to different location. | 
|  | 38 |  | 
|  | 39 | # Set ``SWIFT_DATA_DIR`` to the location of swift drives and objects. | 
|  | 40 | # Default is the common DevStack data directory. | 
|  | 41 | SWIFT_DATA_DIR=${SWIFT_DATA_DIR:-${DATA_DIR}/swift} | 
| Attila Fazekas | e602441 | 2013-09-15 18:38:48 +0200 | [diff] [blame] | 42 | SWIFT_DISK_IMAGE=${SWIFT_DATA_DIR}/drives/images/swift.img | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 43 |  | 
| Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 44 | # Set ``SWIFT_CONF_DIR`` to the location of the configuration files. | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 45 | # Default is ``/etc/swift``. | 
| Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 46 | # TODO(dtroyer): remove SWIFT_CONFIG_DIR after cutting stable/grizzly | 
|  | 47 | SWIFT_CONF_DIR=${SWIFT_CONF_DIR:-${SWIFT_CONFIG_DIR:-/etc/swift}} | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 48 |  | 
| Dean Troyer | b7490da | 2013-03-18 16:07:56 -0500 | [diff] [blame] | 49 | if is_service_enabled s-proxy && is_service_enabled swift3; then | 
|  | 50 | # If we are using swift3, we can default the s3 port to swift instead | 
|  | 51 | # of nova-objectstore | 
|  | 52 | S3_SERVICE_PORT=${S3_SERVICE_PORT:-8080} | 
|  | 53 | fi | 
|  | 54 |  | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 55 | # DevStack will create a loop-back disk formatted as XFS to store the | 
| Kevin Lyda | d66c965 | 2013-01-09 13:39:57 +0000 | [diff] [blame] | 56 | # swift data. Set ``SWIFT_LOOPBACK_DISK_SIZE`` to the disk size in | 
|  | 57 | # kilobytes. | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 58 | # Default is 1 gigabyte. | 
| Attila Fazekas | e602441 | 2013-09-15 18:38:48 +0200 | [diff] [blame] | 59 | SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=1G | 
| Attila Fazekas | 3418c1c | 2013-09-16 18:35:49 +0200 | [diff] [blame] | 60 | # if tempest enabled the default size is 4 Gigabyte. | 
|  | 61 | if is_service_enabled tempest; then | 
| Attila Fazekas | e602441 | 2013-09-15 18:38:48 +0200 | [diff] [blame] | 62 | SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=${SWIFT_LOOPBACK_DISK_SIZE:-4G} | 
| Attila Fazekas | 3418c1c | 2013-09-16 18:35:49 +0200 | [diff] [blame] | 63 | fi | 
|  | 64 |  | 
|  | 65 | SWIFT_LOOPBACK_DISK_SIZE=${SWIFT_LOOPBACK_DISK_SIZE:-$SWIFT_LOOPBACK_DISK_SIZE_DEFAULT} | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 66 |  | 
| Chmouel Boudjnah | bc3a339 | 2013-02-23 04:00:51 +0100 | [diff] [blame] | 67 | # Set ``SWIFT_EXTRAS_MIDDLEWARE`` to extras middlewares. | 
| Chmouel Boudjnah | 1fba1aa | 2013-08-02 00:40:05 +0200 | [diff] [blame] | 68 | # Default is ``staticweb, tempurl, formpost`` | 
|  | 69 | SWIFT_EXTRAS_MIDDLEWARE=${SWIFT_EXTRAS_MIDDLEWARE:-tempurl formpost staticweb} | 
| Chmouel Boudjnah | bc3a339 | 2013-02-23 04:00:51 +0100 | [diff] [blame] | 70 |  | 
| Cyril Roelandt | d988340 | 2013-09-27 15:16:51 +0000 | [diff] [blame] | 71 | # Set ``SWIFT_EXTRAS_MIDDLEWARE_LAST`` to extras middlewares that need to be at | 
|  | 72 | # the end of the pipeline. | 
|  | 73 | SWIFT_EXTRAS_MIDDLEWARE_LAST=${SWIFT_EXTRAS_MIDDLEWARE_LAST} | 
|  | 74 |  | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 75 | # The ring uses a configurable number of bits from a path’s MD5 hash as | 
|  | 76 | # a partition index that designates a device. The number of bits kept | 
|  | 77 | # from the hash is known as the partition power, and 2 to the partition | 
|  | 78 | # power indicates the partition count. Partitioning the full MD5 hash | 
|  | 79 | # ring allows other parts of the cluster to work in batches of items at | 
|  | 80 | # once which ends up either more efficient or at least less complex than | 
|  | 81 | # working with each item separately or the entire cluster all at once. | 
|  | 82 | # By default we define 9 for the partition count (which mean 512). | 
|  | 83 | SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9} | 
|  | 84 |  | 
|  | 85 | # Set ``SWIFT_REPLICAS`` to configure how many replicas are to be | 
| Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 86 | # configured for your Swift cluster. By default we are configuring | 
|  | 87 | # only one replica since this is way less CPU and memory intensive. If | 
|  | 88 | # you are planning to test swift replication you may want to set this | 
|  | 89 | # up to 3. | 
|  | 90 | SWIFT_REPLICAS=${SWIFT_REPLICAS:-1} | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 91 | SWIFT_REPLICAS_SEQ=$(seq ${SWIFT_REPLICAS}) | 
|  | 92 |  | 
|  | 93 | # Set ``OBJECT_PORT_BASE``, ``CONTAINER_PORT_BASE``, ``ACCOUNT_PORT_BASE`` | 
|  | 94 | # Port bases used in port number calclution for the service "nodes" | 
|  | 95 | # The specified port number will be used, the additinal ports calculated by | 
|  | 96 | # base_port + node_num * 10 | 
| Dean Troyer | 1151d6f | 2013-03-29 14:06:52 -0500 | [diff] [blame] | 97 | OBJECT_PORT_BASE=${OBJECT_PORT_BASE:-6013} | 
|  | 98 | CONTAINER_PORT_BASE=${CONTAINER_PORT_BASE:-6011} | 
|  | 99 | ACCOUNT_PORT_BASE=${ACCOUNT_PORT_BASE:-6012} | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 100 |  | 
| Dean Troyer | 6d04fd7 | 2012-12-21 11:03:37 -0600 | [diff] [blame] | 101 |  | 
| Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 102 | # Functions | 
|  | 103 | # --------- | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 104 |  | 
|  | 105 | # cleanup_swift() - Remove residual data files | 
|  | 106 | function cleanup_swift() { | 
| Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 107 | rm -f ${SWIFT_CONF_DIR}{*.builder,*.ring.gz,backups/*.builder,backups/*.ring.gz} | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 108 | if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then | 
|  | 109 | sudo umount ${SWIFT_DATA_DIR}/drives/sdb1 | 
|  | 110 | fi | 
| Attila Fazekas | e602441 | 2013-09-15 18:38:48 +0200 | [diff] [blame] | 111 | if [[ -e ${SWIFT_DISK_IMAGE} ]]; then | 
|  | 112 | rm ${SWIFT_DISK_IMAGE} | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 113 | fi | 
| Chmouel Boudjnah | bc3a339 | 2013-02-23 04:00:51 +0100 | [diff] [blame] | 114 | rm -rf ${SWIFT_DATA_DIR}/run/ | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 115 | if is_apache_enabled_service swift; then | 
|  | 116 | _cleanup_swift_apache_wsgi | 
|  | 117 | fi | 
|  | 118 | } | 
|  | 119 |  | 
|  | 120 | # _cleanup_swift_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file | 
|  | 121 | function _cleanup_swift_apache_wsgi() { | 
|  | 122 | sudo rm -f $SWIFT_APACHE_WSGI_DIR/*.wsgi | 
| Jamie Lennox | 5470701 | 2013-09-17 12:07:48 +1000 | [diff] [blame] | 123 | disable_apache_site proxy-server | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 124 | for node_number in ${SWIFT_REPLICAS_SEQ}; do | 
|  | 125 | for type in object container account; do | 
|  | 126 | site_name=${type}-server-${node_number} | 
| Jamie Lennox | 5470701 | 2013-09-17 12:07:48 +1000 | [diff] [blame] | 127 | disable_apache_site ${site_name} | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 128 | sudo rm -f /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site_name} | 
|  | 129 | done | 
|  | 130 | done | 
|  | 131 | } | 
|  | 132 |  | 
|  | 133 | # _config_swift_apache_wsgi() - Set WSGI config files of Swift | 
|  | 134 | function _config_swift_apache_wsgi() { | 
|  | 135 | sudo mkdir -p ${SWIFT_APACHE_WSGI_DIR} | 
|  | 136 | local apache_vhost_dir=/etc/${APACHE_NAME}/$APACHE_CONF_DIR | 
|  | 137 | local proxy_port=${SWIFT_DEFAULT_BIND_PORT:-8080} | 
|  | 138 |  | 
|  | 139 | # copy proxy vhost and wsgi file | 
|  | 140 | sudo cp ${SWIFT_DIR}/examples/apache2/proxy-server.template ${apache_vhost_dir}/proxy-server | 
|  | 141 | sudo sed -e " | 
|  | 142 | /^#/d;/^$/d; | 
|  | 143 | s/%PORT%/$proxy_port/g; | 
|  | 144 | s/%SERVICENAME%/proxy-server/g; | 
|  | 145 | s/%APACHE_NAME%/${APACHE_NAME}/g; | 
| Jamie Lennox | d582460 | 2013-09-17 11:44:37 +1000 | [diff] [blame] | 146 | s/%USER%/${STACK_USER}/g; | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 147 | " -i ${apache_vhost_dir}/proxy-server | 
| Jamie Lennox | 5470701 | 2013-09-17 12:07:48 +1000 | [diff] [blame] | 148 | enable_apache_site proxy-server | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 149 |  | 
|  | 150 | sudo cp ${SWIFT_DIR}/examples/wsgi/proxy-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi | 
|  | 151 | sudo sed -e " | 
|  | 152 | /^#/d;/^$/d; | 
|  | 153 | s/%SERVICECONF%/proxy-server.conf/g; | 
|  | 154 | " -i ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 155 |  | 
|  | 156 | # copy apache vhost file and set name and port | 
|  | 157 | for node_number in ${SWIFT_REPLICAS_SEQ}; do | 
|  | 158 | object_port=$[OBJECT_PORT_BASE + 10 * ($node_number - 1)] | 
|  | 159 | container_port=$[CONTAINER_PORT_BASE + 10 * ($node_number - 1)] | 
|  | 160 | account_port=$[ACCOUNT_PORT_BASE + 10 * ($node_number - 1)] | 
|  | 161 |  | 
|  | 162 | sudo cp ${SWIFT_DIR}/examples/apache2/object-server.template ${apache_vhost_dir}/object-server-${node_number} | 
|  | 163 | sudo sed -e " | 
|  | 164 | s/%PORT%/$object_port/g; | 
|  | 165 | s/%SERVICENAME%/object-server-${node_number}/g; | 
|  | 166 | s/%APACHE_NAME%/${APACHE_NAME}/g; | 
| Jamie Lennox | d582460 | 2013-09-17 11:44:37 +1000 | [diff] [blame] | 167 | s/%USER%/${STACK_USER}/g; | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 168 | " -i ${apache_vhost_dir}/object-server-${node_number} | 
| Jamie Lennox | 5470701 | 2013-09-17 12:07:48 +1000 | [diff] [blame] | 169 | enable_apache_site object-server-${node_number} | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 170 |  | 
|  | 171 | sudo cp ${SWIFT_DIR}/examples/wsgi/object-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi | 
|  | 172 | sudo sed -e " | 
|  | 173 | /^#/d;/^$/d; | 
|  | 174 | s/%SERVICECONF%/object-server\/${node_number}.conf/g; | 
|  | 175 | " -i ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi | 
|  | 176 |  | 
|  | 177 | sudo cp ${SWIFT_DIR}/examples/apache2/container-server.template ${apache_vhost_dir}/container-server-${node_number} | 
|  | 178 | sudo sed -e " | 
|  | 179 | /^#/d;/^$/d; | 
|  | 180 | s/%PORT%/$container_port/g; | 
|  | 181 | s/%SERVICENAME%/container-server-${node_number}/g; | 
|  | 182 | s/%APACHE_NAME%/${APACHE_NAME}/g; | 
| Jamie Lennox | d582460 | 2013-09-17 11:44:37 +1000 | [diff] [blame] | 183 | s/%USER%/${STACK_USER}/g; | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 184 | " -i ${apache_vhost_dir}/container-server-${node_number} | 
| Jamie Lennox | 5470701 | 2013-09-17 12:07:48 +1000 | [diff] [blame] | 185 | enable_apache_site container-server-${node_number} | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 186 |  | 
|  | 187 | sudo cp ${SWIFT_DIR}/examples/wsgi/container-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi | 
|  | 188 | sudo sed -e " | 
|  | 189 | /^#/d;/^$/d; | 
|  | 190 | s/%SERVICECONF%/container-server\/${node_number}.conf/g; | 
|  | 191 | " -i ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi | 
|  | 192 |  | 
|  | 193 | sudo cp ${SWIFT_DIR}/examples/apache2/account-server.template ${apache_vhost_dir}/account-server-${node_number} | 
|  | 194 | sudo sed -e " | 
|  | 195 | /^#/d;/^$/d; | 
|  | 196 | s/%PORT%/$account_port/g; | 
|  | 197 | s/%SERVICENAME%/account-server-${node_number}/g; | 
|  | 198 | s/%APACHE_NAME%/${APACHE_NAME}/g; | 
| Jamie Lennox | d582460 | 2013-09-17 11:44:37 +1000 | [diff] [blame] | 199 | s/%USER%/${STACK_USER}/g; | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 200 | " -i ${apache_vhost_dir}/account-server-${node_number} | 
| Jamie Lennox | 5470701 | 2013-09-17 12:07:48 +1000 | [diff] [blame] | 201 | enable_apache_site account-server-${node_number} | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 202 |  | 
|  | 203 | sudo cp ${SWIFT_DIR}/examples/wsgi/account-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi | 
|  | 204 | sudo sed -e " | 
|  | 205 | /^#/d;/^$/d; | 
|  | 206 | s/%SERVICECONF%/account-server\/${node_number}.conf/g; | 
|  | 207 | " -i ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 208 | done | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 209 | } | 
|  | 210 |  | 
|  | 211 | # configure_swift() - Set config files, create data dirs and loop image | 
|  | 212 | function configure_swift() { | 
| Chmouel Boudjnah | bc3a339 | 2013-02-23 04:00:51 +0100 | [diff] [blame] | 213 | local swift_pipeline=" " | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 214 | local node_number | 
|  | 215 | local swift_node_config | 
|  | 216 | local swift_log_dir | 
|  | 217 |  | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 218 | # Make sure to kill all swift processes first | 
| Chmouel Boudjnah | ad8b276 | 2013-01-10 15:40:01 +0100 | [diff] [blame] | 219 | swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 220 |  | 
| Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 221 | sudo mkdir -p ${SWIFT_CONF_DIR}/{object,container,account}-server | 
|  | 222 | sudo chown -R $USER: ${SWIFT_CONF_DIR} | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 223 |  | 
| Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 224 | if [[ "$SWIFT_CONF_DIR" != "/etc/swift" ]]; then | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 225 | # Some swift tools are hard-coded to use ``/etc/swift`` and are apparently not going to be fixed. | 
|  | 226 | # Create a symlink if the config dir is moved | 
| Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 227 | sudo ln -sf ${SWIFT_CONF_DIR} /etc/swift | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 228 | fi | 
|  | 229 |  | 
|  | 230 | # Swift use rsync to synchronize between all the different | 
|  | 231 | # partitions (which make more sense when you have a multi-node | 
|  | 232 | # setup) we configure it with our version of rsync. | 
|  | 233 | sed -e " | 
|  | 234 | s/%GROUP%/${USER_GROUP}/; | 
|  | 235 | s/%USER%/$USER/; | 
|  | 236 | s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,; | 
|  | 237 | " $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf | 
|  | 238 | # rsyncd.conf just prepared for 4 nodes | 
| Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 239 | if is_ubuntu; then | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 240 | sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync | 
|  | 241 | else | 
|  | 242 | sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync | 
|  | 243 | fi | 
|  | 244 |  | 
| Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 245 | SWIFT_CONFIG_PROXY_SERVER=${SWIFT_CONF_DIR}/proxy-server.conf | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 246 | cp ${SWIFT_DIR}/etc/proxy-server.conf-sample ${SWIFT_CONFIG_PROXY_SERVER} | 
|  | 247 |  | 
|  | 248 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user | 
|  | 249 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user ${USER} | 
|  | 250 |  | 
|  | 251 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir | 
| Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 252 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir ${SWIFT_CONF_DIR} | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 253 |  | 
|  | 254 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers | 
|  | 255 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1 | 
|  | 256 |  | 
|  | 257 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level | 
|  | 258 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level DEBUG | 
|  | 259 |  | 
|  | 260 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port | 
|  | 261 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT:-8080} | 
|  | 262 |  | 
| Cyril Roelandt | d988340 | 2013-09-27 15:16:51 +0000 | [diff] [blame] | 263 | # Configure Ceilometer | 
|  | 264 | if is_service_enabled ceilometer; then | 
|  | 265 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer use "egg:ceilometer#swift" | 
|  | 266 | SWIFT_EXTRAS_MIDDLEWARE_LAST="${SWIFT_EXTRAS_MIDDLEWARE_LAST} ceilometer" | 
|  | 267 | fi | 
|  | 268 |  | 
| Chmouel Boudjnah | 5cac378 | 2013-07-17 15:13:44 +0000 | [diff] [blame] | 269 | # By default Swift will be installed with keystone and tempauth middleware | 
|  | 270 | # and add the swift3 middleware if its configured for it. The token for | 
|  | 271 | # tempauth would be prefixed with the reseller_prefix setting TEMPAUTH_ the | 
|  | 272 | # token for keystoneauth would have the standard reseller_prefix AUTH_ | 
|  | 273 | if is_service_enabled swift3;then | 
|  | 274 | swift_pipeline=" swift3 s3token " | 
| Chmouel Boudjnah | bc3a339 | 2013-02-23 04:00:51 +0100 | [diff] [blame] | 275 | fi | 
| Chmouel Boudjnah | 5cac378 | 2013-07-17 15:13:44 +0000 | [diff] [blame] | 276 | swift_pipeline+=" authtoken keystoneauth tempauth " | 
| Chmouel Boudjnah | bc3a339 | 2013-02-23 04:00:51 +0100 | [diff] [blame] | 277 | sed -i "/^pipeline/ { s/tempauth/${swift_pipeline} ${SWIFT_EXTRAS_MIDDLEWARE}/ ;}" ${SWIFT_CONFIG_PROXY_SERVER} | 
| Cyril Roelandt | d988340 | 2013-09-27 15:16:51 +0000 | [diff] [blame] | 278 | sed -i "/^pipeline/ { s/proxy-server/${SWIFT_EXTRAS_MIDDLEWARE_LAST} proxy-server/ ; }" ${SWIFT_CONFIG_PROXY_SERVER} | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 279 |  | 
| Chmouel Boudjnah | 5cac378 | 2013-07-17 15:13:44 +0000 | [diff] [blame] | 280 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth account_autocreate | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 281 | iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server account_autocreate true | 
|  | 282 |  | 
| Chmouel Boudjnah | 5cac378 | 2013-07-17 15:13:44 +0000 | [diff] [blame] | 283 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix | 
|  | 284 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix "TEMPAUTH" | 
|  | 285 |  | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 286 | # Configure Keystone | 
|  | 287 | sed -i '/^# \[filter:authtoken\]/,/^# \[filter:keystoneauth\]$/ s/^#[ \t]*//' ${SWIFT_CONFIG_PROXY_SERVER} | 
|  | 288 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_host $KEYSTONE_AUTH_HOST | 
|  | 289 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_port $KEYSTONE_AUTH_PORT | 
|  | 290 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL | 
|  | 291 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/ | 
|  | 292 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME | 
|  | 293 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_user swift | 
|  | 294 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_password $SERVICE_PASSWORD | 
| Dean Troyer | 64ab774 | 2012-12-28 15:38:28 -0600 | [diff] [blame] | 295 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken signing_dir $SWIFT_AUTH_CACHE_DIR | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 296 |  | 
|  | 297 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use | 
|  | 298 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles | 
|  | 299 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin" | 
|  | 300 |  | 
|  | 301 | if is_service_enabled swift3; then | 
|  | 302 | cat <<EOF >>${SWIFT_CONFIG_PROXY_SERVER} | 
|  | 303 | # NOTE(chmou): s3token middleware is not updated yet to use only | 
|  | 304 | # username and password. | 
|  | 305 | [filter:s3token] | 
|  | 306 | paste.filter_factory = keystone.middleware.s3_token:filter_factory | 
|  | 307 | auth_port = ${KEYSTONE_AUTH_PORT} | 
|  | 308 | auth_host = ${KEYSTONE_AUTH_HOST} | 
|  | 309 | auth_protocol = ${KEYSTONE_AUTH_PROTOCOL} | 
|  | 310 | auth_token = ${SERVICE_TOKEN} | 
|  | 311 | admin_token = ${SERVICE_TOKEN} | 
|  | 312 |  | 
|  | 313 | [filter:swift3] | 
|  | 314 | use = egg:swift3#swift3 | 
|  | 315 | EOF | 
|  | 316 | fi | 
|  | 317 |  | 
| Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 318 | cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONF_DIR}/swift.conf | 
|  | 319 | iniset ${SWIFT_CONF_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH} | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 320 |  | 
|  | 321 | # This function generates an object/account/proxy configuration | 
|  | 322 | # emulating 4 nodes on different ports | 
|  | 323 | function generate_swift_config() { | 
|  | 324 | local swift_node_config=$1 | 
|  | 325 | local node_id=$2 | 
|  | 326 | local bind_port=$3 | 
| Chmouel Boudjnah | 35633f0 | 2013-07-16 07:35:13 +0000 | [diff] [blame] | 327 | local server_type=$4 | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 328 |  | 
|  | 329 | log_facility=$[ node_id - 1 ] | 
|  | 330 | node_path=${SWIFT_DATA_DIR}/${node_number} | 
|  | 331 |  | 
|  | 332 | iniuncomment ${swift_node_config} DEFAULT user | 
|  | 333 | iniset ${swift_node_config} DEFAULT user ${USER} | 
|  | 334 |  | 
|  | 335 | iniuncomment ${swift_node_config} DEFAULT bind_port | 
|  | 336 | iniset ${swift_node_config} DEFAULT bind_port ${bind_port} | 
|  | 337 |  | 
|  | 338 | iniuncomment ${swift_node_config} DEFAULT swift_dir | 
| Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 339 | iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONF_DIR} | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 340 |  | 
|  | 341 | iniuncomment ${swift_node_config} DEFAULT devices | 
|  | 342 | iniset ${swift_node_config} DEFAULT devices ${node_path} | 
|  | 343 |  | 
|  | 344 | iniuncomment ${swift_node_config} DEFAULT log_facility | 
|  | 345 | iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility} | 
|  | 346 |  | 
| Chmouel Boudjnah | 82c0996 | 2013-07-16 07:16:07 +0000 | [diff] [blame] | 347 | iniuncomment ${swift_node_config} DEFAULT disable_fallocate | 
|  | 348 | iniset ${swift_node_config} DEFAULT disable_fallocate true | 
|  | 349 |  | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 350 | iniuncomment ${swift_node_config} DEFAULT mount_check | 
|  | 351 | iniset ${swift_node_config} DEFAULT mount_check false | 
|  | 352 |  | 
|  | 353 | iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode | 
|  | 354 | iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes | 
|  | 355 | } | 
|  | 356 |  | 
|  | 357 | for node_number in ${SWIFT_REPLICAS_SEQ}; do | 
| Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 358 | swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 359 | cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config} | 
| Chmouel Boudjnah | 35633f0 | 2013-07-16 07:35:13 +0000 | [diff] [blame] | 360 | generate_swift_config ${swift_node_config} ${node_number} $[OBJECT_PORT_BASE + 10 * (node_number - 1)] object | 
| Chmouel Boudjnah | 8e5d2f0 | 2012-12-20 13:11:43 +0000 | [diff] [blame] | 361 | iniset ${swift_node_config} filter:recon recon_cache_path  ${SWIFT_DATA_DIR}/cache | 
|  | 362 | # Using a sed and not iniset/iniuncomment because we want to a global | 
|  | 363 | # modification and make sure it works for new sections. | 
|  | 364 | sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config} | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 365 |  | 
| Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 366 | swift_node_config=${SWIFT_CONF_DIR}/container-server/${node_number}.conf | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 367 | cp ${SWIFT_DIR}/etc/container-server.conf-sample ${swift_node_config} | 
| Chmouel Boudjnah | 35633f0 | 2013-07-16 07:35:13 +0000 | [diff] [blame] | 368 | generate_swift_config ${swift_node_config} ${node_number} $[CONTAINER_PORT_BASE + 10 * (node_number - 1)] container | 
| Attila Fazekas | 83e1095 | 2012-11-30 23:28:07 +0100 | [diff] [blame] | 369 | iniuncomment ${swift_node_config} app:container-server allow_versions | 
|  | 370 | iniset ${swift_node_config} app:container-server allow_versions  "true" | 
| Chmouel Boudjnah | 8e5d2f0 | 2012-12-20 13:11:43 +0000 | [diff] [blame] | 371 | sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config} | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 372 |  | 
| Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 373 | swift_node_config=${SWIFT_CONF_DIR}/account-server/${node_number}.conf | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 374 | cp ${SWIFT_DIR}/etc/account-server.conf-sample ${swift_node_config} | 
| Chmouel Boudjnah | 35633f0 | 2013-07-16 07:35:13 +0000 | [diff] [blame] | 375 | generate_swift_config ${swift_node_config} ${node_number} $[ACCOUNT_PORT_BASE + 10 * (node_number - 1)] account | 
| Chmouel Boudjnah | 8e5d2f0 | 2012-12-20 13:11:43 +0000 | [diff] [blame] | 376 | sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config} | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 377 | done | 
|  | 378 |  | 
| Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 379 | # Set new accounts in tempauth to match keystone tenant/user (to make testing easier) | 
|  | 380 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest1 "testing .admin" | 
|  | 381 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest2_swiftusertest2 "testing2 .admin" | 
|  | 382 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest3 "testing3 .admin" | 
|  | 383 |  | 
|  | 384 | testfile=${SWIFT_CONF_DIR}/test.conf | 
|  | 385 | cp ${SWIFT_DIR}/test/sample.conf ${testfile} | 
|  | 386 |  | 
|  | 387 | # Set accounts for functional tests | 
|  | 388 | iniset ${testfile} func_test account swifttenanttest1 | 
|  | 389 | iniset ${testfile} func_test username swiftusertest1 | 
|  | 390 | iniset ${testfile} func_test username3 swiftusertest3 | 
|  | 391 | iniset ${testfile} func_test account2 swifttenanttest2 | 
|  | 392 | iniset ${testfile} func_test username2 swiftusertest2 | 
|  | 393 |  | 
| Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 394 | if is_service_enabled key;then | 
|  | 395 | iniuncomment ${testfile} func_test auth_version | 
|  | 396 | iniset ${testfile} func_test auth_host ${KEYSTONE_SERVICE_HOST} | 
|  | 397 | iniset ${testfile} func_test auth_port ${KEYSTONE_AUTH_PORT} | 
|  | 398 | iniset ${testfile} func_test auth_prefix /v2.0/ | 
|  | 399 | fi | 
|  | 400 |  | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 401 | swift_log_dir=${SWIFT_DATA_DIR}/logs | 
|  | 402 | rm -rf ${swift_log_dir} | 
|  | 403 | mkdir -p ${swift_log_dir}/hourly | 
|  | 404 | sudo chown -R $USER:adm ${swift_log_dir} | 
|  | 405 | sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \ | 
|  | 406 | tee /etc/rsyslog.d/10-swift.conf | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 407 | if is_apache_enabled_service swift; then | 
|  | 408 | _config_swift_apache_wsgi | 
|  | 409 | fi | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 410 | } | 
|  | 411 |  | 
| Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 412 | # create_swift_disk - Create Swift backing disk | 
|  | 413 | function create_swift_disk() { | 
|  | 414 | local node_number | 
|  | 415 |  | 
|  | 416 | # First do a bit of setup by creating the directories and | 
|  | 417 | # changing the permissions so we can run it as our user. | 
|  | 418 |  | 
|  | 419 | USER_GROUP=$(id -g) | 
|  | 420 | sudo mkdir -p ${SWIFT_DATA_DIR}/{drives,cache,run,logs} | 
|  | 421 | sudo chown -R $USER:${USER_GROUP} ${SWIFT_DATA_DIR} | 
|  | 422 |  | 
|  | 423 | # Create a loopback disk and format it to XFS. | 
| Attila Fazekas | e602441 | 2013-09-15 18:38:48 +0200 | [diff] [blame] | 424 | if [[ -e ${SWIFT_DISK_IMAGE} ]]; then | 
| Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 425 | if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then | 
|  | 426 | sudo umount ${SWIFT_DATA_DIR}/drives/sdb1 | 
| Attila Fazekas | e602441 | 2013-09-15 18:38:48 +0200 | [diff] [blame] | 427 | sudo rm -f ${SWIFT_DISK_IMAGE} | 
| Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 428 | fi | 
|  | 429 | fi | 
|  | 430 |  | 
|  | 431 | mkdir -p ${SWIFT_DATA_DIR}/drives/images | 
| Attila Fazekas | e602441 | 2013-09-15 18:38:48 +0200 | [diff] [blame] | 432 | sudo touch ${SWIFT_DISK_IMAGE} | 
|  | 433 | sudo chown $USER: ${SWIFT_DISK_IMAGE} | 
| Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 434 |  | 
| Attila Fazekas | e602441 | 2013-09-15 18:38:48 +0200 | [diff] [blame] | 435 | truncate -s ${SWIFT_LOOPBACK_DISK_SIZE} ${SWIFT_DISK_IMAGE} | 
| Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 436 |  | 
|  | 437 | # Make a fresh XFS filesystem | 
| Attila Fazekas | e602441 | 2013-09-15 18:38:48 +0200 | [diff] [blame] | 438 | mkfs.xfs -f -i size=1024  ${SWIFT_DISK_IMAGE} | 
| Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 439 |  | 
|  | 440 | # Mount the disk with mount options to make it as efficient as possible | 
|  | 441 | mkdir -p ${SWIFT_DATA_DIR}/drives/sdb1 | 
|  | 442 | if ! egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then | 
|  | 443 | sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8  \ | 
| Attila Fazekas | e602441 | 2013-09-15 18:38:48 +0200 | [diff] [blame] | 444 | ${SWIFT_DISK_IMAGE} ${SWIFT_DATA_DIR}/drives/sdb1 | 
| Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 445 | fi | 
|  | 446 |  | 
|  | 447 | # Create a link to the above mount and | 
|  | 448 | # create all of the directories needed to emulate a few different servers | 
|  | 449 | for node_number in ${SWIFT_REPLICAS_SEQ}; do | 
|  | 450 | sudo ln -sf ${SWIFT_DATA_DIR}/drives/sdb1/$node_number ${SWIFT_DATA_DIR}/$node_number; | 
|  | 451 | drive=${SWIFT_DATA_DIR}/drives/sdb1/${node_number} | 
|  | 452 | node=${SWIFT_DATA_DIR}/${node_number}/node | 
|  | 453 | node_device=${node}/sdb1 | 
|  | 454 | [[ -d $node ]] && continue | 
|  | 455 | [[ -d $drive ]] && continue | 
|  | 456 | sudo install -o ${USER} -g $USER_GROUP -d $drive | 
|  | 457 | sudo install -o ${USER} -g $USER_GROUP -d $node_device | 
|  | 458 | sudo chown -R $USER: ${node} | 
|  | 459 | done | 
|  | 460 | } | 
| Chmouel Boudjnah | ba31305 | 2013-07-10 21:03:43 +0200 | [diff] [blame] | 461 | # create_swift_accounts() - Set up standard swift accounts and extra | 
|  | 462 | # one for tests we do this by attaching all words in the account name | 
|  | 463 | # since we want to make it compatible with tempauth which use | 
|  | 464 | # underscores for separators. | 
| Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 465 |  | 
|  | 466 | # Tenant               User       Roles | 
|  | 467 | # ------------------------------------------------------------------ | 
| Chmouel Boudjnah | ba31305 | 2013-07-10 21:03:43 +0200 | [diff] [blame] | 468 | # service            swift              service | 
| Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 469 | # swifttenanttest1   swiftusertest1     admin | 
|  | 470 | # swifttenanttest1   swiftusertest3     anotherrole | 
|  | 471 | # swifttenanttest2   swiftusertest2     admin | 
|  | 472 |  | 
| Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 473 | function create_swift_accounts() { | 
| Chmouel Boudjnah | ba31305 | 2013-07-10 21:03:43 +0200 | [diff] [blame] | 474 | KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql} | 
|  | 475 |  | 
|  | 476 | SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") | 
|  | 477 | ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }") | 
|  | 478 |  | 
|  | 479 | SWIFT_USER=$(keystone user-create --name=swift --pass="$SERVICE_PASSWORD" \ | 
|  | 480 | --tenant_id $SERVICE_TENANT --email=swift@example.com | grep " id " | get_field 2) | 
| Jorge Valderrama Romero | f39ee96 | 2013-09-02 17:18:40 +0200 | [diff] [blame] | 481 | keystone user-role-add --tenant-id $SERVICE_TENANT --user-id $SWIFT_USER --role-id $ADMIN_ROLE | 
| Chmouel Boudjnah | ba31305 | 2013-07-10 21:03:43 +0200 | [diff] [blame] | 482 |  | 
|  | 483 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then | 
|  | 484 | SWIFT_SERVICE=$(keystone service-create --name=swift --type="object-store" \ | 
|  | 485 | --description="Swift Service" | grep " id " | get_field 2) | 
|  | 486 | keystone endpoint-create \ | 
|  | 487 | --region RegionOne \ | 
|  | 488 | --service_id $SWIFT_SERVICE \ | 
|  | 489 | --publicurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \ | 
|  | 490 | --adminurl "http://$SERVICE_HOST:8080" \ | 
|  | 491 | --internalurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" | 
|  | 492 | fi | 
|  | 493 |  | 
| Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 494 | SWIFT_TENANT_TEST1=$(keystone tenant-create --name=swifttenanttest1 | grep " id " | get_field 2) | 
|  | 495 | SWIFT_USER_TEST1=$(keystone user-create --name=swiftusertest1 --pass=testing --email=test@example.com | grep " id " | get_field 2) | 
| Jorge Valderrama Romero | f39ee96 | 2013-09-02 17:18:40 +0200 | [diff] [blame] | 496 | keystone user-role-add --user-id $SWIFT_USER_TEST1 --role-id $ADMIN_ROLE --tenant-id $SWIFT_TENANT_TEST1 | 
| Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 497 |  | 
|  | 498 | SWIFT_USER_TEST3=$(keystone user-create --name=swiftusertest3 --pass=testing3 --email=test3@example.com | grep " id " | get_field 2) | 
| Jorge Valderrama Romero | f39ee96 | 2013-09-02 17:18:40 +0200 | [diff] [blame] | 499 | keystone user-role-add --user-id $SWIFT_USER_TEST3 --role-id $ANOTHER_ROLE --tenant-id $SWIFT_TENANT_TEST1 | 
| Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 500 |  | 
|  | 501 | SWIFT_TENANT_TEST2=$(keystone tenant-create --name=swifttenanttest2 | grep " id " | get_field 2) | 
|  | 502 | SWIFT_USER_TEST2=$(keystone user-create --name=swiftusertest2 --pass=testing2 --email=test2@example.com | grep " id " | get_field 2) | 
| Jorge Valderrama Romero | f39ee96 | 2013-09-02 17:18:40 +0200 | [diff] [blame] | 503 | keystone user-role-add --user-id $SWIFT_USER_TEST2 --role-id $ADMIN_ROLE --tenant-id $SWIFT_TENANT_TEST2 | 
| Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 504 | } | 
| Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 505 |  | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 506 | # init_swift() - Initialize rings | 
|  | 507 | function init_swift() { | 
|  | 508 | local node_number | 
|  | 509 | # Make sure to kill all swift processes first | 
| Chmouel Boudjnah | ad8b276 | 2013-01-10 15:40:01 +0100 | [diff] [blame] | 510 | swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 511 |  | 
| Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 512 | # Forcibly re-create the backing filesystem | 
|  | 513 | create_swift_disk | 
|  | 514 |  | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 515 | # This is where we create three different rings for swift with | 
|  | 516 | # different object servers binding on different ports. | 
| Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 517 | pushd ${SWIFT_CONF_DIR} >/dev/null && { | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 518 |  | 
|  | 519 | rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz | 
|  | 520 |  | 
|  | 521 | swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1 | 
|  | 522 | swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1 | 
|  | 523 | swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1 | 
|  | 524 |  | 
|  | 525 | for node_number in ${SWIFT_REPLICAS_SEQ}; do | 
|  | 526 | swift-ring-builder object.builder add z${node_number}-127.0.0.1:$[OBJECT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1 | 
|  | 527 | swift-ring-builder container.builder add z${node_number}-127.0.0.1:$[CONTAINER_PORT_BASE + 10 * (node_number - 1)]/sdb1 1 | 
|  | 528 | swift-ring-builder account.builder add z${node_number}-127.0.0.1:$[ACCOUNT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1 | 
|  | 529 | done | 
|  | 530 | swift-ring-builder object.builder rebalance | 
|  | 531 | swift-ring-builder container.builder rebalance | 
|  | 532 | swift-ring-builder account.builder rebalance | 
|  | 533 | } && popd >/dev/null | 
|  | 534 |  | 
| Dean Troyer | 64ab774 | 2012-12-28 15:38:28 -0600 | [diff] [blame] | 535 | # Create cache dir | 
|  | 536 | sudo mkdir -p $SWIFT_AUTH_CACHE_DIR | 
| Attila Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 537 | sudo chown $STACK_USER $SWIFT_AUTH_CACHE_DIR | 
| Dean Troyer | 64ab774 | 2012-12-28 15:38:28 -0600 | [diff] [blame] | 538 | rm -f $SWIFT_AUTH_CACHE_DIR/* | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 539 | } | 
|  | 540 |  | 
|  | 541 | function install_swift() { | 
|  | 542 | git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH | 
| Dean Troyer | 253a1a3 | 2013-04-01 18:23:22 -0500 | [diff] [blame] | 543 | setup_develop $SWIFT_DIR | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 544 | if is_apache_enabled_service swift; then | 
|  | 545 | install_apache_wsgi | 
|  | 546 | fi | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 547 | } | 
|  | 548 |  | 
|  | 549 | function install_swiftclient() { | 
|  | 550 | git_clone $SWIFTCLIENT_REPO $SWIFTCLIENT_DIR $SWIFTCLIENT_BRANCH | 
| Dean Troyer | 253a1a3 | 2013-04-01 18:23:22 -0500 | [diff] [blame] | 551 | setup_develop $SWIFTCLIENT_DIR | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 552 | } | 
|  | 553 |  | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 554 | # start_swift() - Start running processes, including screen | 
|  | 555 | function start_swift() { | 
|  | 556 | # (re)start rsyslog | 
|  | 557 | restart_service rsyslog | 
| Chmouel Boudjnah | 8ecbb38 | 2013-03-12 12:15:17 +0100 | [diff] [blame] | 558 | # (re)start memcached to make sure we have a clean memcache. | 
|  | 559 | restart_service memcached | 
|  | 560 |  | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 561 | # Start rsync | 
| Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 562 | if is_ubuntu; then | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 563 | sudo /etc/init.d/rsync restart || : | 
|  | 564 | else | 
|  | 565 | sudo systemctl start xinetd.service | 
|  | 566 | fi | 
|  | 567 |  | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 568 | if is_apache_enabled_service swift; then | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 569 | restart_apache_server | 
|  | 570 | swift-init --run-dir=${SWIFT_DATA_DIR}/run rest start | 
|  | 571 | screen_it s-proxy "cd $SWIFT_DIR && sudo tail -f /var/log/$APACHE_NAME/proxy-server" | 
|  | 572 | if [[ ${SWIFT_REPLICAS} == 1 ]]; then | 
|  | 573 | for type in object container account; do | 
|  | 574 | screen_it s-${type} "cd $SWIFT_DIR && sudo tail -f /var/log/$APACHE_NAME/${type}-server-1" | 
|  | 575 | done | 
|  | 576 | fi | 
|  | 577 | return 0 | 
|  | 578 | fi | 
|  | 579 |  | 
| Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 580 | # By default with only one replica we are launching the proxy, | 
|  | 581 | # container, account and object server in screen in foreground and | 
|  | 582 | # other services in background. If we have SWIFT_REPLICAS set to something | 
|  | 583 | # greater than one we first spawn all the swift services then kill the proxy | 
|  | 584 | # service so we can run it in foreground in screen.  ``swift-init ... | 
|  | 585 | # {stop|restart}`` exits with '1' if no servers are running, ignore it just | 
|  | 586 | # in case | 
| Chmouel Boudjnah | ad8b276 | 2013-01-10 15:40:01 +0100 | [diff] [blame] | 587 | swift-init --run-dir=${SWIFT_DATA_DIR}/run all restart || true | 
| Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 588 | if [[ ${SWIFT_REPLICAS} == 1 ]]; then | 
| Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 589 | todo="object container account" | 
|  | 590 | fi | 
| Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 591 | for type in proxy ${todo}; do | 
| Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 592 | swift-init --run-dir=${SWIFT_DATA_DIR}/run ${type} stop || true | 
|  | 593 | done | 
| Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 594 | screen_it s-proxy "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONF_DIR}/proxy-server.conf -v" | 
|  | 595 | if [[ ${SWIFT_REPLICAS} == 1 ]]; then | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 596 | for type in object container account; do | 
| Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 597 | screen_it s-${type} "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-${type}-server ${SWIFT_CONF_DIR}/${type}-server/1.conf -v" | 
| Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 598 | done | 
|  | 599 | fi | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 600 | } | 
|  | 601 |  | 
|  | 602 | # stop_swift() - Stop running processes (non-screen) | 
|  | 603 | function stop_swift() { | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 604 |  | 
|  | 605 | if is_apache_enabled_service swift; then | 
|  | 606 | swift-init --run-dir=${SWIFT_DATA_DIR}/run rest stop && return 0 | 
|  | 607 | fi | 
|  | 608 |  | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 609 | # screen normally killed by unstack.sh | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 610 | if type -p swift-init >/dev/null; then | 
| Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 611 | swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true | 
|  | 612 | fi | 
| Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 613 | # Dump the proxy server | 
|  | 614 | sudo pkill -f swift-proxy-server | 
| Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 615 | } | 
|  | 616 |  | 
|  | 617 | # Restore xtrace | 
|  | 618 | $XTRACE | 
| Sean Dague | 584d90e | 2013-03-29 14:34:53 -0400 | [diff] [blame] | 619 |  | 
|  | 620 | # Local variables: | 
|  | 621 | # mode: shell-script | 
|  | 622 | # End: |