Sean Dague | e263c82 | 2014-12-05 14:25:28 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 3 | # lib/swift |
Dean Troyer | 6d04fd7 | 2012-12-21 11:03:37 -0600 | [diff] [blame] | 4 | # Functions to control the configuration and operation of the **Swift** service |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 5 | |
| 6 | # Dependencies: |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 7 | # |
| 8 | # - ``functions`` file |
| 9 | # - ``apache`` file |
| 10 | # - ``DEST``, ``SCREEN_NAME``, `SWIFT_HASH` must be defined |
| 11 | # - ``STACK_USER`` must be defined |
| 12 | # - ``SWIFT_DATA_DIR`` or ``DATA_DIR`` must be defined |
| 13 | # - ``lib/keystone`` file |
| 14 | # |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 15 | # ``stack.sh`` calls the entry points in this order: |
| 16 | # |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 17 | # - install_swift |
| 18 | # - _config_swift_apache_wsgi |
| 19 | # - configure_swift |
| 20 | # - init_swift |
| 21 | # - start_swift |
| 22 | # - stop_swift |
| 23 | # - cleanup_swift |
| 24 | # - _cleanup_swift_apache_wsgi |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 25 | |
| 26 | # Save trace setting |
| 27 | XTRACE=$(set +o | grep xtrace) |
| 28 | set +o xtrace |
| 29 | |
| 30 | |
| 31 | # Defaults |
| 32 | # -------- |
| 33 | |
Rob Crittenden | 18d4778 | 2014-03-19 17:47:42 -0400 | [diff] [blame] | 34 | if is_ssl_enabled_service "s-proxy" || is_service_enabled tls-proxy; then |
| 35 | SWIFT_SERVICE_PROTOCOL="https" |
| 36 | fi |
| 37 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 38 | # Set up default directories |
Sean Dague | e08ab10 | 2014-11-13 17:09:28 -0500 | [diff] [blame] | 39 | GITDIR["python-swiftclient"]=$DEST/python-swiftclient |
Sean Dague | 5cb1906 | 2014-11-01 01:37:45 +0100 | [diff] [blame] | 40 | |
| 41 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 42 | SWIFT_DIR=$DEST/swift |
Dean Troyer | 64ab774 | 2012-12-28 15:38:28 -0600 | [diff] [blame] | 43 | SWIFT_AUTH_CACHE_DIR=${SWIFT_AUTH_CACHE_DIR:-/var/cache/swift} |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 44 | SWIFT_APACHE_WSGI_DIR=${SWIFT_APACHE_WSGI_DIR:-/var/www/swift} |
Dean Troyer | b7490da | 2013-03-18 16:07:56 -0500 | [diff] [blame] | 45 | SWIFT3_DIR=$DEST/swift3 |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 46 | |
Rob Crittenden | 18d4778 | 2014-03-19 17:47:42 -0400 | [diff] [blame] | 47 | SWIFT_SERVICE_PROTOCOL=${SWIFT_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL} |
| 48 | SWIFT_DEFAULT_BIND_PORT_INT=${SWIFT_DEFAULT_BIND_PORT_INT:-8081} |
| 49 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 50 | # TODO: add logging to different location. |
| 51 | |
| 52 | # Set ``SWIFT_DATA_DIR`` to the location of swift drives and objects. |
| 53 | # Default is the common DevStack data directory. |
| 54 | SWIFT_DATA_DIR=${SWIFT_DATA_DIR:-${DATA_DIR}/swift} |
Attila Fazekas | e602441 | 2013-09-15 18:38:48 +0200 | [diff] [blame] | 55 | SWIFT_DISK_IMAGE=${SWIFT_DATA_DIR}/drives/images/swift.img |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 56 | |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 57 | # Set ``SWIFT_CONF_DIR`` to the location of the configuration files. |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 58 | # Default is ``/etc/swift``. |
JordanP | a6dfe81 | 2014-11-20 18:06:23 +0100 | [diff] [blame] | 59 | SWIFT_CONF_DIR=${SWIFT_CONF_DIR:-/etc/swift} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 60 | |
Dean Troyer | b7490da | 2013-03-18 16:07:56 -0500 | [diff] [blame] | 61 | if is_service_enabled s-proxy && is_service_enabled swift3; then |
| 62 | # If we are using swift3, we can default the s3 port to swift instead |
| 63 | # of nova-objectstore |
| 64 | S3_SERVICE_PORT=${S3_SERVICE_PORT:-8080} |
| 65 | fi |
| 66 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 67 | # 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] | 68 | # swift data. Set ``SWIFT_LOOPBACK_DISK_SIZE`` to the disk size in |
| 69 | # kilobytes. |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 70 | # Default is 1 gigabyte. |
Attila Fazekas | e602441 | 2013-09-15 18:38:48 +0200 | [diff] [blame] | 71 | SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=1G |
Joe Gordon | 66c5424 | 2013-11-12 16:24:14 -0800 | [diff] [blame] | 72 | # if tempest enabled the default size is 6 Gigabyte. |
Attila Fazekas | 3418c1c | 2013-09-16 18:35:49 +0200 | [diff] [blame] | 73 | if is_service_enabled tempest; then |
Joe Gordon | 66c5424 | 2013-11-12 16:24:14 -0800 | [diff] [blame] | 74 | SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=${SWIFT_LOOPBACK_DISK_SIZE:-6G} |
Attila Fazekas | 3418c1c | 2013-09-16 18:35:49 +0200 | [diff] [blame] | 75 | fi |
| 76 | |
| 77 | 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] | 78 | |
Chmouel Boudjnah | bc3a339 | 2013-02-23 04:00:51 +0100 | [diff] [blame] | 79 | # Set ``SWIFT_EXTRAS_MIDDLEWARE`` to extras middlewares. |
Samuel Merritt | f19ccb6 | 2014-03-08 07:54:05 -0800 | [diff] [blame] | 80 | # Default is ``staticweb, formpost`` |
| 81 | SWIFT_EXTRAS_MIDDLEWARE=${SWIFT_EXTRAS_MIDDLEWARE:-formpost staticweb} |
Chmouel Boudjnah | bc3a339 | 2013-02-23 04:00:51 +0100 | [diff] [blame] | 82 | |
Cyril Roelandt | d988340 | 2013-09-27 15:16:51 +0000 | [diff] [blame] | 83 | # Set ``SWIFT_EXTRAS_MIDDLEWARE_LAST`` to extras middlewares that need to be at |
| 84 | # the end of the pipeline. |
Sean Dague | 5375329 | 2014-12-04 19:38:15 -0500 | [diff] [blame^] | 85 | SWIFT_EXTRAS_MIDDLEWARE_LAST=${SWIFT_EXTRAS_MIDDLEWARE_LAST:-} |
Cyril Roelandt | d988340 | 2013-09-27 15:16:51 +0000 | [diff] [blame] | 86 | |
Joe H. Rahme | 1ce2ffd | 2013-10-22 15:19:09 +0200 | [diff] [blame] | 87 | # Set ``SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH`` to extras middlewares that need to be at |
| 88 | # the beginning of the pipeline, before authentication middlewares. |
| 89 | SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH=${SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH:-crossdomain} |
| 90 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 91 | # The ring uses a configurable number of bits from a path’s MD5 hash as |
| 92 | # a partition index that designates a device. The number of bits kept |
| 93 | # from the hash is known as the partition power, and 2 to the partition |
| 94 | # power indicates the partition count. Partitioning the full MD5 hash |
| 95 | # ring allows other parts of the cluster to work in batches of items at |
| 96 | # once which ends up either more efficient or at least less complex than |
| 97 | # working with each item separately or the entire cluster all at once. |
| 98 | # By default we define 9 for the partition count (which mean 512). |
| 99 | SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9} |
| 100 | |
| 101 | # Set ``SWIFT_REPLICAS`` to configure how many replicas are to be |
Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 102 | # configured for your Swift cluster. By default we are configuring |
| 103 | # only one replica since this is way less CPU and memory intensive. If |
| 104 | # you are planning to test swift replication you may want to set this |
| 105 | # up to 3. |
| 106 | SWIFT_REPLICAS=${SWIFT_REPLICAS:-1} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 107 | SWIFT_REPLICAS_SEQ=$(seq ${SWIFT_REPLICAS}) |
| 108 | |
Peter Portante | cee4b3b | 2013-11-20 14:33:16 -0500 | [diff] [blame] | 109 | # Set ``SWIFT_LOG_TOKEN_LENGTH`` to configure how many characters of an auth |
| 110 | # token should be placed in the logs. When keystone is used with PKI tokens, |
| 111 | # the token values can be huge, seemingly larger the 2K, at the least. We |
| 112 | # restrict it here to a default of 12 characters, which should be enough to |
| 113 | # trace through the logs when looking for its use. |
| 114 | SWIFT_LOG_TOKEN_LENGTH=${SWIFT_LOG_TOKEN_LENGTH:-12} |
| 115 | |
Julien Vey | 63024d9 | 2014-05-06 15:10:07 +0200 | [diff] [blame] | 116 | # Set ``SWIFT_MAX_HEADER_SIZE`` to configure the maximun length of headers in |
| 117 | # Swift API |
| 118 | SWIFT_MAX_HEADER_SIZE=${SWIFT_MAX_HEADER_SIZE:-16384} |
| 119 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 120 | # Set ``OBJECT_PORT_BASE``, ``CONTAINER_PORT_BASE``, ``ACCOUNT_PORT_BASE`` |
| 121 | # Port bases used in port number calclution for the service "nodes" |
| 122 | # The specified port number will be used, the additinal ports calculated by |
| 123 | # base_port + node_num * 10 |
Dean Troyer | 1151d6f | 2013-03-29 14:06:52 -0500 | [diff] [blame] | 124 | OBJECT_PORT_BASE=${OBJECT_PORT_BASE:-6013} |
| 125 | CONTAINER_PORT_BASE=${CONTAINER_PORT_BASE:-6011} |
| 126 | ACCOUNT_PORT_BASE=${ACCOUNT_PORT_BASE:-6012} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 127 | |
Jim Rollenhagen | abbb0e9 | 2014-08-05 18:01:48 +0000 | [diff] [blame] | 128 | # Enable tempurl feature |
| 129 | SWIFT_ENABLE_TEMPURLS=${SWIFT_ENABLE_TEMPURLS:-False} |
Sean Dague | 5375329 | 2014-12-04 19:38:15 -0500 | [diff] [blame^] | 130 | SWIFT_TEMPURL_KEY=${SWIFT_TEMPURL_KEY:-} |
Jim Rollenhagen | abbb0e9 | 2014-08-05 18:01:48 +0000 | [diff] [blame] | 131 | |
Dean Troyer | 4237f59 | 2014-01-29 16:22:11 -0600 | [diff] [blame] | 132 | # Tell Tempest this project is present |
| 133 | TEMPEST_SERVICES+=,swift |
| 134 | |
JordanP | fc0ff92 | 2014-12-17 12:39:36 +0100 | [diff] [blame] | 135 | # Toggle for deploying Swift under HTTPD + mod_wsgi |
Morgan Fainberg | 46455a3 | 2014-06-20 10:37:18 -0700 | [diff] [blame] | 136 | SWIFT_USE_MOD_WSGI=${SWIFT_USE_MOD_WSGI:-False} |
Dean Troyer | 6d04fd7 | 2012-12-21 11:03:37 -0600 | [diff] [blame] | 137 | |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 138 | # Functions |
| 139 | # --------- |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 140 | |
Dean Troyer | e4fa721 | 2014-01-15 15:04:49 -0600 | [diff] [blame] | 141 | # Test if any Swift services are enabled |
| 142 | # is_swift_enabled |
| 143 | function is_swift_enabled { |
| 144 | [[ ,${ENABLED_SERVICES} =~ ,"s-" ]] && return 0 |
| 145 | return 1 |
| 146 | } |
| 147 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 148 | # cleanup_swift() - Remove residual data files |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 149 | function cleanup_swift { |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 150 | rm -f ${SWIFT_CONF_DIR}{*.builder,*.ring.gz,backups/*.builder,backups/*.ring.gz} |
| 151 | if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then |
| 152 | sudo umount ${SWIFT_DATA_DIR}/drives/sdb1 |
| 153 | fi |
| 154 | if [[ -e ${SWIFT_DISK_IMAGE} ]]; then |
| 155 | rm ${SWIFT_DISK_IMAGE} |
| 156 | fi |
| 157 | rm -rf ${SWIFT_DATA_DIR}/run/ |
Morgan Fainberg | 46455a3 | 2014-06-20 10:37:18 -0700 | [diff] [blame] | 158 | if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 159 | _cleanup_swift_apache_wsgi |
| 160 | fi |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | # _cleanup_swift_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 164 | function _cleanup_swift_apache_wsgi { |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 165 | sudo rm -f $SWIFT_APACHE_WSGI_DIR/*.wsgi |
Jamie Lennox | 5470701 | 2013-09-17 12:07:48 +1000 | [diff] [blame] | 166 | disable_apache_site proxy-server |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 167 | local node_number type |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 168 | for node_number in ${SWIFT_REPLICAS_SEQ}; do |
| 169 | for type in object container account; do |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 170 | local site_name=${type}-server-${node_number} |
Jamie Lennox | 5470701 | 2013-09-17 12:07:48 +1000 | [diff] [blame] | 171 | disable_apache_site ${site_name} |
Gabriel Assis Bezerra | a688bc6 | 2014-05-27 20:58:22 +0000 | [diff] [blame] | 172 | sudo rm -f $(apache_site_config_for ${site_name}) |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 173 | done |
| 174 | done |
| 175 | } |
| 176 | |
| 177 | # _config_swift_apache_wsgi() - Set WSGI config files of Swift |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 178 | function _config_swift_apache_wsgi { |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 179 | sudo mkdir -p ${SWIFT_APACHE_WSGI_DIR} |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 180 | local proxy_port=${SWIFT_DEFAULT_BIND_PORT:-8080} |
| 181 | |
| 182 | # copy proxy vhost and wsgi file |
Gabriel Assis Bezerra | a688bc6 | 2014-05-27 20:58:22 +0000 | [diff] [blame] | 183 | sudo cp ${SWIFT_DIR}/examples/apache2/proxy-server.template $(apache_site_config_for proxy-server) |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 184 | sudo sed -e " |
| 185 | /^#/d;/^$/d; |
| 186 | s/%PORT%/$proxy_port/g; |
| 187 | s/%SERVICENAME%/proxy-server/g; |
| 188 | s/%APACHE_NAME%/${APACHE_NAME}/g; |
Jamie Lennox | d582460 | 2013-09-17 11:44:37 +1000 | [diff] [blame] | 189 | s/%USER%/${STACK_USER}/g; |
Gabriel Assis Bezerra | a688bc6 | 2014-05-27 20:58:22 +0000 | [diff] [blame] | 190 | " -i $(apache_site_config_for proxy-server) |
Jamie Lennox | 5470701 | 2013-09-17 12:07:48 +1000 | [diff] [blame] | 191 | enable_apache_site proxy-server |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 192 | |
| 193 | sudo cp ${SWIFT_DIR}/examples/wsgi/proxy-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi |
| 194 | sudo sed -e " |
| 195 | /^#/d;/^$/d; |
| 196 | s/%SERVICECONF%/proxy-server.conf/g; |
| 197 | " -i ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 198 | |
| 199 | # copy apache vhost file and set name and port |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 200 | local node_number |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 201 | for node_number in ${SWIFT_REPLICAS_SEQ}; do |
Ian Wienand | 761c456 | 2014-10-21 11:41:37 +1100 | [diff] [blame] | 202 | local object_port=$(( OBJECT_PORT_BASE + 10 * (node_number - 1) )) |
| 203 | local container_port=$(( CONTAINER_PORT_BASE + 10 * (node_number - 1) )) |
| 204 | local account_port=$(( ACCOUNT_PORT_BASE + 10 * (node_number - 1) )) |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 205 | |
Gabriel Assis Bezerra | a688bc6 | 2014-05-27 20:58:22 +0000 | [diff] [blame] | 206 | sudo cp ${SWIFT_DIR}/examples/apache2/object-server.template $(apache_site_config_for object-server-${node_number}) |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 207 | sudo sed -e " |
| 208 | s/%PORT%/$object_port/g; |
| 209 | s/%SERVICENAME%/object-server-${node_number}/g; |
| 210 | s/%APACHE_NAME%/${APACHE_NAME}/g; |
Jamie Lennox | d582460 | 2013-09-17 11:44:37 +1000 | [diff] [blame] | 211 | s/%USER%/${STACK_USER}/g; |
Gabriel Assis Bezerra | a688bc6 | 2014-05-27 20:58:22 +0000 | [diff] [blame] | 212 | " -i $(apache_site_config_for object-server-${node_number}) |
Jamie Lennox | 5470701 | 2013-09-17 12:07:48 +1000 | [diff] [blame] | 213 | enable_apache_site object-server-${node_number} |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 214 | |
| 215 | sudo cp ${SWIFT_DIR}/examples/wsgi/object-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi |
| 216 | sudo sed -e " |
| 217 | /^#/d;/^$/d; |
| 218 | s/%SERVICECONF%/object-server\/${node_number}.conf/g; |
| 219 | " -i ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi |
| 220 | |
Gabriel Assis Bezerra | a688bc6 | 2014-05-27 20:58:22 +0000 | [diff] [blame] | 221 | sudo cp ${SWIFT_DIR}/examples/apache2/container-server.template $(apache_site_config_for container-server-${node_number}) |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 222 | sudo sed -e " |
| 223 | /^#/d;/^$/d; |
| 224 | s/%PORT%/$container_port/g; |
| 225 | s/%SERVICENAME%/container-server-${node_number}/g; |
| 226 | s/%APACHE_NAME%/${APACHE_NAME}/g; |
Jamie Lennox | d582460 | 2013-09-17 11:44:37 +1000 | [diff] [blame] | 227 | s/%USER%/${STACK_USER}/g; |
Gabriel Assis Bezerra | a688bc6 | 2014-05-27 20:58:22 +0000 | [diff] [blame] | 228 | " -i $(apache_site_config_for container-server-${node_number}) |
Jamie Lennox | 5470701 | 2013-09-17 12:07:48 +1000 | [diff] [blame] | 229 | enable_apache_site container-server-${node_number} |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 230 | |
| 231 | sudo cp ${SWIFT_DIR}/examples/wsgi/container-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi |
| 232 | sudo sed -e " |
| 233 | /^#/d;/^$/d; |
| 234 | s/%SERVICECONF%/container-server\/${node_number}.conf/g; |
| 235 | " -i ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi |
| 236 | |
Gabriel Assis Bezerra | a688bc6 | 2014-05-27 20:58:22 +0000 | [diff] [blame] | 237 | sudo cp ${SWIFT_DIR}/examples/apache2/account-server.template $(apache_site_config_for account-server-${node_number}) |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 238 | sudo sed -e " |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 239 | /^#/d;/^$/d; |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 240 | s/%PORT%/$account_port/g; |
| 241 | s/%SERVICENAME%/account-server-${node_number}/g; |
| 242 | s/%APACHE_NAME%/${APACHE_NAME}/g; |
Jamie Lennox | d582460 | 2013-09-17 11:44:37 +1000 | [diff] [blame] | 243 | s/%USER%/${STACK_USER}/g; |
Gabriel Assis Bezerra | a688bc6 | 2014-05-27 20:58:22 +0000 | [diff] [blame] | 244 | " -i $(apache_site_config_for account-server-${node_number}) |
Jamie Lennox | 5470701 | 2013-09-17 12:07:48 +1000 | [diff] [blame] | 245 | enable_apache_site account-server-${node_number} |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 246 | |
| 247 | sudo cp ${SWIFT_DIR}/examples/wsgi/account-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi |
| 248 | sudo sed -e " |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 249 | /^#/d;/^$/d; |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 250 | s/%SERVICECONF%/account-server\/${node_number}.conf/g; |
| 251 | " -i ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 252 | done |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 253 | } |
| 254 | |
Ian Wienand | f8e86bb | 2014-02-21 15:16:31 +1100 | [diff] [blame] | 255 | # This function generates an object/container/account configuration |
| 256 | # emulating 4 nodes on different ports |
Chmouel Boudjnah | 6c585d7 | 2014-10-04 08:14:30 +0200 | [diff] [blame] | 257 | function generate_swift_config_services { |
Ian Wienand | f8e86bb | 2014-02-21 15:16:31 +1100 | [diff] [blame] | 258 | local swift_node_config=$1 |
| 259 | local node_id=$2 |
| 260 | local bind_port=$3 |
| 261 | local server_type=$4 |
| 262 | |
Ian Wienand | 761c456 | 2014-10-21 11:41:37 +1100 | [diff] [blame] | 263 | log_facility=$(( node_id - 1 )) |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 264 | local node_path=${SWIFT_DATA_DIR}/${node_number} |
Ian Wienand | f8e86bb | 2014-02-21 15:16:31 +1100 | [diff] [blame] | 265 | |
| 266 | iniuncomment ${swift_node_config} DEFAULT user |
| 267 | iniset ${swift_node_config} DEFAULT user ${STACK_USER} |
| 268 | |
| 269 | iniuncomment ${swift_node_config} DEFAULT bind_port |
| 270 | iniset ${swift_node_config} DEFAULT bind_port ${bind_port} |
| 271 | |
| 272 | iniuncomment ${swift_node_config} DEFAULT swift_dir |
| 273 | iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONF_DIR} |
| 274 | |
| 275 | iniuncomment ${swift_node_config} DEFAULT devices |
| 276 | iniset ${swift_node_config} DEFAULT devices ${node_path} |
| 277 | |
| 278 | iniuncomment ${swift_node_config} DEFAULT log_facility |
| 279 | iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility} |
| 280 | |
| 281 | iniuncomment ${swift_node_config} DEFAULT workers |
Chmouel Boudjnah | 55dc2c2 | 2014-09-12 09:34:20 +0200 | [diff] [blame] | 282 | iniset ${swift_node_config} DEFAULT workers ${API_WORKERS:-1} |
Ian Wienand | f8e86bb | 2014-02-21 15:16:31 +1100 | [diff] [blame] | 283 | |
| 284 | iniuncomment ${swift_node_config} DEFAULT disable_fallocate |
| 285 | iniset ${swift_node_config} DEFAULT disable_fallocate true |
| 286 | |
| 287 | iniuncomment ${swift_node_config} DEFAULT mount_check |
| 288 | iniset ${swift_node_config} DEFAULT mount_check false |
| 289 | |
| 290 | iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode |
| 291 | iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes |
Chmouel Boudjnah | 6c585d7 | 2014-10-04 08:14:30 +0200 | [diff] [blame] | 292 | |
| 293 | # Using a sed and not iniset/iniuncomment because we want to a global |
| 294 | # modification and make sure it works for new sections. |
| 295 | sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config} |
Ian Wienand | f8e86bb | 2014-02-21 15:16:31 +1100 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 299 | # configure_swift() - Set config files, create data dirs and loop image |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 300 | function configure_swift { |
Joe H. Rahme | 1ce2ffd | 2013-10-22 15:19:09 +0200 | [diff] [blame] | 301 | local swift_pipeline="${SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH}" |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 302 | local node_number |
| 303 | local swift_node_config |
| 304 | local swift_log_dir |
| 305 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 306 | # Make sure to kill all swift processes first |
Chmouel Boudjnah | ad8b276 | 2013-01-10 15:40:01 +0100 | [diff] [blame] | 307 | swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 308 | |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 309 | sudo mkdir -p ${SWIFT_CONF_DIR}/{object,container,account}-server |
Stephan Renatus | e578eff | 2013-11-19 13:31:04 +0100 | [diff] [blame] | 310 | sudo chown -R ${STACK_USER}: ${SWIFT_CONF_DIR} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 311 | |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 312 | if [[ "$SWIFT_CONF_DIR" != "/etc/swift" ]]; then |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 313 | # Some swift tools are hard-coded to use ``/etc/swift`` and are apparently not going to be fixed. |
| 314 | # Create a symlink if the config dir is moved |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 315 | sudo ln -sf ${SWIFT_CONF_DIR} /etc/swift |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 316 | fi |
| 317 | |
| 318 | # Swift use rsync to synchronize between all the different |
| 319 | # partitions (which make more sense when you have a multi-node |
| 320 | # setup) we configure it with our version of rsync. |
| 321 | sed -e " |
| 322 | s/%GROUP%/${USER_GROUP}/; |
Stephan Renatus | e578eff | 2013-11-19 13:31:04 +0100 | [diff] [blame] | 323 | s/%USER%/${STACK_USER}/; |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 324 | s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,; |
| 325 | " $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf |
| 326 | # rsyncd.conf just prepared for 4 nodes |
Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 327 | if is_ubuntu; then |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 328 | sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync |
Attila Fazekas | 0e57b96 | 2014-02-28 09:09:52 +0100 | [diff] [blame] | 329 | elif [ -e /etc/xinetd.d/rsync ]; then |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 330 | sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync |
| 331 | fi |
| 332 | |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 333 | SWIFT_CONFIG_PROXY_SERVER=${SWIFT_CONF_DIR}/proxy-server.conf |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 334 | cp ${SWIFT_DIR}/etc/proxy-server.conf-sample ${SWIFT_CONFIG_PROXY_SERVER} |
| 335 | |
Daisuke Morita | d03915f | 2014-10-08 06:52:21 +0000 | [diff] [blame] | 336 | # To run container sync feature introduced in Swift ver 1.12.0, |
| 337 | # container sync "realm" is added in container-sync-realms.conf |
| 338 | local csyncfile=${SWIFT_CONF_DIR}/container-sync-realms.conf |
| 339 | cp ${SWIFT_DIR}/etc/container-sync-realms.conf-sample ${csyncfile} |
| 340 | iniset ${csyncfile} realm1 key realm1key |
| 341 | iniset ${csyncfile} realm1 cluster_name1 "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:8080/v1/" |
Chmouel Boudjnah | f2c1a71 | 2014-01-29 21:38:14 +0000 | [diff] [blame] | 342 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 343 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user |
Stephan Renatus | e578eff | 2013-11-19 13:31:04 +0100 | [diff] [blame] | 344 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user ${STACK_USER} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 345 | |
| 346 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 347 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir ${SWIFT_CONF_DIR} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 348 | |
| 349 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers |
| 350 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1 |
| 351 | |
| 352 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level |
| 353 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level DEBUG |
| 354 | |
| 355 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port |
Rob Crittenden | 18d4778 | 2014-03-19 17:47:42 -0400 | [diff] [blame] | 356 | if is_service_enabled tls-proxy; then |
| 357 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT_INT} |
| 358 | else |
| 359 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT:-8080} |
| 360 | fi |
| 361 | |
| 362 | if is_ssl_enabled_service s-proxy; then |
| 363 | ensure_certificates SWIFT |
| 364 | |
| 365 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT cert_file "$SWIFT_SSL_CERT" |
| 366 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT key_file "$SWIFT_SSL_KEY" |
| 367 | fi |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 368 | |
Joe Gordon | d254da5 | 2013-11-19 21:06:29 -0800 | [diff] [blame] | 369 | # Devstack is commonly run in a small slow environment, so bump the |
| 370 | # timeouts up. |
| 371 | # node_timeout is how long between read operations a node takes to |
| 372 | # respond to the proxy server |
| 373 | # conn_timeout is all about how long it takes a connect() system call to |
| 374 | # return |
| 375 | iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server node_timeout 120 |
| 376 | iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server conn_timeout 20 |
| 377 | |
Dina Belova | eedfdee | 2014-06-24 16:52:46 +0400 | [diff] [blame] | 378 | # Configure Ceilometer |
| 379 | if is_service_enabled ceilometer; then |
| 380 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer "set log_level" "WARN" |
| 381 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer use "egg:ceilometer#swift" |
| 382 | SWIFT_EXTRAS_MIDDLEWARE_LAST="${SWIFT_EXTRAS_MIDDLEWARE_LAST} ceilometer" |
| 383 | fi |
Cyril Roelandt | d988340 | 2013-09-27 15:16:51 +0000 | [diff] [blame] | 384 | |
Peter Portante | cee4b3b | 2013-11-20 14:33:16 -0500 | [diff] [blame] | 385 | # Restrict the length of auth tokens in the swift proxy-server logs. |
| 386 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:proxy-logging reveal_sensitive_prefix ${SWIFT_LOG_TOKEN_LENGTH} |
| 387 | |
Chmouel Boudjnah | 5cac378 | 2013-07-17 15:13:44 +0000 | [diff] [blame] | 388 | # By default Swift will be installed with keystone and tempauth middleware |
| 389 | # and add the swift3 middleware if its configured for it. The token for |
Adam Spiers | cb96159 | 2013-10-05 12:11:07 +0100 | [diff] [blame] | 390 | # tempauth would be prefixed with the reseller_prefix setting `TEMPAUTH_` the |
| 391 | # token for keystoneauth would have the standard reseller_prefix `AUTH_` |
Chmouel Boudjnah | 5cac378 | 2013-07-17 15:13:44 +0000 | [diff] [blame] | 392 | if is_service_enabled swift3;then |
Joe H. Rahme | 1ce2ffd | 2013-10-22 15:19:09 +0200 | [diff] [blame] | 393 | swift_pipeline+=" swift3 s3token " |
Chmouel Boudjnah | bc3a339 | 2013-02-23 04:00:51 +0100 | [diff] [blame] | 394 | fi |
Chmouel Boudjnah | 254fd55 | 2014-06-30 12:22:59 +0000 | [diff] [blame] | 395 | |
| 396 | if is_service_enabled key;then |
| 397 | swift_pipeline+=" authtoken keystoneauth" |
| 398 | fi |
| 399 | swift_pipeline+=" tempauth " |
| 400 | |
Chmouel Boudjnah | bc3a339 | 2013-02-23 04:00:51 +0100 | [diff] [blame] | 401 | 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] | 402 | 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] | 403 | |
Chmouel Boudjnah | 5cac378 | 2013-07-17 15:13:44 +0000 | [diff] [blame] | 404 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth account_autocreate |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 405 | iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server account_autocreate true |
| 406 | |
Chmouel Boudjnah | 5cac378 | 2013-07-17 15:13:44 +0000 | [diff] [blame] | 407 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix |
| 408 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix "TEMPAUTH" |
| 409 | |
Joe H. Rahme | 1ce2ffd | 2013-10-22 15:19:09 +0200 | [diff] [blame] | 410 | # Configure Crossdomain |
| 411 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:crossdomain use "egg:swift#crossdomain" |
| 412 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 413 | # Configure Keystone |
| 414 | sed -i '/^# \[filter:authtoken\]/,/^# \[filter:keystoneauth\]$/ s/^#[ \t]*//' ${SWIFT_CONFIG_PROXY_SERVER} |
Brant Knudson | 0595237 | 2014-09-19 17:22:22 -0500 | [diff] [blame] | 415 | configure_auth_token_middleware ${SWIFT_CONFIG_PROXY_SERVER} swift $SWIFT_AUTH_CACHE_DIR filter:authtoken |
Peter Portante | 8afc893 | 2013-11-20 17:34:39 -0500 | [diff] [blame] | 416 | # This causes the authtoken middleware to use the same python logging |
| 417 | # adapter provided by the swift proxy-server, so that request transaction |
| 418 | # IDs will included in all of its log messages. |
| 419 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken log_name swift |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 420 | |
| 421 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use |
| 422 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles |
| 423 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin" |
| 424 | |
| 425 | if is_service_enabled swift3; then |
| 426 | cat <<EOF >>${SWIFT_CONFIG_PROXY_SERVER} |
| 427 | # NOTE(chmou): s3token middleware is not updated yet to use only |
| 428 | # username and password. |
| 429 | [filter:s3token] |
Chmouel Boudjnah | 891277f | 2014-02-03 21:07:03 +0000 | [diff] [blame] | 430 | paste.filter_factory = keystoneclient.middleware.s3_token:filter_factory |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 431 | auth_port = ${KEYSTONE_AUTH_PORT} |
| 432 | auth_host = ${KEYSTONE_AUTH_HOST} |
| 433 | auth_protocol = ${KEYSTONE_AUTH_PROTOCOL} |
Rob Crittenden | 18d4778 | 2014-03-19 17:47:42 -0400 | [diff] [blame] | 434 | cafile = ${SSL_BUNDLE_FILE} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 435 | auth_token = ${SERVICE_TOKEN} |
| 436 | admin_token = ${SERVICE_TOKEN} |
| 437 | |
| 438 | [filter:swift3] |
| 439 | use = egg:swift3#swift3 |
| 440 | EOF |
| 441 | fi |
| 442 | |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 443 | cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONF_DIR}/swift.conf |
| 444 | iniset ${SWIFT_CONF_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH} |
Julien Vey | 63024d9 | 2014-05-06 15:10:07 +0200 | [diff] [blame] | 445 | iniset ${SWIFT_CONF_DIR}/swift.conf swift-constraints max_header_size ${SWIFT_MAX_HEADER_SIZE} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 446 | |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 447 | local node_number |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 448 | for node_number in ${SWIFT_REPLICAS_SEQ}; do |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 449 | local swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 450 | cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config} |
Chmouel Boudjnah | 6c585d7 | 2014-10-04 08:14:30 +0200 | [diff] [blame] | 451 | generate_swift_config_services ${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] | 452 | iniset ${swift_node_config} filter:recon recon_cache_path ${SWIFT_DATA_DIR}/cache |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 453 | |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 454 | swift_node_config=${SWIFT_CONF_DIR}/container-server/${node_number}.conf |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 455 | cp ${SWIFT_DIR}/etc/container-server.conf-sample ${swift_node_config} |
Chmouel Boudjnah | 6c585d7 | 2014-10-04 08:14:30 +0200 | [diff] [blame] | 456 | generate_swift_config_services ${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] | 457 | iniuncomment ${swift_node_config} app:container-server allow_versions |
| 458 | iniset ${swift_node_config} app:container-server allow_versions "true" |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 459 | |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 460 | swift_node_config=${SWIFT_CONF_DIR}/account-server/${node_number}.conf |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 461 | cp ${SWIFT_DIR}/etc/account-server.conf-sample ${swift_node_config} |
Chmouel Boudjnah | 6c585d7 | 2014-10-04 08:14:30 +0200 | [diff] [blame] | 462 | generate_swift_config_services ${swift_node_config} ${node_number} $(( ACCOUNT_PORT_BASE + 10 * (node_number - 1) )) account |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 463 | done |
| 464 | |
Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 465 | # Set new accounts in tempauth to match keystone tenant/user (to make testing easier) |
| 466 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest1 "testing .admin" |
| 467 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest2_swiftusertest2 "testing2 .admin" |
| 468 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest3 "testing3 .admin" |
| 469 | |
| 470 | testfile=${SWIFT_CONF_DIR}/test.conf |
| 471 | cp ${SWIFT_DIR}/test/sample.conf ${testfile} |
| 472 | |
| 473 | # Set accounts for functional tests |
| 474 | iniset ${testfile} func_test account swifttenanttest1 |
| 475 | iniset ${testfile} func_test username swiftusertest1 |
| 476 | iniset ${testfile} func_test username3 swiftusertest3 |
| 477 | iniset ${testfile} func_test account2 swifttenanttest2 |
| 478 | iniset ${testfile} func_test username2 swiftusertest2 |
Alistair Coles | 24779f6 | 2014-10-15 18:57:59 +0100 | [diff] [blame] | 479 | iniset ${testfile} func_test account4 swifttenanttest4 |
| 480 | iniset ${testfile} func_test username4 swiftusertest4 |
| 481 | iniset ${testfile} func_test password4 testing4 |
| 482 | iniset ${testfile} func_test domain4 swift_test |
Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 483 | |
Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 484 | if is_service_enabled key;then |
| 485 | iniuncomment ${testfile} func_test auth_version |
Alistair Coles | 24779f6 | 2014-10-15 18:57:59 +0100 | [diff] [blame] | 486 | local auth_vers=$(iniget ${testfile} func_test auth_version) |
Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 487 | iniset ${testfile} func_test auth_host ${KEYSTONE_SERVICE_HOST} |
| 488 | iniset ${testfile} func_test auth_port ${KEYSTONE_AUTH_PORT} |
Alistair Coles | 24779f6 | 2014-10-15 18:57:59 +0100 | [diff] [blame] | 489 | if [[ $auth_vers == "3" ]]; then |
| 490 | iniset ${testfile} func_test auth_prefix /v3/ |
| 491 | else |
| 492 | iniset ${testfile} func_test auth_prefix /v2.0/ |
| 493 | fi |
Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 494 | fi |
| 495 | |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 496 | local swift_log_dir=${SWIFT_DATA_DIR}/logs |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 497 | rm -rf ${swift_log_dir} |
| 498 | mkdir -p ${swift_log_dir}/hourly |
Stephan Renatus | e578eff | 2013-11-19 13:31:04 +0100 | [diff] [blame] | 499 | sudo chown -R ${STACK_USER}:adm ${swift_log_dir} |
Yves-Gwenael Bourhis | f894c2a | 2014-04-16 13:37:46 +0200 | [diff] [blame] | 500 | |
| 501 | if [[ $SYSLOG != "False" ]]; then |
| 502 | sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \ |
| 503 | tee /etc/rsyslog.d/10-swift.conf |
| 504 | # restart syslog to take the changes |
| 505 | sudo killall -HUP rsyslogd |
| 506 | fi |
Sean Dague | ad7e8c6 | 2014-03-19 19:13:20 -0400 | [diff] [blame] | 507 | |
Morgan Fainberg | 46455a3 | 2014-06-20 10:37:18 -0700 | [diff] [blame] | 508 | if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 509 | _config_swift_apache_wsgi |
| 510 | fi |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 511 | } |
| 512 | |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 513 | # create_swift_disk - Create Swift backing disk |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 514 | function create_swift_disk { |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 515 | local node_number |
| 516 | |
| 517 | # First do a bit of setup by creating the directories and |
| 518 | # changing the permissions so we can run it as our user. |
| 519 | |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 520 | local user_group=$(id -g ${STACK_USER}) |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 521 | sudo mkdir -p ${SWIFT_DATA_DIR}/{drives,cache,run,logs} |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 522 | sudo chown -R ${STACK_USER}:${user_group} ${SWIFT_DATA_DIR} |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 523 | |
| 524 | # Create a loopback disk and format it to XFS. |
Attila Fazekas | e602441 | 2013-09-15 18:38:48 +0200 | [diff] [blame] | 525 | if [[ -e ${SWIFT_DISK_IMAGE} ]]; then |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 526 | if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then |
| 527 | sudo umount ${SWIFT_DATA_DIR}/drives/sdb1 |
Attila Fazekas | e602441 | 2013-09-15 18:38:48 +0200 | [diff] [blame] | 528 | sudo rm -f ${SWIFT_DISK_IMAGE} |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 529 | fi |
| 530 | fi |
| 531 | |
| 532 | mkdir -p ${SWIFT_DATA_DIR}/drives/images |
Attila Fazekas | e602441 | 2013-09-15 18:38:48 +0200 | [diff] [blame] | 533 | sudo touch ${SWIFT_DISK_IMAGE} |
Stephan Renatus | e578eff | 2013-11-19 13:31:04 +0100 | [diff] [blame] | 534 | sudo chown ${STACK_USER}: ${SWIFT_DISK_IMAGE} |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 535 | |
Attila Fazekas | e602441 | 2013-09-15 18:38:48 +0200 | [diff] [blame] | 536 | truncate -s ${SWIFT_LOOPBACK_DISK_SIZE} ${SWIFT_DISK_IMAGE} |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 537 | |
| 538 | # Make a fresh XFS filesystem |
Longgeek | fd034f0 | 2014-03-24 17:32:02 +0800 | [diff] [blame] | 539 | /sbin/mkfs.xfs -f -i size=1024 ${SWIFT_DISK_IMAGE} |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 540 | |
| 541 | # Mount the disk with mount options to make it as efficient as possible |
| 542 | mkdir -p ${SWIFT_DATA_DIR}/drives/sdb1 |
| 543 | if ! egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then |
| 544 | sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8 \ |
Attila Fazekas | e602441 | 2013-09-15 18:38:48 +0200 | [diff] [blame] | 545 | ${SWIFT_DISK_IMAGE} ${SWIFT_DATA_DIR}/drives/sdb1 |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 546 | fi |
| 547 | |
| 548 | # Create a link to the above mount and |
| 549 | # create all of the directories needed to emulate a few different servers |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 550 | local node_number |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 551 | for node_number in ${SWIFT_REPLICAS_SEQ}; do |
| 552 | sudo ln -sf ${SWIFT_DATA_DIR}/drives/sdb1/$node_number ${SWIFT_DATA_DIR}/$node_number; |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 553 | local drive=${SWIFT_DATA_DIR}/drives/sdb1/${node_number} |
| 554 | local node=${SWIFT_DATA_DIR}/${node_number}/node |
| 555 | local node_device=${node}/sdb1 |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 556 | [[ -d $node ]] && continue |
| 557 | [[ -d $drive ]] && continue |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 558 | sudo install -o ${STACK_USER} -g $user_group -d $drive |
| 559 | sudo install -o ${STACK_USER} -g $user_group -d $node_device |
Stephan Renatus | e578eff | 2013-11-19 13:31:04 +0100 | [diff] [blame] | 560 | sudo chown -R ${STACK_USER}: ${node} |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 561 | done |
| 562 | } |
Chmouel Boudjnah | ba31305 | 2013-07-10 21:03:43 +0200 | [diff] [blame] | 563 | # create_swift_accounts() - Set up standard swift accounts and extra |
| 564 | # one for tests we do this by attaching all words in the account name |
| 565 | # since we want to make it compatible with tempauth which use |
| 566 | # underscores for separators. |
Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 567 | |
Alistair Coles | 24779f6 | 2014-10-15 18:57:59 +0100 | [diff] [blame] | 568 | # Tenant User Roles Domain |
Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 569 | # ------------------------------------------------------------------ |
Alistair Coles | 24779f6 | 2014-10-15 18:57:59 +0100 | [diff] [blame] | 570 | # service swift service default |
| 571 | # swifttenanttest1 swiftusertest1 admin default |
| 572 | # swifttenanttest1 swiftusertest3 anotherrole default |
| 573 | # swifttenanttest2 swiftusertest2 admin default |
| 574 | # swifttenanttest4 swiftusertest4 admin swift_test |
Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 575 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 576 | function create_swift_accounts { |
Sahid Orentino Ferdjaoui | 1814e67 | 2014-02-11 17:56:07 +0100 | [diff] [blame] | 577 | # Defines specific passwords used by tools/create_userrc.sh |
JordanP | 7c6d005 | 2014-10-06 23:08:50 +0200 | [diff] [blame] | 578 | # As these variables are used by create_userrc.sh, they must be exported |
| 579 | # The _password suffix is expected by create_userrc.sh |
| 580 | export swiftusertest1_password=testing |
| 581 | export swiftusertest2_password=testing2 |
| 582 | export swiftusertest3_password=testing3 |
Alistair Coles | 24779f6 | 2014-10-15 18:57:59 +0100 | [diff] [blame] | 583 | export swiftusertest4_password=testing4 |
Sahid Orentino Ferdjaoui | 1814e67 | 2014-02-11 17:56:07 +0100 | [diff] [blame] | 584 | |
Chmouel Boudjnah | ba31305 | 2013-07-10 21:03:43 +0200 | [diff] [blame] | 585 | KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql} |
| 586 | |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 587 | local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") |
| 588 | local admin_role=$(openstack role list | awk "/ admin / { print \$2 }") |
Masayuki Igawa | d365405 | 2014-09-01 17:30:05 +0900 | [diff] [blame] | 589 | local another_role=$(openstack role list | awk "/ anotherrole / { print \$2 }") |
Chmouel Boudjnah | ba31305 | 2013-07-10 21:03:43 +0200 | [diff] [blame] | 590 | |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 591 | local swift_user=$(get_or_create_user "swift" \ |
| 592 | "$SERVICE_PASSWORD" $service_tenant) |
| 593 | get_or_add_user_role $admin_role $swift_user $service_tenant |
Chmouel Boudjnah | ba31305 | 2013-07-10 21:03:43 +0200 | [diff] [blame] | 594 | |
| 595 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then |
Bartosz GĂ³rski | 0abde39 | 2014-02-28 14:15:19 +0100 | [diff] [blame] | 596 | |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 597 | local swift_service=$(get_or_create_service "swift" \ |
Bartosz GĂ³rski | 0abde39 | 2014-02-28 14:15:19 +0100 | [diff] [blame] | 598 | "object-store" "Swift Service") |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 599 | get_or_create_endpoint $swift_service \ |
Bartosz GĂ³rski | 0abde39 | 2014-02-28 14:15:19 +0100 | [diff] [blame] | 600 | "$REGION_NAME" \ |
Rob Crittenden | 18d4778 | 2014-03-19 17:47:42 -0400 | [diff] [blame] | 601 | "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \ |
| 602 | "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:8080" \ |
| 603 | "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" |
Chmouel Boudjnah | ba31305 | 2013-07-10 21:03:43 +0200 | [diff] [blame] | 604 | fi |
| 605 | |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 606 | local swift_tenant_test1=$(get_or_create_project swifttenanttest1) |
| 607 | die_if_not_set $LINENO swift_tenant_test1 "Failure creating swift_tenant_test1" |
| 608 | SWIFT_USER_TEST1=$(get_or_create_user swiftusertest1 $swiftusertest1_password \ |
| 609 | "$swift_tenant_test1" "test@example.com") |
DennyZhang | 23178a9 | 2013-10-22 17:07:32 -0500 | [diff] [blame] | 610 | die_if_not_set $LINENO SWIFT_USER_TEST1 "Failure creating SWIFT_USER_TEST1" |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 611 | get_or_add_user_role $admin_role $SWIFT_USER_TEST1 $swift_tenant_test1 |
Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 612 | |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 613 | local swift_user_test3=$(get_or_create_user swiftusertest3 $swiftusertest3_password \ |
| 614 | "$swift_tenant_test1" "test3@example.com") |
| 615 | die_if_not_set $LINENO swift_user_test3 "Failure creating swift_user_test3" |
Masayuki Igawa | d365405 | 2014-09-01 17:30:05 +0900 | [diff] [blame] | 616 | get_or_add_user_role $another_role $swift_user_test3 $swift_tenant_test1 |
Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 617 | |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 618 | local swift_tenant_test2=$(get_or_create_project swifttenanttest2) |
| 619 | die_if_not_set $LINENO swift_tenant_test2 "Failure creating swift_tenant_test2" |
Steve Martinelli | 1968542 | 2014-01-24 13:02:26 -0600 | [diff] [blame] | 620 | |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 621 | local swift_user_test2=$(get_or_create_user swiftusertest2 $swiftusertest2_password \ |
| 622 | "$swift_tenant_test2" "test2@example.com") |
| 623 | die_if_not_set $LINENO swift_user_test2 "Failure creating swift_user_test2" |
| 624 | get_or_add_user_role $admin_role $swift_user_test2 $swift_tenant_test2 |
Alistair Coles | 24779f6 | 2014-10-15 18:57:59 +0100 | [diff] [blame] | 625 | |
| 626 | local swift_domain=$(get_or_create_domain swift_test 'Used for swift functional testing') |
| 627 | die_if_not_set $LINENO swift_domain "Failure creating swift_test domain" |
| 628 | |
| 629 | local swift_tenant_test4=$(get_or_create_project swifttenanttest4 $swift_domain) |
| 630 | die_if_not_set $LINENO swift_tenant_test4 "Failure creating swift_tenant_test4" |
| 631 | local swift_user_test4=$(get_or_create_user swiftusertest4 $swiftusertest4_password \ |
| 632 | $swift_tenant_test4 "test4@example.com" $swift_domain) |
| 633 | die_if_not_set $LINENO swift_user_test4 "Failure creating swift_user_test4" |
| 634 | get_or_add_user_role $admin_role $swift_user_test4 $swift_tenant_test4 |
Chmouel Boudjnah | 0ce91a5 | 2013-07-05 11:59:24 +0000 | [diff] [blame] | 635 | } |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 636 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 637 | # init_swift() - Initialize rings |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 638 | function init_swift { |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 639 | local node_number |
| 640 | # Make sure to kill all swift processes first |
Chmouel Boudjnah | ad8b276 | 2013-01-10 15:40:01 +0100 | [diff] [blame] | 641 | swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 642 | |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 643 | # Forcibly re-create the backing filesystem |
| 644 | create_swift_disk |
| 645 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 646 | # This is where we create three different rings for swift with |
| 647 | # different object servers binding on different ports. |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 648 | pushd ${SWIFT_CONF_DIR} >/dev/null && { |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 649 | |
| 650 | rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz |
| 651 | |
| 652 | swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1 |
| 653 | swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1 |
| 654 | swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1 |
| 655 | |
| 656 | for node_number in ${SWIFT_REPLICAS_SEQ}; do |
Ian Wienand | d968f2b | 2014-08-14 11:43:54 +1000 | [diff] [blame] | 657 | swift-ring-builder object.builder add z${node_number}-127.0.0.1:$(( OBJECT_PORT_BASE + 10 * (node_number - 1) ))/sdb1 1 |
| 658 | swift-ring-builder container.builder add z${node_number}-127.0.0.1:$(( CONTAINER_PORT_BASE + 10 * (node_number - 1) ))/sdb1 1 |
| 659 | swift-ring-builder account.builder add z${node_number}-127.0.0.1:$(( ACCOUNT_PORT_BASE + 10 * (node_number - 1) ))/sdb1 1 |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 660 | done |
| 661 | swift-ring-builder object.builder rebalance |
| 662 | swift-ring-builder container.builder rebalance |
| 663 | swift-ring-builder account.builder rebalance |
| 664 | } && popd >/dev/null |
| 665 | |
Dean Troyer | 64ab774 | 2012-12-28 15:38:28 -0600 | [diff] [blame] | 666 | # Create cache dir |
| 667 | sudo mkdir -p $SWIFT_AUTH_CACHE_DIR |
Attila Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 668 | sudo chown $STACK_USER $SWIFT_AUTH_CACHE_DIR |
Dean Troyer | 64ab774 | 2012-12-28 15:38:28 -0600 | [diff] [blame] | 669 | rm -f $SWIFT_AUTH_CACHE_DIR/* |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 670 | } |
| 671 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 672 | function install_swift { |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 673 | git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH |
Dean Troyer | 253a1a3 | 2013-04-01 18:23:22 -0500 | [diff] [blame] | 674 | setup_develop $SWIFT_DIR |
Morgan Fainberg | 46455a3 | 2014-06-20 10:37:18 -0700 | [diff] [blame] | 675 | if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 676 | install_apache_wsgi |
| 677 | fi |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 678 | } |
| 679 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 680 | function install_swiftclient { |
Sean Dague | e08ab10 | 2014-11-13 17:09:28 -0500 | [diff] [blame] | 681 | if use_library_from_git "python-swiftclient"; then |
| 682 | git_clone_by_name "python-swiftclient" |
| 683 | setup_dev_lib "python-swiftclient" |
Sean Dague | 5cb1906 | 2014-11-01 01:37:45 +0100 | [diff] [blame] | 684 | fi |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 685 | } |
| 686 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 687 | # start_swift() - Start running processes, including screen |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 688 | function start_swift { |
Chmouel Boudjnah | 8ecbb38 | 2013-03-12 12:15:17 +0100 | [diff] [blame] | 689 | # (re)start memcached to make sure we have a clean memcache. |
| 690 | restart_service memcached |
| 691 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 692 | # Start rsync |
Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 693 | if is_ubuntu; then |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 694 | sudo /etc/init.d/rsync restart || : |
Attila Fazekas | 0e57b96 | 2014-02-28 09:09:52 +0100 | [diff] [blame] | 695 | elif [ -e /etc/xinetd.d/rsync ]; then |
| 696 | start_service xinetd |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 697 | else |
Attila Fazekas | 0e57b96 | 2014-02-28 09:09:52 +0100 | [diff] [blame] | 698 | start_service rsyncd |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 699 | fi |
| 700 | |
Morgan Fainberg | 46455a3 | 2014-06-20 10:37:18 -0700 | [diff] [blame] | 701 | if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 702 | restart_apache_server |
| 703 | swift-init --run-dir=${SWIFT_DATA_DIR}/run rest start |
Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 704 | tail_log s-proxy /var/log/$APACHE_NAME/proxy-server |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 705 | if [[ ${SWIFT_REPLICAS} == 1 ]]; then |
| 706 | for type in object container account; do |
Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 707 | tail_log s-${type} /var/log/$APACHE_NAME/${type}-server-1 |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 708 | done |
| 709 | fi |
| 710 | return 0 |
| 711 | fi |
| 712 | |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 713 | # By default with only one replica we are launching the proxy, |
| 714 | # container, account and object server in screen in foreground and |
| 715 | # other services in background. If we have SWIFT_REPLICAS set to something |
| 716 | # greater than one we first spawn all the swift services then kill the proxy |
| 717 | # service so we can run it in foreground in screen. ``swift-init ... |
| 718 | # {stop|restart}`` exits with '1' if no servers are running, ignore it just |
| 719 | # in case |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 720 | local todo type |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 721 | swift-init --run-dir=${SWIFT_DATA_DIR}/run all restart || true |
| 722 | if [[ ${SWIFT_REPLICAS} == 1 ]]; then |
Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 723 | todo="object container account" |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 724 | fi |
| 725 | for type in proxy ${todo}; do |
| 726 | swift-init --run-dir=${SWIFT_DATA_DIR}/run ${type} stop || true |
| 727 | done |
Rob Crittenden | 18d4778 | 2014-03-19 17:47:42 -0400 | [diff] [blame] | 728 | if is_service_enabled tls-proxy; then |
| 729 | local proxy_port=${SWIFT_DEFAULT_BIND_PORT:-8080} |
| 730 | start_tls_proxy '*' $proxy_port $SERVICE_HOST $SWIFT_DEFAULT_BIND_PORT_INT & |
| 731 | fi |
Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 732 | run_process s-proxy "$SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONF_DIR}/proxy-server.conf -v" |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 733 | if [[ ${SWIFT_REPLICAS} == 1 ]]; then |
| 734 | for type in object container account; do |
Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 735 | run_process s-${type} "$SWIFT_DIR/bin/swift-${type}-server ${SWIFT_CONF_DIR}/${type}-server/1.conf -v" |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 736 | done |
| 737 | fi |
Jim Rollenhagen | abbb0e9 | 2014-08-05 18:01:48 +0000 | [diff] [blame] | 738 | |
| 739 | if [[ "$SWIFT_ENABLE_TEMPURLS" == "True" ]]; then |
| 740 | swift_configure_tempurls |
| 741 | fi |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | # stop_swift() - Stop running processes (non-screen) |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 745 | function stop_swift { |
Dean Troyer | 084f51f | 2014-07-25 15:08:52 -0500 | [diff] [blame] | 746 | local type |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 747 | |
Morgan Fainberg | 46455a3 | 2014-06-20 10:37:18 -0700 | [diff] [blame] | 748 | if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 749 | swift-init --run-dir=${SWIFT_DATA_DIR}/run rest stop && return 0 |
| 750 | fi |
| 751 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 752 | # screen normally killed by unstack.sh |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 753 | if type -p swift-init >/dev/null; then |
Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 754 | swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true |
| 755 | fi |
Chmouel Boudjnah | f36a9b2 | 2014-02-03 23:44:47 +0100 | [diff] [blame] | 756 | # Dump all of the servers |
Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 757 | # Maintain the iteration as stop_process() has some desirable side-effects |
Dean Troyer | 1eae3e1 | 2014-03-06 11:49:22 -0600 | [diff] [blame] | 758 | for type in proxy object container account; do |
Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 759 | stop_process s-${type} |
Dean Troyer | 1eae3e1 | 2014-03-06 11:49:22 -0600 | [diff] [blame] | 760 | done |
| 761 | # Blast out any stragglers |
Chmouel Boudjnah | f36a9b2 | 2014-02-03 23:44:47 +0100 | [diff] [blame] | 762 | pkill -f swift- |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 763 | } |
| 764 | |
Jim Rollenhagen | abbb0e9 | 2014-08-05 18:01:48 +0000 | [diff] [blame] | 765 | function swift_configure_tempurls { |
| 766 | OS_USERNAME=swift \ |
| 767 | OS_TENANT_NAME=$SERVICE_TENANT_NAME \ |
| 768 | OS_PASSWORD=$SERVICE_PASSWORD \ |
| 769 | swift post -m "Temp-URL-Key: $SWIFT_TEMPURL_KEY" |
| 770 | } |
| 771 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 772 | # Restore xtrace |
| 773 | $XTRACE |
Sean Dague | 584d90e | 2013-03-29 14:34:53 -0400 | [diff] [blame] | 774 | |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 775 | # Tell emacs to use shell-script-mode |
| 776 | ## Local variables: |
| 777 | ## mode: shell-script |
| 778 | ## End: |