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