blob: 9c13701c6e69770d700d33318c40df62a65edb13 [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
Attila Fazekasece6a332012-11-29 14:19:41 +01003# lib/swift
Dean Troyer6d04fd72012-12-21 11:03:37 -06004# Functions to control the configuration and operation of the **Swift** service
Attila Fazekasece6a332012-11-29 14:19:41 +01005
6# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01007#
8# - ``functions`` file
9# - ``apache`` file
Sean Dague0eebeb42017-08-30 14:16:58 -040010# - ``DEST``, `SWIFT_HASH` must be defined
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010011# - ``STACK_USER`` must be defined
12# - ``SWIFT_DATA_DIR`` or ``DATA_DIR`` must be defined
13# - ``lib/keystone`` file
14#
Attila Fazekasece6a332012-11-29 14:19:41 +010015# ``stack.sh`` calls the entry points in this order:
16#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010017# - 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 Fazekasece6a332012-11-29 14:19:41 +010025
26# Save trace setting
Ian Wienand523f4882015-10-13 11:03:03 +110027_XTRACE_LIB_SWIFT=$(set +o | grep xtrace)
Attila Fazekasece6a332012-11-29 14:19:41 +010028set +o xtrace
29
30
31# Defaults
32# --------
33
Sean Daguef3b2f4c2017-04-13 10:11:48 -040034if is_service_enabled tls-proxy; then
Rob Crittenden18d47782014-03-19 17:47:42 -040035 SWIFT_SERVICE_PROTOCOL="https"
36fi
37
Attila Fazekasece6a332012-11-29 14:19:41 +010038# Set up default directories
Sean Daguee08ab102014-11-13 17:09:28 -050039GITDIR["python-swiftclient"]=$DEST/python-swiftclient
Paul Belangera62ede72018-03-14 11:58:56 -040040SWIFT_DIR=$DEST/swift
Sean Dague5cb19062014-11-01 01:37:45 +010041
Sean Dague5edae542017-03-21 20:50:24 -040042# Swift virtual environment
43if [[ ${USE_VENV} = True ]]; then
44 PROJECT_VENV["swift"]=${SWIFT_DIR}.venv
45 SWIFT_BIN_DIR=${PROJECT_VENV["swift"]}/bin
46else
47 SWIFT_BIN_DIR=$(get_python_exec_prefix)
48fi
49
zhang-hared98a5d02013-06-21 18:18:02 +080050SWIFT_APACHE_WSGI_DIR=${SWIFT_APACHE_WSGI_DIR:-/var/www/swift}
Attila Fazekasece6a332012-11-29 14:19:41 +010051
Rob Crittenden18d47782014-03-19 17:47:42 -040052SWIFT_SERVICE_PROTOCOL=${SWIFT_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
Falk Reimann22f747b2015-08-28 12:40:19 +020053SWIFT_DEFAULT_BIND_PORT=${SWIFT_DEFAULT_BIND_PORT:-8080}
Rob Crittenden18d47782014-03-19 17:47:42 -040054SWIFT_DEFAULT_BIND_PORT_INT=${SWIFT_DEFAULT_BIND_PORT_INT:-8081}
Brian Haley180f5eb2015-06-16 13:14:31 -040055SWIFT_SERVICE_LOCAL_HOST=${SWIFT_SERVICE_LOCAL_HOST:-$SERVICE_LOCAL_HOST}
Jens Harbottdc7b4292017-09-19 10:52:32 +000056SWIFT_SERVICE_LISTEN_ADDRESS=${SWIFT_SERVICE_LISTEN_ADDRESS:-$(ipv6_unquote $SERVICE_LISTEN_ADDRESS)}
Rob Crittenden18d47782014-03-19 17:47:42 -040057
Attila Fazekasece6a332012-11-29 14:19:41 +010058# TODO: add logging to different location.
59
60# Set ``SWIFT_DATA_DIR`` to the location of swift drives and objects.
61# Default is the common DevStack data directory.
62SWIFT_DATA_DIR=${SWIFT_DATA_DIR:-${DATA_DIR}/swift}
Attila Fazekase6024412013-09-15 18:38:48 +020063SWIFT_DISK_IMAGE=${SWIFT_DATA_DIR}/drives/images/swift.img
Attila Fazekasece6a332012-11-29 14:19:41 +010064
Dean Troyer6ec72fa2013-03-13 11:44:53 -050065# Set ``SWIFT_CONF_DIR`` to the location of the configuration files.
Attila Fazekasece6a332012-11-29 14:19:41 +010066# Default is ``/etc/swift``.
JordanPa6dfe812014-11-20 18:06:23 +010067SWIFT_CONF_DIR=${SWIFT_CONF_DIR:-/etc/swift}
Attila Fazekasece6a332012-11-29 14:19:41 +010068
Kota Tsuyuzaki070e4ee2018-09-13 03:08:19 +090069if is_service_enabled s-proxy && is_service_enabled s3api; then
70 # If we are using ``s3api``, we can default the S3 port to swift instead
Dean Troyerb7490da2013-03-18 16:07:56 -050071 # of nova-objectstore
Falk Reimann22f747b2015-08-28 12:40:19 +020072 S3_SERVICE_PORT=${S3_SERVICE_PORT:-$SWIFT_DEFAULT_BIND_PORT}
Dean Troyerb7490da2013-03-18 16:07:56 -050073fi
74
Ivan Kolodyazhny9ebd65b2015-03-08 23:51:55 +020075if is_service_enabled g-api; then
76 # Minimum Cinder volume size is 1G so if Swift backend for Glance is
77 # only 1G we can not upload volume to image.
78 # Increase Swift disk size up to 2G
79 SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=2G
Matthew Oliver7b857232016-03-07 18:21:29 +110080 SWIFT_MAX_FILE_SIZE_DEFAULT=1073741824 # 1G
Ivan Kolodyazhny9ebd65b2015-03-08 23:51:55 +020081else
82 # DevStack will create a loop-back disk formatted as XFS to store the
83 # swift data. Set ``SWIFT_LOOPBACK_DISK_SIZE`` to the disk size in
84 # kilobytes.
85 # Default is 1 gigabyte.
86 SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=1G
Matthew Oliver7b857232016-03-07 18:21:29 +110087 SWIFT_MAX_FILE_SIZE_DEFAULT=536870912 # 512M
Ivan Kolodyazhny9ebd65b2015-03-08 23:51:55 +020088fi
89
Joe Gordon66c54242013-11-12 16:24:14 -080090# if tempest enabled the default size is 6 Gigabyte.
Attila Fazekas3418c1c2013-09-16 18:35:49 +020091if is_service_enabled tempest; then
Joe Gordon66c54242013-11-12 16:24:14 -080092 SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=${SWIFT_LOOPBACK_DISK_SIZE:-6G}
Matthew Oliver7b857232016-03-07 18:21:29 +110093 SWIFT_MAX_FILE_SIZE_DEFAULT=5368709122 # Swift default 5G
Attila Fazekas3418c1c2013-09-16 18:35:49 +020094fi
95
96SWIFT_LOOPBACK_DISK_SIZE=${SWIFT_LOOPBACK_DISK_SIZE:-$SWIFT_LOOPBACK_DISK_SIZE_DEFAULT}
Attila Fazekasece6a332012-11-29 14:19:41 +010097
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010098# Set ``SWIFT_EXTRAS_MIDDLEWARE`` to extras middlewares.
Samuel Merrittf19ccb62014-03-08 07:54:05 -080099# Default is ``staticweb, formpost``
100SWIFT_EXTRAS_MIDDLEWARE=${SWIFT_EXTRAS_MIDDLEWARE:-formpost staticweb}
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100101
Cyril Roelandtd9883402013-09-27 15:16:51 +0000102# Set ``SWIFT_EXTRAS_MIDDLEWARE_LAST`` to extras middlewares that need to be at
103# the end of the pipeline.
Sean Dague53753292014-12-04 19:38:15 -0500104SWIFT_EXTRAS_MIDDLEWARE_LAST=${SWIFT_EXTRAS_MIDDLEWARE_LAST:-}
Cyril Roelandtd9883402013-09-27 15:16:51 +0000105
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200106# Set ``SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH`` to extras middlewares that need to be at
107# the beginning of the pipeline, before authentication middlewares.
108SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH=${SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH:-crossdomain}
109
Marian Horbanea21eb42015-08-18 06:57:18 -0400110# The ring uses a configurable number of bits from a path's MD5 hash as
Attila Fazekasece6a332012-11-29 14:19:41 +0100111# a partition index that designates a device. The number of bits kept
112# from the hash is known as the partition power, and 2 to the partition
113# power indicates the partition count. Partitioning the full MD5 hash
114# ring allows other parts of the cluster to work in batches of items at
115# once which ends up either more efficient or at least less complex than
116# working with each item separately or the entire cluster all at once.
117# By default we define 9 for the partition count (which mean 512).
118SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9}
119
120# Set ``SWIFT_REPLICAS`` to configure how many replicas are to be
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100121# configured for your Swift cluster. By default we are configuring
122# only one replica since this is way less CPU and memory intensive. If
123# you are planning to test swift replication you may want to set this
124# up to 3.
125SWIFT_REPLICAS=${SWIFT_REPLICAS:-1}
Attila Fazekasece6a332012-11-29 14:19:41 +0100126SWIFT_REPLICAS_SEQ=$(seq ${SWIFT_REPLICAS})
127
Jordan Pittier980d65f2017-03-27 14:29:58 +0200128# Set ``SWIFT_START_ALL_SERVICES`` to control whether all Swift
129# services (including the *-auditor, *-replicator, *-reconstructor, etc.
130# daemons) should be started.
131SWIFT_START_ALL_SERVICES=$(trueorfalse True SWIFT_START_ALL_SERVICES)
132
Peter Portantecee4b3b2013-11-20 14:33:16 -0500133# Set ``SWIFT_LOG_TOKEN_LENGTH`` to configure how many characters of an auth
134# token should be placed in the logs. When keystone is used with PKI tokens,
135# the token values can be huge, seemingly larger the 2K, at the least. We
136# restrict it here to a default of 12 characters, which should be enough to
137# trace through the logs when looking for its use.
138SWIFT_LOG_TOKEN_LENGTH=${SWIFT_LOG_TOKEN_LENGTH:-12}
139
Atsushi SAKAIfe7b56c2015-11-13 17:06:16 +0900140# Set ``SWIFT_MAX_HEADER_SIZE`` to configure the maximum length of headers in
Julien Vey63024d92014-05-06 15:10:07 +0200141# Swift API
142SWIFT_MAX_HEADER_SIZE=${SWIFT_MAX_HEADER_SIZE:-16384}
143
Matthew Oliver7b857232016-03-07 18:21:29 +1100144# Set ``SWIFT_MAX_FILE_SIZE`` to configure the maximum file size in Swift API
145# Default 500MB because the loopback file used for swift could be 1 or 2 GB
146SWIFT_MAX_FILE_SIZE=${SWIFT_MAX_FILE_SIZE:-$SWIFT_MAX_FILE_SIZE_DEFAULT}
147
Attila Fazekasece6a332012-11-29 14:19:41 +0100148# Set ``OBJECT_PORT_BASE``, ``CONTAINER_PORT_BASE``, ``ACCOUNT_PORT_BASE``
Atsushi SAKAIfe7b56c2015-11-13 17:06:16 +0900149# Port bases used in port number calculation for the service "nodes"
150# The specified port number will be used, the additional ports calculated by
Attila Fazekasece6a332012-11-29 14:19:41 +0100151# base_port + node_num * 10
Denis Afonsodbe08682015-10-02 23:51:41 -0400152OBJECT_PORT_BASE=${OBJECT_PORT_BASE:-6613}
153CONTAINER_PORT_BASE=${CONTAINER_PORT_BASE:-6611}
154ACCOUNT_PORT_BASE=${ACCOUNT_PORT_BASE:-6612}
Attila Fazekasece6a332012-11-29 14:19:41 +0100155
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000156# Enable tempurl feature
157SWIFT_ENABLE_TEMPURLS=${SWIFT_ENABLE_TEMPURLS:-False}
Sean Dague53753292014-12-04 19:38:15 -0500158SWIFT_TEMPURL_KEY=${SWIFT_TEMPURL_KEY:-}
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000159
Dean Troyerdc97cb72015-03-28 08:20:50 -0500160# Toggle for deploying Swift under HTTPD + mod_wsgi
161SWIFT_USE_MOD_WSGI=${SWIFT_USE_MOD_WSGI:-False}
162
Christian Schwede91d22452016-04-12 10:53:46 +0200163# A space-separated list of storage node IPs that
164# should be used to create the Swift rings
165SWIFT_STORAGE_IPS=${SWIFT_STORAGE_IPS:-}
166
167
Dean Troyercc6b4432013-04-08 15:38:03 -0500168# Functions
169# ---------
Attila Fazekasece6a332012-11-29 14:19:41 +0100170
Dean Troyere4fa7212014-01-15 15:04:49 -0600171# Test if any Swift services are enabled
172# is_swift_enabled
173function is_swift_enabled {
Clark Boylan902158b2017-05-30 14:11:09 -0700174 [[ ,${DISABLED_SERVICES} =~ ,"swift" ]] && return 1
Dean Troyere4fa7212014-01-15 15:04:49 -0600175 [[ ,${ENABLED_SERVICES} =~ ,"s-" ]] && return 0
176 return 1
177}
178
Attila Fazekasece6a332012-11-29 14:19:41 +0100179# cleanup_swift() - Remove residual data files
Ian Wienandaee18c72014-02-21 15:35:08 +1100180function cleanup_swift {
Sean Dague101b4242013-10-22 08:47:11 -0400181 rm -f ${SWIFT_CONF_DIR}{*.builder,*.ring.gz,backups/*.builder,backups/*.ring.gz}
182 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
183 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
184 fi
185 if [[ -e ${SWIFT_DISK_IMAGE} ]]; then
186 rm ${SWIFT_DISK_IMAGE}
187 fi
188 rm -rf ${SWIFT_DATA_DIR}/run/
Morgan Fainberg46455a32014-06-20 10:37:18 -0700189 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
Sean Dague101b4242013-10-22 08:47:11 -0400190 _cleanup_swift_apache_wsgi
191 fi
zhang-hared98a5d02013-06-21 18:18:02 +0800192}
193
194# _cleanup_swift_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
Ian Wienandaee18c72014-02-21 15:35:08 +1100195function _cleanup_swift_apache_wsgi {
zhang-hared98a5d02013-06-21 18:18:02 +0800196 sudo rm -f $SWIFT_APACHE_WSGI_DIR/*.wsgi
Jamie Lennox54707012013-09-17 12:07:48 +1000197 disable_apache_site proxy-server
Dean Troyer084f51f2014-07-25 15:08:52 -0500198 local node_number type
zhang-hared98a5d02013-06-21 18:18:02 +0800199 for node_number in ${SWIFT_REPLICAS_SEQ}; do
200 for type in object container account; do
Dean Troyer084f51f2014-07-25 15:08:52 -0500201 local site_name=${type}-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000202 disable_apache_site ${site_name}
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000203 sudo rm -f $(apache_site_config_for ${site_name})
zhang-hared98a5d02013-06-21 18:18:02 +0800204 done
205 done
206}
207
208# _config_swift_apache_wsgi() - Set WSGI config files of Swift
Ian Wienandaee18c72014-02-21 15:35:08 +1100209function _config_swift_apache_wsgi {
zhang-hared98a5d02013-06-21 18:18:02 +0800210 sudo mkdir -p ${SWIFT_APACHE_WSGI_DIR}
Falk Reimann22f747b2015-08-28 12:40:19 +0200211 local proxy_port=${SWIFT_DEFAULT_BIND_PORT}
zhang-hared98a5d02013-06-21 18:18:02 +0800212
213 # copy proxy vhost and wsgi file
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000214 sudo cp ${SWIFT_DIR}/examples/apache2/proxy-server.template $(apache_site_config_for proxy-server)
zhang-hared98a5d02013-06-21 18:18:02 +0800215 sudo sed -e "
216 /^#/d;/^$/d;
217 s/%PORT%/$proxy_port/g;
218 s/%SERVICENAME%/proxy-server/g;
219 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000220 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000221 " -i $(apache_site_config_for proxy-server)
Jamie Lennox54707012013-09-17 12:07:48 +1000222 enable_apache_site proxy-server
zhang-hared98a5d02013-06-21 18:18:02 +0800223
224 sudo cp ${SWIFT_DIR}/examples/wsgi/proxy-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
225 sudo sed -e "
226 /^#/d;/^$/d;
227 s/%SERVICECONF%/proxy-server.conf/g;
228 " -i ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
zhang-hared98a5d02013-06-21 18:18:02 +0800229
230 # copy apache vhost file and set name and port
Dean Troyer084f51f2014-07-25 15:08:52 -0500231 local node_number
zhang-hared98a5d02013-06-21 18:18:02 +0800232 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Ian Wienandada886d2015-10-07 14:06:26 +1100233 local object_port
234 object_port=$(( OBJECT_PORT_BASE + 10 * (node_number - 1) ))
235 local container_port
236 container_port=$(( CONTAINER_PORT_BASE + 10 * (node_number - 1) ))
237 local account_port
238 account_port=$(( ACCOUNT_PORT_BASE + 10 * (node_number - 1) ))
zhang-hared98a5d02013-06-21 18:18:02 +0800239
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000240 sudo cp ${SWIFT_DIR}/examples/apache2/object-server.template $(apache_site_config_for object-server-${node_number})
zhang-hared98a5d02013-06-21 18:18:02 +0800241 sudo sed -e "
242 s/%PORT%/$object_port/g;
243 s/%SERVICENAME%/object-server-${node_number}/g;
244 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000245 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000246 " -i $(apache_site_config_for object-server-${node_number})
Jamie Lennox54707012013-09-17 12:07:48 +1000247 enable_apache_site object-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800248
249 sudo cp ${SWIFT_DIR}/examples/wsgi/object-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
250 sudo sed -e "
251 /^#/d;/^$/d;
252 s/%SERVICECONF%/object-server\/${node_number}.conf/g;
253 " -i ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
254
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000255 sudo cp ${SWIFT_DIR}/examples/apache2/container-server.template $(apache_site_config_for container-server-${node_number})
zhang-hared98a5d02013-06-21 18:18:02 +0800256 sudo sed -e "
257 /^#/d;/^$/d;
258 s/%PORT%/$container_port/g;
259 s/%SERVICENAME%/container-server-${node_number}/g;
260 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000261 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000262 " -i $(apache_site_config_for container-server-${node_number})
Jamie Lennox54707012013-09-17 12:07:48 +1000263 enable_apache_site container-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800264
265 sudo cp ${SWIFT_DIR}/examples/wsgi/container-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
266 sudo sed -e "
267 /^#/d;/^$/d;
268 s/%SERVICECONF%/container-server\/${node_number}.conf/g;
269 " -i ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
270
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000271 sudo cp ${SWIFT_DIR}/examples/apache2/account-server.template $(apache_site_config_for account-server-${node_number})
zhang-hared98a5d02013-06-21 18:18:02 +0800272 sudo sed -e "
Sean Dague101b4242013-10-22 08:47:11 -0400273 /^#/d;/^$/d;
zhang-hared98a5d02013-06-21 18:18:02 +0800274 s/%PORT%/$account_port/g;
275 s/%SERVICENAME%/account-server-${node_number}/g;
276 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000277 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000278 " -i $(apache_site_config_for account-server-${node_number})
Jamie Lennox54707012013-09-17 12:07:48 +1000279 enable_apache_site account-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800280
281 sudo cp ${SWIFT_DIR}/examples/wsgi/account-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
282 sudo sed -e "
Sean Dague101b4242013-10-22 08:47:11 -0400283 /^#/d;/^$/d;
zhang-hared98a5d02013-06-21 18:18:02 +0800284 s/%SERVICECONF%/account-server\/${node_number}.conf/g;
285 " -i ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
zhang-hared98a5d02013-06-21 18:18:02 +0800286 done
Attila Fazekasece6a332012-11-29 14:19:41 +0100287}
288
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100289# This function generates an object/container/account configuration
290# emulating 4 nodes on different ports
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200291function generate_swift_config_services {
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100292 local swift_node_config=$1
293 local node_id=$2
294 local bind_port=$3
295 local server_type=$4
296
Ian Wienand761c4562014-10-21 11:41:37 +1100297 log_facility=$(( node_id - 1 ))
Dean Troyer084f51f2014-07-25 15:08:52 -0500298 local node_path=${SWIFT_DATA_DIR}/${node_number}
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100299
300 iniuncomment ${swift_node_config} DEFAULT user
301 iniset ${swift_node_config} DEFAULT user ${STACK_USER}
302
303 iniuncomment ${swift_node_config} DEFAULT bind_port
304 iniset ${swift_node_config} DEFAULT bind_port ${bind_port}
305
306 iniuncomment ${swift_node_config} DEFAULT swift_dir
307 iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONF_DIR}
308
309 iniuncomment ${swift_node_config} DEFAULT devices
310 iniset ${swift_node_config} DEFAULT devices ${node_path}
311
312 iniuncomment ${swift_node_config} DEFAULT log_facility
313 iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility}
314
315 iniuncomment ${swift_node_config} DEFAULT workers
Chmouel Boudjnah55dc2c22014-09-12 09:34:20 +0200316 iniset ${swift_node_config} DEFAULT workers ${API_WORKERS:-1}
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100317
318 iniuncomment ${swift_node_config} DEFAULT disable_fallocate
319 iniset ${swift_node_config} DEFAULT disable_fallocate true
320
321 iniuncomment ${swift_node_config} DEFAULT mount_check
322 iniset ${swift_node_config} DEFAULT mount_check false
323
324 iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode
325 iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200326
327 # Using a sed and not iniset/iniuncomment because we want to a global
328 # modification and make sure it works for new sections.
329 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100330}
331
Attila Fazekasece6a332012-11-29 14:19:41 +0100332# configure_swift() - Set config files, create data dirs and loop image
Ian Wienandaee18c72014-02-21 15:35:08 +1100333function configure_swift {
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200334 local swift_pipeline="${SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH}"
Attila Fazekasece6a332012-11-29 14:19:41 +0100335 local node_number
336 local swift_node_config
337 local swift_log_dir
338
Attila Fazekasece6a332012-11-29 14:19:41 +0100339 # Make sure to kill all swift processes first
Paul Belangera62ede72018-03-14 11:58:56 -0400340 $SWIFT_BIN_DIR/swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100341
Dean Troyer8421c2b2015-03-16 13:52:19 -0500342 sudo install -d -o ${STACK_USER} ${SWIFT_CONF_DIR}
343 sudo install -d -o ${STACK_USER} ${SWIFT_CONF_DIR}/{object,container,account}-server
Attila Fazekasece6a332012-11-29 14:19:41 +0100344
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500345 if [[ "$SWIFT_CONF_DIR" != "/etc/swift" ]]; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100346 # Some swift tools are hard-coded to use ``/etc/swift`` and are apparently not going to be fixed.
347 # Create a symlink if the config dir is moved
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500348 sudo ln -sf ${SWIFT_CONF_DIR} /etc/swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100349 fi
350
351 # Swift use rsync to synchronize between all the different
352 # partitions (which make more sense when you have a multi-node
353 # setup) we configure it with our version of rsync.
354 sed -e "
Takashi Kajinami25f84272021-08-21 21:38:43 +0900355 s/%GROUP%/$(id -g -n ${STACK_USER})/;
Stephan Renatuse578eff2013-11-19 13:31:04 +0100356 s/%USER%/${STACK_USER}/;
Attila Fazekasece6a332012-11-29 14:19:41 +0100357 s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,;
358 " $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf
359 # rsyncd.conf just prepared for 4 nodes
Vincent Untzc18b9652012-12-04 12:36:34 +0100360 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100361 sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync
Attila Fazekas0e57b962014-02-28 09:09:52 +0100362 elif [ -e /etc/xinetd.d/rsync ]; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100363 sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync
364 fi
365
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500366 SWIFT_CONFIG_PROXY_SERVER=${SWIFT_CONF_DIR}/proxy-server.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100367 cp ${SWIFT_DIR}/etc/proxy-server.conf-sample ${SWIFT_CONFIG_PROXY_SERVER}
Sumit Jamgade1fccf0b2018-05-24 16:24:00 +0200368 cp ${SWIFT_DIR}/etc/internal-client.conf-sample ${SWIFT_CONF_DIR}/internal-client.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100369
Daisuke Moritad03915f2014-10-08 06:52:21 +0000370 # To run container sync feature introduced in Swift ver 1.12.0,
371 # container sync "realm" is added in container-sync-realms.conf
372 local csyncfile=${SWIFT_CONF_DIR}/container-sync-realms.conf
373 cp ${SWIFT_DIR}/etc/container-sync-realms.conf-sample ${csyncfile}
374 iniset ${csyncfile} realm1 key realm1key
Falk Reimann22f747b2015-08-28 12:40:19 +0200375 iniset ${csyncfile} realm1 cluster_name1 "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:$SWIFT_DEFAULT_BIND_PORT/v1/"
Chmouel Boudjnahf2c1a712014-01-29 21:38:14 +0000376
Attila Fazekasece6a332012-11-29 14:19:41 +0100377 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user
Stephan Renatuse578eff2013-11-19 13:31:04 +0100378 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user ${STACK_USER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100379
380 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500381 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100382
383 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers
384 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1
385
386 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level
387 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level DEBUG
388
Rawlin Peters92ad1522015-07-20 13:33:33 -0600389 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_ip
390 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_ip ${SWIFT_SERVICE_LISTEN_ADDRESS}
391
Attila Fazekasece6a332012-11-29 14:19:41 +0100392 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port
Rob Crittenden18d47782014-03-19 17:47:42 -0400393 if is_service_enabled tls-proxy; then
394 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT_INT}
395 else
Falk Reimann22f747b2015-08-28 12:40:19 +0200396 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT}
Rob Crittenden18d47782014-03-19 17:47:42 -0400397 fi
398
Dean Troyerdc97cb72015-03-28 08:20:50 -0500399 # DevStack is commonly run in a small slow environment, so bump the timeouts up.
400 # ``node_timeout`` is the node read operation response time to the proxy server
401 # ``conn_timeout`` is how long it takes a connect() system call to return
Joe Gordond254da52013-11-19 21:06:29 -0800402 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server node_timeout 120
403 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server conn_timeout 20
404
Attila Fazekas2bd8d902016-10-13 08:24:57 +0200405 # Versioned Writes
406 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:versioned_writes allow_versioned_writes true
407
Dina Belovaeedfdee2014-06-24 16:52:46 +0400408 # Configure Ceilometer
409 if is_service_enabled ceilometer; then
410 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer "set log_level" "WARN"
gordon chungb6197e62015-02-12 15:33:35 -0500411 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer paste.filter_factory "ceilometermiddleware.swift:filter_factory"
412 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer control_exchange "swift"
Thomas Herve26e431d2017-04-13 14:27:35 +0200413 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer url $(get_notification_url)
gordon chungb6197e62015-02-12 15:33:35 -0500414 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer driver "messaging"
415 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer topic "notifications"
Dina Belovaeedfdee2014-06-24 16:52:46 +0400416 SWIFT_EXTRAS_MIDDLEWARE_LAST="${SWIFT_EXTRAS_MIDDLEWARE_LAST} ceilometer"
417 fi
Cyril Roelandtd9883402013-09-27 15:16:51 +0000418
Dean Troyerdc97cb72015-03-28 08:20:50 -0500419 # Restrict the length of auth tokens in the Swift ``proxy-server`` logs.
Peter Portantecee4b3b2013-11-20 14:33:16 -0500420 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:proxy-logging reveal_sensitive_prefix ${SWIFT_LOG_TOKEN_LENGTH}
421
Dean Troyerdc97cb72015-03-28 08:20:50 -0500422 # By default Swift will be installed with Keystone and tempauth middleware
Kota Tsuyuzaki070e4ee2018-09-13 03:08:19 +0900423 # and add the s3api middleware if its configured for it. The token for
Adam Spierscb961592013-10-05 12:11:07 +0100424 # tempauth would be prefixed with the reseller_prefix setting `TEMPAUTH_` the
425 # token for keystoneauth would have the standard reseller_prefix `AUTH_`
Kota Tsuyuzaki070e4ee2018-09-13 03:08:19 +0900426 if is_service_enabled s3api;then
427 swift_pipeline+=" s3api"
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100428 fi
Dean Troyer5ce44cd2015-02-12 22:18:33 -0600429 if is_service_enabled keystone; then
Tim Burke5b48e362020-05-26 16:21:45 -0700430 swift_pipeline+=" authtoken"
Kota Tsuyuzaki070e4ee2018-09-13 03:08:19 +0900431 if is_service_enabled s3api;then
432 swift_pipeline+=" s3token"
Jens Harbottc2491ba2020-06-14 18:06:23 +0200433 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:s3token auth_uri ${KEYSTONE_SERVICE_URI_V3}
Tim Burke6681a1f2020-05-26 20:11:24 -0700434 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:s3token delay_auth_decision true
Kota Tsuyuzaki070e4ee2018-09-13 03:08:19 +0900435 fi
Tim Burke5b48e362020-05-26 16:21:45 -0700436 swift_pipeline+=" keystoneauth"
Chmouel Boudjnah254fd552014-06-30 12:22:59 +0000437 fi
Kota Tsuyuzaki070e4ee2018-09-13 03:08:19 +0900438
Chmouel Boudjnah254fd552014-06-30 12:22:59 +0000439 swift_pipeline+=" tempauth "
440
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100441 sed -i "/^pipeline/ { s/tempauth/${swift_pipeline} ${SWIFT_EXTRAS_MIDDLEWARE}/ ;}" ${SWIFT_CONFIG_PROXY_SERVER}
Cyril Roelandtd9883402013-09-27 15:16:51 +0000442 sed -i "/^pipeline/ { s/proxy-server/${SWIFT_EXTRAS_MIDDLEWARE_LAST} proxy-server/ ; }" ${SWIFT_CONFIG_PROXY_SERVER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100443
444 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server account_autocreate true
Brian Ober958c1692016-05-11 19:11:31 -0500445 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server allow_account_management true
Attila Fazekasece6a332012-11-29 14:19:41 +0100446
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200447 # Configure Crossdomain
448 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:crossdomain use "egg:swift#crossdomain"
449
Dean Troyerdc97cb72015-03-28 08:20:50 -0500450 # Configure authtoken middleware to use the same Python logging
451 # adapter provided by the Swift ``proxy-server``, so that request transaction
Peter Portante8afc8932013-11-20 17:34:39 -0500452 # IDs will included in all of its log messages.
453 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken log_name swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100454
Jamie Lennox38c95b82015-01-30 02:15:42 +0000455 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken paste.filter_factory keystonemiddleware.auth_token:filter_factory
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100456 configure_keystone_authtoken_middleware $SWIFT_CONFIG_PROXY_SERVER swift filter:authtoken
Jamie Lennox38c95b82015-01-30 02:15:42 +0000457 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken delay_auth_decision 1
458 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken cache swift.cache
459 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken include_service_catalog False
460
461 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use "egg:swift#keystoneauth"
Attila Fazekasece6a332012-11-29 14:19:41 +0100462 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin"
463
Dean Troyerdc97cb72015-03-28 08:20:50 -0500464 # Configure Tempauth. In the sample config file Keystoneauth is commented
Donagh McCabe7faceb62014-12-19 13:20:45 +0000465 # out. Make sure we uncomment Tempauth after we uncomment Keystoneauth
466 # otherwise, this code also sets the reseller_prefix for Keystoneauth.
467 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth account_autocreate
Donagh McCabe7faceb62014-12-19 13:20:45 +0000468 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix "TEMPAUTH"
469
Tim Burke59fb9612017-08-15 13:48:04 -0700470 # Allow both reseller prefixes to be used with domain_remap
471 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:domain_remap reseller_prefixes "AUTH, TEMPAUTH"
472
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500473 cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONF_DIR}/swift.conf
474 iniset ${SWIFT_CONF_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH}
Julien Vey63024d92014-05-06 15:10:07 +0200475 iniset ${SWIFT_CONF_DIR}/swift.conf swift-constraints max_header_size ${SWIFT_MAX_HEADER_SIZE}
Matthew Oliver7b857232016-03-07 18:21:29 +1100476 iniset ${SWIFT_CONF_DIR}/swift.conf swift-constraints max_file_size ${SWIFT_MAX_FILE_SIZE}
Attila Fazekasece6a332012-11-29 14:19:41 +0100477
Dean Troyer084f51f2014-07-25 15:08:52 -0500478 local node_number
Attila Fazekasece6a332012-11-29 14:19:41 +0100479 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Dean Troyer084f51f2014-07-25 15:08:52 -0500480 local swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100481 cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config}
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200482 generate_swift_config_services ${swift_node_config} ${node_number} $(( OBJECT_PORT_BASE + 10 * (node_number - 1) )) object
Rawlin Peters92ad1522015-07-20 13:33:33 -0600483 iniuncomment ${swift_node_config} DEFAULT bind_ip
484 iniset ${swift_node_config} DEFAULT bind_ip ${SWIFT_SERVICE_LISTEN_ADDRESS}
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000485 iniset ${swift_node_config} filter:recon recon_cache_path ${SWIFT_DATA_DIR}/cache
Attila Fazekasece6a332012-11-29 14:19:41 +0100486
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500487 swift_node_config=${SWIFT_CONF_DIR}/container-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100488 cp ${SWIFT_DIR}/etc/container-server.conf-sample ${swift_node_config}
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200489 generate_swift_config_services ${swift_node_config} ${node_number} $(( CONTAINER_PORT_BASE + 10 * (node_number - 1) )) container
Rawlin Peters92ad1522015-07-20 13:33:33 -0600490 iniuncomment ${swift_node_config} DEFAULT bind_ip
491 iniset ${swift_node_config} DEFAULT bind_ip ${SWIFT_SERVICE_LISTEN_ADDRESS}
Attila Fazekasece6a332012-11-29 14:19:41 +0100492
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500493 swift_node_config=${SWIFT_CONF_DIR}/account-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100494 cp ${SWIFT_DIR}/etc/account-server.conf-sample ${swift_node_config}
Chmouel Boudjnah6c585d72014-10-04 08:14:30 +0200495 generate_swift_config_services ${swift_node_config} ${node_number} $(( ACCOUNT_PORT_BASE + 10 * (node_number - 1) )) account
Rawlin Peters92ad1522015-07-20 13:33:33 -0600496 iniuncomment ${swift_node_config} DEFAULT bind_ip
497 iniset ${swift_node_config} DEFAULT bind_ip ${SWIFT_SERVICE_LISTEN_ADDRESS}
Attila Fazekasece6a332012-11-29 14:19:41 +0100498 done
499
Sean Dague19dfa2a2016-04-04 10:11:54 -0400500 # Set new accounts in tempauth to match keystone project/user (to make testing easier)
501 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swiftprojecttest1_swiftusertest1 "testing .admin"
502 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swiftprojecttest2_swiftusertest2 "testing2 .admin"
503 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swiftprojecttest1_swiftusertest3 "testing3 .admin"
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000504
505 testfile=${SWIFT_CONF_DIR}/test.conf
506 cp ${SWIFT_DIR}/test/sample.conf ${testfile}
507
508 # Set accounts for functional tests
Sean Dague19dfa2a2016-04-04 10:11:54 -0400509 iniset ${testfile} func_test account swiftprojecttest1
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000510 iniset ${testfile} func_test username swiftusertest1
511 iniset ${testfile} func_test username3 swiftusertest3
Sean Dague19dfa2a2016-04-04 10:11:54 -0400512 iniset ${testfile} func_test account2 swiftprojecttest2
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000513 iniset ${testfile} func_test username2 swiftusertest2
Sean Dague19dfa2a2016-04-04 10:11:54 -0400514 iniset ${testfile} func_test account4 swiftprojecttest4
Alistair Coles24779f62014-10-15 18:57:59 +0100515 iniset ${testfile} func_test username4 swiftusertest4
516 iniset ${testfile} func_test password4 testing4
517 iniset ${testfile} func_test domain4 swift_test
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000518
Dean Troyer5ce44cd2015-02-12 22:18:33 -0600519 if is_service_enabled keystone; then
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000520 iniuncomment ${testfile} func_test auth_version
Ian Wienandada886d2015-10-07 14:06:26 +1100521 local auth_vers
522 auth_vers=$(iniget ${testfile} func_test auth_version)
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000523 iniset ${testfile} func_test auth_host ${KEYSTONE_SERVICE_HOST}
Jens Harbottc2491ba2020-06-14 18:06:23 +0200524 if [[ "$KEYSTONE_SERVICE_PROTOCOL" == "https" ]]; then
Tim Burkef43ea472017-04-18 21:51:57 -0700525 iniset ${testfile} func_test auth_port 443
Alistair Coles24779f62014-10-15 18:57:59 +0100526 else
Tim Burkef43ea472017-04-18 21:51:57 -0700527 iniset ${testfile} func_test auth_port 80
528 fi
Jens Harbott32c00892019-04-10 10:33:39 +0000529 iniset ${testfile} func_test auth_uri ${KEYSTONE_SERVICE_URI}
Tim Burkef43ea472017-04-18 21:51:57 -0700530 if [[ "$auth_vers" == "3" ]]; then
531 iniset ${testfile} func_test auth_prefix /identity/v3/
532 else
533 iniset ${testfile} func_test auth_prefix /identity/v2.0/
Alistair Coles24779f62014-10-15 18:57:59 +0100534 fi
Clark Boylane28db4c2017-06-01 16:07:32 -0700535 if is_service_enabled tls-proxy; then
536 iniset ${testfile} func_test cafile ${SSL_BUNDLE_FILE}
537 iniset ${testfile} func_test web_front_end apache2
538 fi
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000539 fi
540
Ian Wienandada886d2015-10-07 14:06:26 +1100541 local user_group
542 user_group=$(id -g ${STACK_USER})
Geronimo Orozco2f6576b2015-03-19 12:08:23 -0600543 sudo install -d -o ${STACK_USER} -g ${user_group} ${SWIFT_DATA_DIR}
544
Dean Troyer084f51f2014-07-25 15:08:52 -0500545 local swift_log_dir=${SWIFT_DATA_DIR}/logs
Geronimo Orozco2f6576b2015-03-19 12:08:23 -0600546 sudo rm -rf ${swift_log_dir}
Dirk Mueller4404f682018-03-02 00:37:58 +0100547 local swift_log_group=adm
548 if is_suse; then
549 swift_log_group=root
550 fi
551 sudo install -d -o ${STACK_USER} -g ${swift_log_group} ${swift_log_dir}/hourly
Yves-Gwenael Bourhisf894c2a2014-04-16 13:37:46 +0200552
553 if [[ $SYSLOG != "False" ]]; then
554 sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \
555 tee /etc/rsyslog.d/10-swift.conf
Paul Belanger37c78432017-04-19 13:19:21 -0400556 echo "MaxMessageSize 6k" | sudo tee /etc/rsyslog.d/99-maxsize.conf
Yves-Gwenael Bourhisf894c2a2014-04-16 13:37:46 +0200557 # restart syslog to take the changes
558 sudo killall -HUP rsyslogd
559 fi
Sean Daguead7e8c62014-03-19 19:13:20 -0400560
Morgan Fainberg46455a32014-06-20 10:37:18 -0700561 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800562 _config_swift_apache_wsgi
563 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100564}
565
Dean Troyer1c6c1122013-03-27 17:40:53 -0500566# create_swift_disk - Create Swift backing disk
Ian Wienandaee18c72014-02-21 15:35:08 +1100567function create_swift_disk {
Dean Troyer1c6c1122013-03-27 17:40:53 -0500568 local node_number
569
570 # First do a bit of setup by creating the directories and
571 # changing the permissions so we can run it as our user.
572
Ian Wienandada886d2015-10-07 14:06:26 +1100573 local user_group
574 user_group=$(id -g ${STACK_USER})
Dean Troyer8421c2b2015-03-16 13:52:19 -0500575 sudo install -d -o ${STACK_USER} -g ${user_group} ${SWIFT_DATA_DIR}/{drives,cache,run,logs}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500576
577 # Create a loopback disk and format it to XFS.
Attila Fazekase6024412013-09-15 18:38:48 +0200578 if [[ -e ${SWIFT_DISK_IMAGE} ]]; then
Dean Troyer1c6c1122013-03-27 17:40:53 -0500579 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
580 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
Attila Fazekase6024412013-09-15 18:38:48 +0200581 sudo rm -f ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500582 fi
583 fi
584
585 mkdir -p ${SWIFT_DATA_DIR}/drives/images
Attila Fazekase6024412013-09-15 18:38:48 +0200586 sudo touch ${SWIFT_DISK_IMAGE}
Stephan Renatuse578eff2013-11-19 13:31:04 +0100587 sudo chown ${STACK_USER}: ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500588
Attila Fazekase6024412013-09-15 18:38:48 +0200589 truncate -s ${SWIFT_LOOPBACK_DISK_SIZE} ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500590
591 # Make a fresh XFS filesystem
Longgeekfd034f02014-03-24 17:32:02 +0800592 /sbin/mkfs.xfs -f -i size=1024 ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500593
594 # Mount the disk with mount options to make it as efficient as possible
595 mkdir -p ${SWIFT_DATA_DIR}/drives/sdb1
596 if ! egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
Lee Yarwood5d7d8912018-12-03 14:21:06 +0000597 sudo mount -t xfs -o loop,noatime,nodiratime,logbufs=8 \
Attila Fazekase6024412013-09-15 18:38:48 +0200598 ${SWIFT_DISK_IMAGE} ${SWIFT_DATA_DIR}/drives/sdb1
Dean Troyer1c6c1122013-03-27 17:40:53 -0500599 fi
600
601 # Create a link to the above mount and
602 # create all of the directories needed to emulate a few different servers
Dean Troyer084f51f2014-07-25 15:08:52 -0500603 local node_number
Dean Troyer1c6c1122013-03-27 17:40:53 -0500604 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Clay Gerrard0e58d222017-08-28 14:03:18 -0700605 # node_devices must match *.conf devices option
606 local node_devices=${SWIFT_DATA_DIR}/${node_number}
607 local real_devices=${SWIFT_DATA_DIR}/drives/sdb1/$node_number
608 sudo ln -sf $real_devices $node_devices;
609 local device=${real_devices}/sdb1
610 [[ -d $device ]] && continue
611 sudo install -o ${STACK_USER} -g $user_group -d $device
Dean Troyer1c6c1122013-03-27 17:40:53 -0500612 done
613}
Dean Troyerdc97cb72015-03-28 08:20:50 -0500614
615# create_swift_accounts() - Set up standard Swift accounts and extra
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200616# one for tests we do this by attaching all words in the account name
617# since we want to make it compatible with tempauth which use
618# underscores for separators.
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000619
Sean Dague19dfa2a2016-04-04 10:11:54 -0400620# Project User Roles Domain
621# -------------------------------------------------------------------
622# service swift service default
623# swiftprojecttest1 swiftusertest1 admin default
624# swiftprojecttest1 swiftusertest3 anotherrole default
625# swiftprojecttest2 swiftusertest2 admin default
626# swiftprojecttest4 swiftusertest4 admin swift_test
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000627
Ian Wienandaee18c72014-02-21 15:35:08 +1100628function create_swift_accounts {
Dean Troyerdc97cb72015-03-28 08:20:50 -0500629 # Defines specific passwords used by ``tools/create_userrc.sh``
630 # As these variables are used by ``create_userrc.sh,`` they must be exported
631 # The _password suffix is expected by ``create_userrc.sh``.
JordanP7c6d0052014-10-06 23:08:50 +0200632 export swiftusertest1_password=testing
633 export swiftusertest2_password=testing2
634 export swiftusertest3_password=testing3
Alistair Coles24779f62014-10-15 18:57:59 +0100635 export swiftusertest4_password=testing4
Sahid Orentino Ferdjaoui1814e672014-02-11 17:56:07 +0100636
Ian Wienandada886d2015-10-07 14:06:26 +1100637 local another_role
638 another_role=$(get_or_create_role "anotherrole")
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200639
Jim Rollenhagenae74ed72015-02-12 07:33:36 -0800640 # NOTE(jroll): Swift doesn't need the admin role here, however Ironic uses
641 # temp urls, which break when uploaded by a non-admin role
642 create_service_user "swift" "admin"
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200643
Sean Dague985e9582016-02-10 07:25:24 -0500644 get_or_create_service "swift" "object-store" "Swift Service"
Matt Riedemannae4578b2016-04-23 01:45:40 +0000645 get_or_create_endpoint \
Sean Dague985e9582016-02-10 07:25:24 -0500646 "object-store" \
647 "$REGION_NAME" \
Sean Dague260583e2016-04-04 09:11:25 -0400648 "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:$SWIFT_DEFAULT_BIND_PORT/v1/AUTH_\$(project_id)s" \
Sean Dague11eb2012017-02-13 16:16:59 -0500649 "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:$SWIFT_DEFAULT_BIND_PORT"
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200650
Sean Dague19dfa2a2016-04-04 10:11:54 -0400651 local swift_project_test1
652 swift_project_test1=$(get_or_create_project swiftprojecttest1 default)
653 die_if_not_set $LINENO swift_project_test1 "Failure creating swift_project_test1"
Jamie Lennox9d7e7762015-05-29 01:08:53 +0000654 SWIFT_USER_TEST1=$(get_or_create_user swiftusertest1 $swiftusertest1_password \
655 "default" "test@example.com")
DennyZhang23178a92013-10-22 17:07:32 -0500656 die_if_not_set $LINENO SWIFT_USER_TEST1 "Failure creating SWIFT_USER_TEST1"
Sean Dague19dfa2a2016-04-04 10:11:54 -0400657 get_or_add_user_project_role admin $SWIFT_USER_TEST1 $swift_project_test1
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000658
Ian Wienandada886d2015-10-07 14:06:26 +1100659 local swift_user_test3
660 swift_user_test3=$(get_or_create_user swiftusertest3 $swiftusertest3_password \
Jamie Lennox9d7e7762015-05-29 01:08:53 +0000661 "default" "test3@example.com")
Dean Troyer084f51f2014-07-25 15:08:52 -0500662 die_if_not_set $LINENO swift_user_test3 "Failure creating swift_user_test3"
Sean Dague19dfa2a2016-04-04 10:11:54 -0400663 get_or_add_user_project_role $another_role $swift_user_test3 $swift_project_test1
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000664
Sean Dague19dfa2a2016-04-04 10:11:54 -0400665 local swift_project_test2
666 swift_project_test2=$(get_or_create_project swiftprojecttest2 default)
667 die_if_not_set $LINENO swift_project_test2 "Failure creating swift_project_test2"
Steve Martinelli19685422014-01-24 13:02:26 -0600668
Ian Wienandada886d2015-10-07 14:06:26 +1100669 local swift_user_test2
670 swift_user_test2=$(get_or_create_user swiftusertest2 $swiftusertest2_password \
Jamie Lennox9d7e7762015-05-29 01:08:53 +0000671 "default" "test2@example.com")
Dean Troyer084f51f2014-07-25 15:08:52 -0500672 die_if_not_set $LINENO swift_user_test2 "Failure creating swift_user_test2"
Sean Dague19dfa2a2016-04-04 10:11:54 -0400673 get_or_add_user_project_role admin $swift_user_test2 $swift_project_test2
Alistair Coles24779f62014-10-15 18:57:59 +0100674
Ian Wienandada886d2015-10-07 14:06:26 +1100675 local swift_domain
676 swift_domain=$(get_or_create_domain swift_test 'Used for swift functional testing')
Alistair Coles24779f62014-10-15 18:57:59 +0100677 die_if_not_set $LINENO swift_domain "Failure creating swift_test domain"
678
Sean Dague19dfa2a2016-04-04 10:11:54 -0400679 local swift_project_test4
680 swift_project_test4=$(get_or_create_project swiftprojecttest4 $swift_domain)
681 die_if_not_set $LINENO swift_project_test4 "Failure creating swift_project_test4"
Jamie Lennox18f39bf2015-01-28 13:38:32 +1000682
Ian Wienandada886d2015-10-07 14:06:26 +1100683 local swift_user_test4
684 swift_user_test4=$(get_or_create_user swiftusertest4 $swiftusertest4_password \
Jamie Lennox9d7e7762015-05-29 01:08:53 +0000685 $swift_domain "test4@example.com")
Alistair Coles24779f62014-10-15 18:57:59 +0100686 die_if_not_set $LINENO swift_user_test4 "Failure creating swift_user_test4"
Sean Dague19dfa2a2016-04-04 10:11:54 -0400687 get_or_add_user_project_role admin $swift_user_test4 $swift_project_test4
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000688}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500689
Attila Fazekasece6a332012-11-29 14:19:41 +0100690# init_swift() - Initialize rings
Ian Wienandaee18c72014-02-21 15:35:08 +1100691function init_swift {
Attila Fazekasece6a332012-11-29 14:19:41 +0100692 local node_number
693 # Make sure to kill all swift processes first
Paul Belangera62ede72018-03-14 11:58:56 -0400694 $SWIFT_BIN_DIR/swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100695
Dean Troyer1c6c1122013-03-27 17:40:53 -0500696 # Forcibly re-create the backing filesystem
697 create_swift_disk
698
Attila Fazekasece6a332012-11-29 14:19:41 +0100699 # This is where we create three different rings for swift with
700 # different object servers binding on different ports.
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500701 pushd ${SWIFT_CONF_DIR} >/dev/null && {
Attila Fazekasece6a332012-11-29 14:19:41 +0100702
703 rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
704
Paul Belangera62ede72018-03-14 11:58:56 -0400705 $SWIFT_BIN_DIR/swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
706 $SWIFT_BIN_DIR/swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
707 $SWIFT_BIN_DIR/swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
Attila Fazekasece6a332012-11-29 14:19:41 +0100708
Christian Schwede91d22452016-04-12 10:53:46 +0200709 # The ring will be created on each node, and because the order of
710 # nodes is identical we can use a seed for rebalancing, making it
711 # possible to get a ring on each node that uses the same partition
712 # assignment.
713 if [[ -n $SWIFT_STORAGE_IPS ]]; then
714 local node_number
715 node_number=1
716
717 for node in ${SWIFT_STORAGE_IPS}; do
Paul Belangera62ede72018-03-14 11:58:56 -0400718 $SWIFT_BIN_DIR/swift-ring-builder object.builder add z${node_number}-${node}:${OBJECT_PORT_BASE}/sdb1 1
719 $SWIFT_BIN_DIR/swift-ring-builder container.builder add z${node_number}-${node}:${CONTAINER_PORT_BASE}/sdb1 1
720 $SWIFT_BIN_DIR/swift-ring-builder account.builder add z${node_number}-${node}:${ACCOUNT_PORT_BASE}/sdb1 1
Christian Schwede91d22452016-04-12 10:53:46 +0200721 let "node_number=node_number+1"
722 done
723
724 else
725
726 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Paul Belangera62ede72018-03-14 11:58:56 -0400727 $SWIFT_BIN_DIR/swift-ring-builder object.builder add z${node_number}-${SWIFT_SERVICE_LOCAL_HOST}:$(( OBJECT_PORT_BASE + 10 * (node_number - 1) ))/sdb1 1
728 $SWIFT_BIN_DIR/swift-ring-builder container.builder add z${node_number}-${SWIFT_SERVICE_LOCAL_HOST}:$(( CONTAINER_PORT_BASE + 10 * (node_number - 1) ))/sdb1 1
729 $SWIFT_BIN_DIR/swift-ring-builder account.builder add z${node_number}-${SWIFT_SERVICE_LOCAL_HOST}:$(( ACCOUNT_PORT_BASE + 10 * (node_number - 1) ))/sdb1 1
Christian Schwede91d22452016-04-12 10:53:46 +0200730 done
731 fi
732
733 # We use a seed for rebalancing. Doing this allows us to create
734 # identical rings on multiple nodes if SWIFT_STORAGE_IPS is the same
Paul Belangera62ede72018-03-14 11:58:56 -0400735 $SWIFT_BIN_DIR/swift-ring-builder object.builder rebalance 42
736 $SWIFT_BIN_DIR/swift-ring-builder container.builder rebalance 42
737 $SWIFT_BIN_DIR/swift-ring-builder account.builder rebalance 42
Attila Fazekasece6a332012-11-29 14:19:41 +0100738 } && popd >/dev/null
Attila Fazekasece6a332012-11-29 14:19:41 +0100739}
740
Ian Wienandaee18c72014-02-21 15:35:08 +1100741function install_swift {
Attila Fazekasece6a332012-11-29 14:19:41 +0100742 git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH
Ghanshyam Mann04b0b612020-12-22 12:23:56 -0600743 # keystonemiddleware needs to be installed via keystone extras as defined
744 # in setup.cfg, see bug #1909018 for more details.
745 setup_develop $SWIFT_DIR keystone
Morgan Fainberg46455a32014-06-20 10:37:18 -0700746 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800747 install_apache_wsgi
748 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100749}
750
Ian Wienandaee18c72014-02-21 15:35:08 +1100751function install_swiftclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500752 if use_library_from_git "python-swiftclient"; then
753 git_clone_by_name "python-swiftclient"
754 setup_dev_lib "python-swiftclient"
Sean Dague5cb19062014-11-01 01:37:45 +0100755 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100756}
757
Chris Dent1848b832015-06-27 15:05:17 +0100758# install_ceilometermiddleware() - Collect source and prepare
759# note that this doesn't really have anything to do with ceilometer;
760# though ceilometermiddleware has ceilometer in its name as an
761# artifact of history, it is not a ceilometer specific tool. It
762# simply generates pycadf-based notifications about requests and
763# responses on the swift proxy
764function install_ceilometermiddleware {
765 if use_library_from_git "ceilometermiddleware"; then
766 git_clone_by_name "ceilometermiddleware"
767 setup_dev_lib "ceilometermiddleware"
768 else
769 pip_install_gr ceilometermiddleware
770 fi
771}
772
Sean Dague0eebeb42017-08-30 14:16:58 -0400773# start_swift() - Start running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100774function start_swift {
Chmouel Boudjnah8ecbb382013-03-12 12:15:17 +0100775 # (re)start memcached to make sure we have a clean memcache.
776 restart_service memcached
777
Attila Fazekasece6a332012-11-29 14:19:41 +0100778 # Start rsync
Vincent Untzc18b9652012-12-04 12:36:34 +0100779 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100780 sudo /etc/init.d/rsync restart || :
Attila Fazekas0e57b962014-02-28 09:09:52 +0100781 elif [ -e /etc/xinetd.d/rsync ]; then
782 start_service xinetd
Attila Fazekasece6a332012-11-29 14:19:41 +0100783 else
Attila Fazekas0e57b962014-02-28 09:09:52 +0100784 start_service rsyncd
Attila Fazekasece6a332012-11-29 14:19:41 +0100785 fi
786
Morgan Fainberg46455a32014-06-20 10:37:18 -0700787 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
Jordan Pittier980d65f2017-03-27 14:29:58 +0200788 # Apache should serve the "PACO" a.k.a "main" services
zhang-hared98a5d02013-06-21 18:18:02 +0800789 restart_apache_server
Jordan Pittier980d65f2017-03-27 14:29:58 +0200790 # The rest of the services should be started in backgroud
Paul Belangera62ede72018-03-14 11:58:56 -0400791 $SWIFT_BIN_DIR/swift-init --run-dir=${SWIFT_DATA_DIR}/run rest start
zhang-hared98a5d02013-06-21 18:18:02 +0800792 return 0
793 fi
794
Jordan Pittier980d65f2017-03-27 14:29:58 +0200795
796 # By default with only one replica we are launching the proxy, container
797 # account and object server in screen in foreground. Then, the rest of
798 # the services is optionally started.
799 #
800 # If we have ``SWIFT_REPLICAS`` set to something greater than one
801 # we first spawn *all* the Swift services then kill the proxy service
802 # so we can run it in foreground in screen.
803 #
804 # ``swift-init ... {stop|restart}`` exits with '1' if no servers are
805 # running, ignore it just in case
Sean Dague101b4242013-10-22 08:47:11 -0400806 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
Jordan Pittier980d65f2017-03-27 14:29:58 +0200807 local foreground_services type
808
809 foreground_services="object container account"
810 for type in ${foreground_services}; do
811 run_process s-${type} "$SWIFT_BIN_DIR/swift-${type}-server ${SWIFT_CONF_DIR}/${type}-server/1.conf -v"
812 done
813
814 if [[ "$SWIFT_START_ALL_SERVICES" == "True" ]]; then
Paul Belangera62ede72018-03-14 11:58:56 -0400815 $SWIFT_BIN_DIR/swift-init --run-dir=${SWIFT_DATA_DIR}/run rest start
Jordan Pittier980d65f2017-03-27 14:29:58 +0200816 else
817 # The container-sync daemon is strictly needed to pass the container
818 # sync Tempest tests.
Ian Wienand2346e9a2018-02-09 12:49:22 +1100819 enable_service s-container-sync
820 run_process s-container-sync "$SWIFT_BIN_DIR/swift-container-sync ${SWIFT_CONF_DIR}/container-server/1.conf"
Jordan Pittier980d65f2017-03-27 14:29:58 +0200821 fi
822 else
Paul Belangera62ede72018-03-14 11:58:56 -0400823 $SWIFT_BIN_DIR/swift-init --run-dir=${SWIFT_DATA_DIR}/run all restart || true
824 $SWIFT_BIN_DIR/swift-init --run-dir=${SWIFT_DATA_DIR}/run proxy stop || true
Sean Dague101b4242013-10-22 08:47:11 -0400825 fi
Jordan Pittier980d65f2017-03-27 14:29:58 +0200826
Rob Crittenden18d47782014-03-19 17:47:42 -0400827 if is_service_enabled tls-proxy; then
Falk Reimann22f747b2015-08-28 12:40:19 +0200828 local proxy_port=${SWIFT_DEFAULT_BIND_PORT}
Clark Boylanf4dbd122017-05-31 13:17:22 -0700829 start_tls_proxy swift '*' $proxy_port $SERVICE_HOST $SWIFT_DEFAULT_BIND_PORT_INT $SWIFT_MAX_HEADER_SIZE
Rob Crittenden18d47782014-03-19 17:47:42 -0400830 fi
Sean Dague5edae542017-03-21 20:50:24 -0400831 run_process s-proxy "$SWIFT_BIN_DIR/swift-proxy-server ${SWIFT_CONF_DIR}/proxy-server.conf -v"
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000832
Tim Burkeab703502017-07-19 09:55:26 -0700833 # We also started the storage services, but proxy started last and
834 # will take the longest to start, so by the time it comes up, we're
835 # probably fine.
836 echo "Waiting for swift proxy to start..."
837 if ! wait_for_service $SERVICE_TIMEOUT $SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:$SWIFT_DEFAULT_BIND_PORT/info; then
838 die $LINENO "swift proxy did not start"
839 fi
840
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000841 if [[ "$SWIFT_ENABLE_TEMPURLS" == "True" ]]; then
842 swift_configure_tempurls
843 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100844}
845
Sean Dague0eebeb42017-08-30 14:16:58 -0400846# stop_swift() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100847function stop_swift {
Dean Troyer084f51f2014-07-25 15:08:52 -0500848 local type
zhang-hared98a5d02013-06-21 18:18:02 +0800849
Morgan Fainberg46455a32014-06-20 10:37:18 -0700850 if [ "$SWIFT_USE_MOD_WSGI" == "True" ]; then
Paul Belangera62ede72018-03-14 11:58:56 -0400851 $SWIFT_BIN_DIR/swift-init --run-dir=${SWIFT_DATA_DIR}/run rest stop && return 0
zhang-hared98a5d02013-06-21 18:18:02 +0800852 fi
853
Dean Troyerdc97cb72015-03-28 08:20:50 -0500854 # screen normally killed by ``unstack.sh``
Paul Belangera62ede72018-03-14 11:58:56 -0400855 if type -p $SWIFT_BIN_DIR/swift-init >/dev/null; then
856 $SWIFT_BIN_DIR/swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100857 fi
Chmouel Boudjnahf36a9b22014-02-03 23:44:47 +0100858 # Dump all of the servers
Chris Dent2f27a0e2014-09-09 13:46:02 +0100859 # Maintain the iteration as stop_process() has some desirable side-effects
Dean Troyer1eae3e12014-03-06 11:49:22 -0600860 for type in proxy object container account; do
Chris Dent2f27a0e2014-09-09 13:46:02 +0100861 stop_process s-${type}
Dean Troyer1eae3e12014-03-06 11:49:22 -0600862 done
863 # Blast out any stragglers
Attila Fazekasf750a6f2015-07-01 12:17:35 +0200864 pkill -f swift- || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100865}
866
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000867function swift_configure_tempurls {
Steve Martinellia91d4552015-10-20 23:15:38 -0400868 # note we are using swift credentials!
Dr. Jens Harbottf56f7a52021-11-09 10:57:25 +0100869 openstack --os-cloud "" \
870 --os-region-name $REGION_NAME \
871 --os-auth-url $KEYSTONE_SERVICE_URI \
872 --os-username=swift \
873 --os-password=$SERVICE_PASSWORD \
874 --os-user-domain-name=$SERVICE_DOMAIN_NAME \
875 --os-project-name=$SERVICE_PROJECT_NAME \
876 --os-project-domain-name=$SERVICE_DOMAIN_NAME \
877 object store account \
Steve Martinellia91d4552015-10-20 23:15:38 -0400878 set --property "Temp-URL-Key=$SWIFT_TEMPURL_KEY"
Jim Rollenhagenabbb0e92014-08-05 18:01:48 +0000879}
880
Attila Fazekasece6a332012-11-29 14:19:41 +0100881# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +1100882$_XTRACE_LIB_SWIFT
Sean Dague584d90e2013-03-29 14:34:53 -0400883
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100884# Tell emacs to use shell-script-mode
885## Local variables:
886## mode: shell-script
887## End: