blob: c47b09f6d71221f603ee6c700c25b85e36f06893 [file] [log] [blame]
Attila Fazekasece6a332012-11-29 14:19:41 +01001# lib/swift
Dean Troyer6d04fd72012-12-21 11:03:37 -06002# Functions to control the configuration and operation of the **Swift** service
Attila Fazekasece6a332012-11-29 14:19:41 +01003
4# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01005#
6# - ``functions`` file
7# - ``apache`` file
8# - ``DEST``, ``SCREEN_NAME``, `SWIFT_HASH` must be defined
9# - ``STACK_USER`` must be defined
10# - ``SWIFT_DATA_DIR`` or ``DATA_DIR`` must be defined
11# - ``lib/keystone`` file
12#
Attila Fazekasece6a332012-11-29 14:19:41 +010013# ``stack.sh`` calls the entry points in this order:
14#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010015# - install_swift
16# - _config_swift_apache_wsgi
17# - configure_swift
18# - init_swift
19# - start_swift
20# - stop_swift
21# - cleanup_swift
22# - _cleanup_swift_apache_wsgi
Attila Fazekasece6a332012-11-29 14:19:41 +010023
24# Save trace setting
25XTRACE=$(set +o | grep xtrace)
26set +o xtrace
27
28
29# Defaults
30# --------
31
Attila Fazekasece6a332012-11-29 14:19:41 +010032# Set up default directories
Attila Fazekasece6a332012-11-29 14:19:41 +010033SWIFT_DIR=$DEST/swift
34SWIFTCLIENT_DIR=$DEST/python-swiftclient
Dean Troyer64ab7742012-12-28 15:38:28 -060035SWIFT_AUTH_CACHE_DIR=${SWIFT_AUTH_CACHE_DIR:-/var/cache/swift}
zhang-hared98a5d02013-06-21 18:18:02 +080036SWIFT_APACHE_WSGI_DIR=${SWIFT_APACHE_WSGI_DIR:-/var/www/swift}
Dean Troyerb7490da2013-03-18 16:07:56 -050037SWIFT3_DIR=$DEST/swift3
Attila Fazekasece6a332012-11-29 14:19:41 +010038
39# TODO: add logging to different location.
40
41# Set ``SWIFT_DATA_DIR`` to the location of swift drives and objects.
42# Default is the common DevStack data directory.
43SWIFT_DATA_DIR=${SWIFT_DATA_DIR:-${DATA_DIR}/swift}
Attila Fazekase6024412013-09-15 18:38:48 +020044SWIFT_DISK_IMAGE=${SWIFT_DATA_DIR}/drives/images/swift.img
Attila Fazekasece6a332012-11-29 14:19:41 +010045
Dean Troyer6ec72fa2013-03-13 11:44:53 -050046# Set ``SWIFT_CONF_DIR`` to the location of the configuration files.
Attila Fazekasece6a332012-11-29 14:19:41 +010047# Default is ``/etc/swift``.
Dean Troyer6ec72fa2013-03-13 11:44:53 -050048# TODO(dtroyer): remove SWIFT_CONFIG_DIR after cutting stable/grizzly
49SWIFT_CONF_DIR=${SWIFT_CONF_DIR:-${SWIFT_CONFIG_DIR:-/etc/swift}}
Attila Fazekasece6a332012-11-29 14:19:41 +010050
Dean Troyerb7490da2013-03-18 16:07:56 -050051if is_service_enabled s-proxy && is_service_enabled swift3; then
52 # If we are using swift3, we can default the s3 port to swift instead
53 # of nova-objectstore
54 S3_SERVICE_PORT=${S3_SERVICE_PORT:-8080}
55fi
56
Attila Fazekasece6a332012-11-29 14:19:41 +010057# DevStack will create a loop-back disk formatted as XFS to store the
Kevin Lydad66c9652013-01-09 13:39:57 +000058# swift data. Set ``SWIFT_LOOPBACK_DISK_SIZE`` to the disk size in
59# kilobytes.
Attila Fazekasece6a332012-11-29 14:19:41 +010060# Default is 1 gigabyte.
Attila Fazekase6024412013-09-15 18:38:48 +020061SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=1G
Joe Gordon66c54242013-11-12 16:24:14 -080062# if tempest enabled the default size is 6 Gigabyte.
Attila Fazekas3418c1c2013-09-16 18:35:49 +020063if is_service_enabled tempest; then
Joe Gordon66c54242013-11-12 16:24:14 -080064 SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=${SWIFT_LOOPBACK_DISK_SIZE:-6G}
Attila Fazekas3418c1c2013-09-16 18:35:49 +020065fi
66
67SWIFT_LOOPBACK_DISK_SIZE=${SWIFT_LOOPBACK_DISK_SIZE:-$SWIFT_LOOPBACK_DISK_SIZE_DEFAULT}
Attila Fazekasece6a332012-11-29 14:19:41 +010068
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010069# Set ``SWIFT_EXTRAS_MIDDLEWARE`` to extras middlewares.
Samuel Merrittf19ccb62014-03-08 07:54:05 -080070# Default is ``staticweb, formpost``
71SWIFT_EXTRAS_MIDDLEWARE=${SWIFT_EXTRAS_MIDDLEWARE:-formpost staticweb}
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010072
Cyril Roelandtd9883402013-09-27 15:16:51 +000073# Set ``SWIFT_EXTRAS_MIDDLEWARE_LAST`` to extras middlewares that need to be at
74# the end of the pipeline.
75SWIFT_EXTRAS_MIDDLEWARE_LAST=${SWIFT_EXTRAS_MIDDLEWARE_LAST}
76
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +020077# Set ``SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH`` to extras middlewares that need to be at
78# the beginning of the pipeline, before authentication middlewares.
79SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH=${SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH:-crossdomain}
80
Attila Fazekasece6a332012-11-29 14:19:41 +010081# The ring uses a configurable number of bits from a path’s MD5 hash as
82# a partition index that designates a device. The number of bits kept
83# from the hash is known as the partition power, and 2 to the partition
84# power indicates the partition count. Partitioning the full MD5 hash
85# ring allows other parts of the cluster to work in batches of items at
86# once which ends up either more efficient or at least less complex than
87# working with each item separately or the entire cluster all at once.
88# By default we define 9 for the partition count (which mean 512).
89SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9}
90
91# Set ``SWIFT_REPLICAS`` to configure how many replicas are to be
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +010092# configured for your Swift cluster. By default we are configuring
93# only one replica since this is way less CPU and memory intensive. If
94# you are planning to test swift replication you may want to set this
95# up to 3.
96SWIFT_REPLICAS=${SWIFT_REPLICAS:-1}
Attila Fazekasece6a332012-11-29 14:19:41 +010097SWIFT_REPLICAS_SEQ=$(seq ${SWIFT_REPLICAS})
98
Peter Portantecee4b3b2013-11-20 14:33:16 -050099# Set ``SWIFT_LOG_TOKEN_LENGTH`` to configure how many characters of an auth
100# token should be placed in the logs. When keystone is used with PKI tokens,
101# the token values can be huge, seemingly larger the 2K, at the least. We
102# restrict it here to a default of 12 characters, which should be enough to
103# trace through the logs when looking for its use.
104SWIFT_LOG_TOKEN_LENGTH=${SWIFT_LOG_TOKEN_LENGTH:-12}
105
Julien Vey63024d92014-05-06 15:10:07 +0200106# Set ``SWIFT_MAX_HEADER_SIZE`` to configure the maximun length of headers in
107# Swift API
108SWIFT_MAX_HEADER_SIZE=${SWIFT_MAX_HEADER_SIZE:-16384}
109
Attila Fazekasece6a332012-11-29 14:19:41 +0100110# Set ``OBJECT_PORT_BASE``, ``CONTAINER_PORT_BASE``, ``ACCOUNT_PORT_BASE``
111# Port bases used in port number calclution for the service "nodes"
112# The specified port number will be used, the additinal ports calculated by
113# base_port + node_num * 10
Dean Troyer1151d6f2013-03-29 14:06:52 -0500114OBJECT_PORT_BASE=${OBJECT_PORT_BASE:-6013}
115CONTAINER_PORT_BASE=${CONTAINER_PORT_BASE:-6011}
116ACCOUNT_PORT_BASE=${ACCOUNT_PORT_BASE:-6012}
Attila Fazekasece6a332012-11-29 14:19:41 +0100117
Dean Troyer4237f592014-01-29 16:22:11 -0600118# Tell Tempest this project is present
119TEMPEST_SERVICES+=,swift
120
Dean Troyer6d04fd72012-12-21 11:03:37 -0600121
Dean Troyercc6b4432013-04-08 15:38:03 -0500122# Functions
123# ---------
Attila Fazekasece6a332012-11-29 14:19:41 +0100124
Dean Troyere4fa7212014-01-15 15:04:49 -0600125# Test if any Swift services are enabled
126# is_swift_enabled
127function is_swift_enabled {
128 [[ ,${ENABLED_SERVICES} =~ ,"s-" ]] && return 0
129 return 1
130}
131
Attila Fazekasece6a332012-11-29 14:19:41 +0100132# cleanup_swift() - Remove residual data files
Ian Wienandaee18c72014-02-21 15:35:08 +1100133function cleanup_swift {
Sean Dague101b4242013-10-22 08:47:11 -0400134 rm -f ${SWIFT_CONF_DIR}{*.builder,*.ring.gz,backups/*.builder,backups/*.ring.gz}
135 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
136 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
137 fi
138 if [[ -e ${SWIFT_DISK_IMAGE} ]]; then
139 rm ${SWIFT_DISK_IMAGE}
140 fi
141 rm -rf ${SWIFT_DATA_DIR}/run/
142 if is_apache_enabled_service swift; then
143 _cleanup_swift_apache_wsgi
144 fi
zhang-hared98a5d02013-06-21 18:18:02 +0800145}
146
147# _cleanup_swift_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
Ian Wienandaee18c72014-02-21 15:35:08 +1100148function _cleanup_swift_apache_wsgi {
zhang-hared98a5d02013-06-21 18:18:02 +0800149 sudo rm -f $SWIFT_APACHE_WSGI_DIR/*.wsgi
Jamie Lennox54707012013-09-17 12:07:48 +1000150 disable_apache_site proxy-server
zhang-hared98a5d02013-06-21 18:18:02 +0800151 for node_number in ${SWIFT_REPLICAS_SEQ}; do
152 for type in object container account; do
153 site_name=${type}-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000154 disable_apache_site ${site_name}
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000155 sudo rm -f $(apache_site_config_for ${site_name})
zhang-hared98a5d02013-06-21 18:18:02 +0800156 done
157 done
158}
159
160# _config_swift_apache_wsgi() - Set WSGI config files of Swift
Ian Wienandaee18c72014-02-21 15:35:08 +1100161function _config_swift_apache_wsgi {
zhang-hared98a5d02013-06-21 18:18:02 +0800162 sudo mkdir -p ${SWIFT_APACHE_WSGI_DIR}
zhang-hared98a5d02013-06-21 18:18:02 +0800163 local proxy_port=${SWIFT_DEFAULT_BIND_PORT:-8080}
164
165 # copy proxy vhost and wsgi file
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000166 sudo cp ${SWIFT_DIR}/examples/apache2/proxy-server.template $(apache_site_config_for proxy-server)
zhang-hared98a5d02013-06-21 18:18:02 +0800167 sudo sed -e "
168 /^#/d;/^$/d;
169 s/%PORT%/$proxy_port/g;
170 s/%SERVICENAME%/proxy-server/g;
171 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000172 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000173 " -i $(apache_site_config_for proxy-server)
Jamie Lennox54707012013-09-17 12:07:48 +1000174 enable_apache_site proxy-server
zhang-hared98a5d02013-06-21 18:18:02 +0800175
176 sudo cp ${SWIFT_DIR}/examples/wsgi/proxy-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
177 sudo sed -e "
178 /^#/d;/^$/d;
179 s/%SERVICECONF%/proxy-server.conf/g;
180 " -i ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
zhang-hared98a5d02013-06-21 18:18:02 +0800181
182 # copy apache vhost file and set name and port
183 for node_number in ${SWIFT_REPLICAS_SEQ}; do
184 object_port=$[OBJECT_PORT_BASE + 10 * ($node_number - 1)]
185 container_port=$[CONTAINER_PORT_BASE + 10 * ($node_number - 1)]
186 account_port=$[ACCOUNT_PORT_BASE + 10 * ($node_number - 1)]
187
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000188 sudo cp ${SWIFT_DIR}/examples/apache2/object-server.template $(apache_site_config_for object-server-${node_number})
zhang-hared98a5d02013-06-21 18:18:02 +0800189 sudo sed -e "
190 s/%PORT%/$object_port/g;
191 s/%SERVICENAME%/object-server-${node_number}/g;
192 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000193 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000194 " -i $(apache_site_config_for object-server-${node_number})
Jamie Lennox54707012013-09-17 12:07:48 +1000195 enable_apache_site object-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800196
197 sudo cp ${SWIFT_DIR}/examples/wsgi/object-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
198 sudo sed -e "
199 /^#/d;/^$/d;
200 s/%SERVICECONF%/object-server\/${node_number}.conf/g;
201 " -i ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
202
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000203 sudo cp ${SWIFT_DIR}/examples/apache2/container-server.template $(apache_site_config_for container-server-${node_number})
zhang-hared98a5d02013-06-21 18:18:02 +0800204 sudo sed -e "
205 /^#/d;/^$/d;
206 s/%PORT%/$container_port/g;
207 s/%SERVICENAME%/container-server-${node_number}/g;
208 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000209 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000210 " -i $(apache_site_config_for container-server-${node_number})
Jamie Lennox54707012013-09-17 12:07:48 +1000211 enable_apache_site container-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800212
213 sudo cp ${SWIFT_DIR}/examples/wsgi/container-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
214 sudo sed -e "
215 /^#/d;/^$/d;
216 s/%SERVICECONF%/container-server\/${node_number}.conf/g;
217 " -i ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
218
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000219 sudo cp ${SWIFT_DIR}/examples/apache2/account-server.template $(apache_site_config_for account-server-${node_number})
zhang-hared98a5d02013-06-21 18:18:02 +0800220 sudo sed -e "
Sean Dague101b4242013-10-22 08:47:11 -0400221 /^#/d;/^$/d;
zhang-hared98a5d02013-06-21 18:18:02 +0800222 s/%PORT%/$account_port/g;
223 s/%SERVICENAME%/account-server-${node_number}/g;
224 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000225 s/%USER%/${STACK_USER}/g;
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000226 " -i $(apache_site_config_for account-server-${node_number})
Jamie Lennox54707012013-09-17 12:07:48 +1000227 enable_apache_site account-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800228
229 sudo cp ${SWIFT_DIR}/examples/wsgi/account-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
230 sudo sed -e "
Sean Dague101b4242013-10-22 08:47:11 -0400231 /^#/d;/^$/d;
zhang-hared98a5d02013-06-21 18:18:02 +0800232 s/%SERVICECONF%/account-server\/${node_number}.conf/g;
233 " -i ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
zhang-hared98a5d02013-06-21 18:18:02 +0800234 done
Attila Fazekasece6a332012-11-29 14:19:41 +0100235}
236
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100237# This function generates an object/container/account configuration
238# emulating 4 nodes on different ports
Ian Wienandaee18c72014-02-21 15:35:08 +1100239function generate_swift_config {
Ian Wienandf8e86bb2014-02-21 15:16:31 +1100240 local swift_node_config=$1
241 local node_id=$2
242 local bind_port=$3
243 local server_type=$4
244
245 log_facility=$[ node_id - 1 ]
246 node_path=${SWIFT_DATA_DIR}/${node_number}
247
248 iniuncomment ${swift_node_config} DEFAULT user
249 iniset ${swift_node_config} DEFAULT user ${STACK_USER}
250
251 iniuncomment ${swift_node_config} DEFAULT bind_port
252 iniset ${swift_node_config} DEFAULT bind_port ${bind_port}
253
254 iniuncomment ${swift_node_config} DEFAULT swift_dir
255 iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONF_DIR}
256
257 iniuncomment ${swift_node_config} DEFAULT devices
258 iniset ${swift_node_config} DEFAULT devices ${node_path}
259
260 iniuncomment ${swift_node_config} DEFAULT log_facility
261 iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility}
262
263 iniuncomment ${swift_node_config} DEFAULT workers
264 iniset ${swift_node_config} DEFAULT workers 1
265
266 iniuncomment ${swift_node_config} DEFAULT disable_fallocate
267 iniset ${swift_node_config} DEFAULT disable_fallocate true
268
269 iniuncomment ${swift_node_config} DEFAULT mount_check
270 iniset ${swift_node_config} DEFAULT mount_check false
271
272 iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode
273 iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes
274}
275
276
Attila Fazekasece6a332012-11-29 14:19:41 +0100277# configure_swift() - Set config files, create data dirs and loop image
Ian Wienandaee18c72014-02-21 15:35:08 +1100278function configure_swift {
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200279 local swift_pipeline="${SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH}"
Attila Fazekasece6a332012-11-29 14:19:41 +0100280 local node_number
281 local swift_node_config
282 local swift_log_dir
283
Attila Fazekasece6a332012-11-29 14:19:41 +0100284 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100285 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100286
Dean Troyer1c6c1122013-03-27 17:40:53 -0500287 sudo mkdir -p ${SWIFT_CONF_DIR}/{object,container,account}-server
Stephan Renatuse578eff2013-11-19 13:31:04 +0100288 sudo chown -R ${STACK_USER}: ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100289
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500290 if [[ "$SWIFT_CONF_DIR" != "/etc/swift" ]]; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100291 # Some swift tools are hard-coded to use ``/etc/swift`` and are apparently not going to be fixed.
292 # Create a symlink if the config dir is moved
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500293 sudo ln -sf ${SWIFT_CONF_DIR} /etc/swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100294 fi
295
296 # Swift use rsync to synchronize between all the different
297 # partitions (which make more sense when you have a multi-node
298 # setup) we configure it with our version of rsync.
299 sed -e "
300 s/%GROUP%/${USER_GROUP}/;
Stephan Renatuse578eff2013-11-19 13:31:04 +0100301 s/%USER%/${STACK_USER}/;
Attila Fazekasece6a332012-11-29 14:19:41 +0100302 s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,;
303 " $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf
304 # rsyncd.conf just prepared for 4 nodes
Vincent Untzc18b9652012-12-04 12:36:34 +0100305 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100306 sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync
Attila Fazekas0e57b962014-02-28 09:09:52 +0100307 elif [ -e /etc/xinetd.d/rsync ]; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100308 sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync
309 fi
310
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500311 SWIFT_CONFIG_PROXY_SERVER=${SWIFT_CONF_DIR}/proxy-server.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100312 cp ${SWIFT_DIR}/etc/proxy-server.conf-sample ${SWIFT_CONFIG_PROXY_SERVER}
313
Chmouel Boudjnahf2c1a712014-01-29 21:38:14 +0000314 cp ${SWIFT_DIR}/etc/container-sync-realms.conf-sample ${SWIFT_CONF_DIR}/container-sync-realms.conf
315
Attila Fazekasece6a332012-11-29 14:19:41 +0100316 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user
Stephan Renatuse578eff2013-11-19 13:31:04 +0100317 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user ${STACK_USER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100318
319 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500320 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100321
322 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers
323 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1
324
325 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level
326 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level DEBUG
327
328 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port
329 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT:-8080}
330
Joe Gordond254da52013-11-19 21:06:29 -0800331 # Devstack is commonly run in a small slow environment, so bump the
332 # timeouts up.
333 # node_timeout is how long between read operations a node takes to
334 # respond to the proxy server
335 # conn_timeout is all about how long it takes a connect() system call to
336 # return
337 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server node_timeout 120
338 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server conn_timeout 20
339
Joe Gordonc381a542014-03-19 11:09:31 -0700340 # Skipped due to bug 1294789
341 ## Configure Ceilometer
342 #if is_service_enabled ceilometer; then
343 # iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer use "egg:ceilometer#swift"
344 # SWIFT_EXTRAS_MIDDLEWARE_LAST="${SWIFT_EXTRAS_MIDDLEWARE_LAST} ceilometer"
345 #fi
Cyril Roelandtd9883402013-09-27 15:16:51 +0000346
Peter Portantecee4b3b2013-11-20 14:33:16 -0500347 # Restrict the length of auth tokens in the swift proxy-server logs.
348 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:proxy-logging reveal_sensitive_prefix ${SWIFT_LOG_TOKEN_LENGTH}
349
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000350 # By default Swift will be installed with keystone and tempauth middleware
351 # and add the swift3 middleware if its configured for it. The token for
Adam Spierscb961592013-10-05 12:11:07 +0100352 # tempauth would be prefixed with the reseller_prefix setting `TEMPAUTH_` the
353 # token for keystoneauth would have the standard reseller_prefix `AUTH_`
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000354 if is_service_enabled swift3;then
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200355 swift_pipeline+=" swift3 s3token "
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100356 fi
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000357 swift_pipeline+=" authtoken keystoneauth tempauth "
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100358 sed -i "/^pipeline/ { s/tempauth/${swift_pipeline} ${SWIFT_EXTRAS_MIDDLEWARE}/ ;}" ${SWIFT_CONFIG_PROXY_SERVER}
Cyril Roelandtd9883402013-09-27 15:16:51 +0000359 sed -i "/^pipeline/ { s/proxy-server/${SWIFT_EXTRAS_MIDDLEWARE_LAST} proxy-server/ ; }" ${SWIFT_CONFIG_PROXY_SERVER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100360
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000361 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth account_autocreate
Attila Fazekasece6a332012-11-29 14:19:41 +0100362 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server account_autocreate true
363
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000364 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix
365 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix "TEMPAUTH"
366
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200367 # Configure Crossdomain
368 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:crossdomain use "egg:swift#crossdomain"
369
Attila Fazekasece6a332012-11-29 14:19:41 +0100370 # Configure Keystone
371 sed -i '/^# \[filter:authtoken\]/,/^# \[filter:keystoneauth\]$/ s/^#[ \t]*//' ${SWIFT_CONFIG_PROXY_SERVER}
372 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_host $KEYSTONE_AUTH_HOST
373 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_port $KEYSTONE_AUTH_PORT
374 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000375 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken cafile $KEYSTONE_SSL_CA
Attila Fazekasece6a332012-11-29 14:19:41 +0100376 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
377 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
378 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_user swift
379 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_password $SERVICE_PASSWORD
Dean Troyer64ab7742012-12-28 15:38:28 -0600380 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken signing_dir $SWIFT_AUTH_CACHE_DIR
Peter Portante8afc8932013-11-20 17:34:39 -0500381 # This causes the authtoken middleware to use the same python logging
382 # adapter provided by the swift proxy-server, so that request transaction
383 # IDs will included in all of its log messages.
384 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken log_name swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100385
386 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use
387 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles
388 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin"
389
390 if is_service_enabled swift3; then
391 cat <<EOF >>${SWIFT_CONFIG_PROXY_SERVER}
392# NOTE(chmou): s3token middleware is not updated yet to use only
393# username and password.
394[filter:s3token]
Chmouel Boudjnah891277f2014-02-03 21:07:03 +0000395paste.filter_factory = keystoneclient.middleware.s3_token:filter_factory
Attila Fazekasece6a332012-11-29 14:19:41 +0100396auth_port = ${KEYSTONE_AUTH_PORT}
397auth_host = ${KEYSTONE_AUTH_HOST}
398auth_protocol = ${KEYSTONE_AUTH_PROTOCOL}
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000399cafile = ${KEYSTONE_SSL_CA}
Attila Fazekasece6a332012-11-29 14:19:41 +0100400auth_token = ${SERVICE_TOKEN}
401admin_token = ${SERVICE_TOKEN}
402
403[filter:swift3]
404use = egg:swift3#swift3
405EOF
406 fi
407
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500408 cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONF_DIR}/swift.conf
409 iniset ${SWIFT_CONF_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH}
Julien Vey63024d92014-05-06 15:10:07 +0200410 iniset ${SWIFT_CONF_DIR}/swift.conf swift-constraints max_header_size ${SWIFT_MAX_HEADER_SIZE}
Attila Fazekasece6a332012-11-29 14:19:41 +0100411
Attila Fazekasece6a332012-11-29 14:19:41 +0100412 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500413 swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100414 cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000415 generate_swift_config ${swift_node_config} ${node_number} $[OBJECT_PORT_BASE + 10 * (node_number - 1)] object
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000416 iniset ${swift_node_config} filter:recon recon_cache_path ${SWIFT_DATA_DIR}/cache
417 # Using a sed and not iniset/iniuncomment because we want to a global
418 # modification and make sure it works for new sections.
419 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100420
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500421 swift_node_config=${SWIFT_CONF_DIR}/container-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100422 cp ${SWIFT_DIR}/etc/container-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000423 generate_swift_config ${swift_node_config} ${node_number} $[CONTAINER_PORT_BASE + 10 * (node_number - 1)] container
Attila Fazekas83e10952012-11-30 23:28:07 +0100424 iniuncomment ${swift_node_config} app:container-server allow_versions
425 iniset ${swift_node_config} app:container-server allow_versions "true"
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000426 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100427
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500428 swift_node_config=${SWIFT_CONF_DIR}/account-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100429 cp ${SWIFT_DIR}/etc/account-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000430 generate_swift_config ${swift_node_config} ${node_number} $[ACCOUNT_PORT_BASE + 10 * (node_number - 1)] account
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000431 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100432 done
433
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000434 # Set new accounts in tempauth to match keystone tenant/user (to make testing easier)
435 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest1 "testing .admin"
436 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest2_swiftusertest2 "testing2 .admin"
437 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest3 "testing3 .admin"
438
439 testfile=${SWIFT_CONF_DIR}/test.conf
440 cp ${SWIFT_DIR}/test/sample.conf ${testfile}
441
442 # Set accounts for functional tests
443 iniset ${testfile} func_test account swifttenanttest1
444 iniset ${testfile} func_test username swiftusertest1
445 iniset ${testfile} func_test username3 swiftusertest3
446 iniset ${testfile} func_test account2 swifttenanttest2
447 iniset ${testfile} func_test username2 swiftusertest2
448
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000449 if is_service_enabled key;then
450 iniuncomment ${testfile} func_test auth_version
451 iniset ${testfile} func_test auth_host ${KEYSTONE_SERVICE_HOST}
452 iniset ${testfile} func_test auth_port ${KEYSTONE_AUTH_PORT}
453 iniset ${testfile} func_test auth_prefix /v2.0/
454 fi
455
Attila Fazekasece6a332012-11-29 14:19:41 +0100456 swift_log_dir=${SWIFT_DATA_DIR}/logs
457 rm -rf ${swift_log_dir}
458 mkdir -p ${swift_log_dir}/hourly
Stephan Renatuse578eff2013-11-19 13:31:04 +0100459 sudo chown -R ${STACK_USER}:adm ${swift_log_dir}
Yves-Gwenael Bourhisf894c2a2014-04-16 13:37:46 +0200460
461 if [[ $SYSLOG != "False" ]]; then
462 sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \
463 tee /etc/rsyslog.d/10-swift.conf
464 # restart syslog to take the changes
465 sudo killall -HUP rsyslogd
466 fi
Sean Daguead7e8c62014-03-19 19:13:20 -0400467
zhang-hared98a5d02013-06-21 18:18:02 +0800468 if is_apache_enabled_service swift; then
469 _config_swift_apache_wsgi
470 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100471}
472
Dean Troyer1c6c1122013-03-27 17:40:53 -0500473# create_swift_disk - Create Swift backing disk
Ian Wienandaee18c72014-02-21 15:35:08 +1100474function create_swift_disk {
Dean Troyer1c6c1122013-03-27 17:40:53 -0500475 local node_number
476
477 # First do a bit of setup by creating the directories and
478 # changing the permissions so we can run it as our user.
479
Stephan Renatuse578eff2013-11-19 13:31:04 +0100480 USER_GROUP=$(id -g ${STACK_USER})
Dean Troyer1c6c1122013-03-27 17:40:53 -0500481 sudo mkdir -p ${SWIFT_DATA_DIR}/{drives,cache,run,logs}
Stephan Renatuse578eff2013-11-19 13:31:04 +0100482 sudo chown -R ${STACK_USER}:${USER_GROUP} ${SWIFT_DATA_DIR}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500483
484 # Create a loopback disk and format it to XFS.
Attila Fazekase6024412013-09-15 18:38:48 +0200485 if [[ -e ${SWIFT_DISK_IMAGE} ]]; then
Dean Troyer1c6c1122013-03-27 17:40:53 -0500486 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
487 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
Attila Fazekase6024412013-09-15 18:38:48 +0200488 sudo rm -f ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500489 fi
490 fi
491
492 mkdir -p ${SWIFT_DATA_DIR}/drives/images
Attila Fazekase6024412013-09-15 18:38:48 +0200493 sudo touch ${SWIFT_DISK_IMAGE}
Stephan Renatuse578eff2013-11-19 13:31:04 +0100494 sudo chown ${STACK_USER}: ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500495
Attila Fazekase6024412013-09-15 18:38:48 +0200496 truncate -s ${SWIFT_LOOPBACK_DISK_SIZE} ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500497
498 # Make a fresh XFS filesystem
Longgeekfd034f02014-03-24 17:32:02 +0800499 /sbin/mkfs.xfs -f -i size=1024 ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500500
501 # Mount the disk with mount options to make it as efficient as possible
502 mkdir -p ${SWIFT_DATA_DIR}/drives/sdb1
503 if ! egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
504 sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8 \
Attila Fazekase6024412013-09-15 18:38:48 +0200505 ${SWIFT_DISK_IMAGE} ${SWIFT_DATA_DIR}/drives/sdb1
Dean Troyer1c6c1122013-03-27 17:40:53 -0500506 fi
507
508 # Create a link to the above mount and
509 # create all of the directories needed to emulate a few different servers
510 for node_number in ${SWIFT_REPLICAS_SEQ}; do
511 sudo ln -sf ${SWIFT_DATA_DIR}/drives/sdb1/$node_number ${SWIFT_DATA_DIR}/$node_number;
512 drive=${SWIFT_DATA_DIR}/drives/sdb1/${node_number}
513 node=${SWIFT_DATA_DIR}/${node_number}/node
514 node_device=${node}/sdb1
515 [[ -d $node ]] && continue
516 [[ -d $drive ]] && continue
Stephan Renatuse578eff2013-11-19 13:31:04 +0100517 sudo install -o ${STACK_USER} -g $USER_GROUP -d $drive
518 sudo install -o ${STACK_USER} -g $USER_GROUP -d $node_device
519 sudo chown -R ${STACK_USER}: ${node}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500520 done
521}
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200522# create_swift_accounts() - Set up standard swift accounts and extra
523# one for tests we do this by attaching all words in the account name
524# since we want to make it compatible with tempauth which use
525# underscores for separators.
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000526
527# Tenant User Roles
528# ------------------------------------------------------------------
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200529# service swift service
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000530# swifttenanttest1 swiftusertest1 admin
531# swifttenanttest1 swiftusertest3 anotherrole
532# swifttenanttest2 swiftusertest2 admin
533
Ian Wienandaee18c72014-02-21 15:35:08 +1100534function create_swift_accounts {
Sahid Orentino Ferdjaoui1814e672014-02-11 17:56:07 +0100535 # Defines specific passwords used by tools/create_userrc.sh
536 SWIFTUSERTEST1_PASSWORD=testing
537 SWIFTUSERTEST2_PASSWORD=testing2
538 SWIFTUSERTEST3_PASSWORD=testing3
539
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200540 KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql}
541
Steve Martinelli19685422014-01-24 13:02:26 -0600542 SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
543 ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200544
Steve Martinelli19685422014-01-24 13:02:26 -0600545 SWIFT_USER=$(openstack user create \
546 swift \
547 --password "$SERVICE_PASSWORD" \
548 --project $SERVICE_TENANT \
549 --email=swift@example.com \
550 | grep " id " | get_field 2)
551 openstack role add \
552 $ADMIN_ROLE \
553 --project $SERVICE_TENANT \
554 --user $SWIFT_USER
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200555
556 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Steve Martinelli19685422014-01-24 13:02:26 -0600557 SWIFT_SERVICE=$(openstack service create \
558 swift \
559 --type="object-store" \
560 --description="Swift Service" \
561 | grep " id " | get_field 2)
562 openstack endpoint create \
563 $SWIFT_SERVICE \
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200564 --region RegionOne \
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200565 --publicurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \
566 --adminurl "http://$SERVICE_HOST:8080" \
567 --internalurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s"
568 fi
569
Steve Martinelli19685422014-01-24 13:02:26 -0600570 SWIFT_TENANT_TEST1=$(openstack project create swifttenanttest1 | grep " id " | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500571 die_if_not_set $LINENO SWIFT_TENANT_TEST1 "Failure creating SWIFT_TENANT_TEST1"
Steve Martinelli19685422014-01-24 13:02:26 -0600572 SWIFT_USER_TEST1=$(openstack user create swiftusertest1 --password=$SWIFTUSERTEST1_PASSWORD \
573 --project "$SWIFT_TENANT_TEST1" --email=test@example.com | grep " id " | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500574 die_if_not_set $LINENO SWIFT_USER_TEST1 "Failure creating SWIFT_USER_TEST1"
Steve Martinelli19685422014-01-24 13:02:26 -0600575 openstack role add --user $SWIFT_USER_TEST1 --project $SWIFT_TENANT_TEST1 $ADMIN_ROLE
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000576
Steve Martinelli19685422014-01-24 13:02:26 -0600577 SWIFT_USER_TEST3=$(openstack user create swiftusertest3 --password=$SWIFTUSERTEST3_PASSWORD \
578 --project "$SWIFT_TENANT_TEST1" --email=test3@example.com | grep " id " | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500579 die_if_not_set $LINENO SWIFT_USER_TEST3 "Failure creating SWIFT_USER_TEST3"
Steve Martinelli19685422014-01-24 13:02:26 -0600580 openstack role add --user $SWIFT_USER_TEST3 --project $SWIFT_TENANT_TEST1 $ANOTHER_ROLE
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000581
Steve Martinelli19685422014-01-24 13:02:26 -0600582 SWIFT_TENANT_TEST2=$(openstack project create swifttenanttest2 | grep " id " | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500583 die_if_not_set $LINENO SWIFT_TENANT_TEST2 "Failure creating SWIFT_TENANT_TEST2"
Steve Martinelli19685422014-01-24 13:02:26 -0600584
585 SWIFT_USER_TEST2=$(openstack user create swiftusertest2 --password=$SWIFTUSERTEST2_PASSWORD \
586 --project "$SWIFT_TENANT_TEST2" --email=test2@example.com | grep " id " | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500587 die_if_not_set $LINENO SWIFT_USER_TEST2 "Failure creating SWIFT_USER_TEST2"
Steve Martinelli19685422014-01-24 13:02:26 -0600588 openstack role add --user $SWIFT_USER_TEST2 --project $SWIFT_TENANT_TEST2 $ADMIN_ROLE
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000589}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500590
Attila Fazekasece6a332012-11-29 14:19:41 +0100591# init_swift() - Initialize rings
Ian Wienandaee18c72014-02-21 15:35:08 +1100592function init_swift {
Attila Fazekasece6a332012-11-29 14:19:41 +0100593 local node_number
594 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100595 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100596
Dean Troyer1c6c1122013-03-27 17:40:53 -0500597 # Forcibly re-create the backing filesystem
598 create_swift_disk
599
Attila Fazekasece6a332012-11-29 14:19:41 +0100600 # This is where we create three different rings for swift with
601 # different object servers binding on different ports.
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500602 pushd ${SWIFT_CONF_DIR} >/dev/null && {
Attila Fazekasece6a332012-11-29 14:19:41 +0100603
604 rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
605
606 swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
607 swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
608 swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
609
610 for node_number in ${SWIFT_REPLICAS_SEQ}; do
611 swift-ring-builder object.builder add z${node_number}-127.0.0.1:$[OBJECT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
612 swift-ring-builder container.builder add z${node_number}-127.0.0.1:$[CONTAINER_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
613 swift-ring-builder account.builder add z${node_number}-127.0.0.1:$[ACCOUNT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
614 done
615 swift-ring-builder object.builder rebalance
616 swift-ring-builder container.builder rebalance
617 swift-ring-builder account.builder rebalance
618 } && popd >/dev/null
619
Dean Troyer64ab7742012-12-28 15:38:28 -0600620 # Create cache dir
621 sudo mkdir -p $SWIFT_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100622 sudo chown $STACK_USER $SWIFT_AUTH_CACHE_DIR
Dean Troyer64ab7742012-12-28 15:38:28 -0600623 rm -f $SWIFT_AUTH_CACHE_DIR/*
Attila Fazekasece6a332012-11-29 14:19:41 +0100624}
625
Ian Wienandaee18c72014-02-21 15:35:08 +1100626function install_swift {
Attila Fazekasece6a332012-11-29 14:19:41 +0100627 git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500628 setup_develop $SWIFT_DIR
zhang-hared98a5d02013-06-21 18:18:02 +0800629 if is_apache_enabled_service swift; then
630 install_apache_wsgi
631 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100632}
633
Ian Wienandaee18c72014-02-21 15:35:08 +1100634function install_swiftclient {
Attila Fazekasece6a332012-11-29 14:19:41 +0100635 git_clone $SWIFTCLIENT_REPO $SWIFTCLIENT_DIR $SWIFTCLIENT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500636 setup_develop $SWIFTCLIENT_DIR
Attila Fazekasece6a332012-11-29 14:19:41 +0100637}
638
Attila Fazekasece6a332012-11-29 14:19:41 +0100639# start_swift() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100640function start_swift {
Chmouel Boudjnah8ecbb382013-03-12 12:15:17 +0100641 # (re)start memcached to make sure we have a clean memcache.
642 restart_service memcached
643
Attila Fazekasece6a332012-11-29 14:19:41 +0100644 # Start rsync
Vincent Untzc18b9652012-12-04 12:36:34 +0100645 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100646 sudo /etc/init.d/rsync restart || :
Attila Fazekas0e57b962014-02-28 09:09:52 +0100647 elif [ -e /etc/xinetd.d/rsync ]; then
648 start_service xinetd
Attila Fazekasece6a332012-11-29 14:19:41 +0100649 else
Attila Fazekas0e57b962014-02-28 09:09:52 +0100650 start_service rsyncd
Attila Fazekasece6a332012-11-29 14:19:41 +0100651 fi
652
zhang-hared98a5d02013-06-21 18:18:02 +0800653 if is_apache_enabled_service swift; then
zhang-hared98a5d02013-06-21 18:18:02 +0800654 restart_apache_server
655 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest start
656 screen_it s-proxy "cd $SWIFT_DIR && sudo tail -f /var/log/$APACHE_NAME/proxy-server"
657 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
658 for type in object container account; do
659 screen_it s-${type} "cd $SWIFT_DIR && sudo tail -f /var/log/$APACHE_NAME/${type}-server-1"
660 done
661 fi
662 return 0
663 fi
664
Sean Dague101b4242013-10-22 08:47:11 -0400665 # By default with only one replica we are launching the proxy,
666 # container, account and object server in screen in foreground and
667 # other services in background. If we have SWIFT_REPLICAS set to something
668 # greater than one we first spawn all the swift services then kill the proxy
669 # service so we can run it in foreground in screen. ``swift-init ...
670 # {stop|restart}`` exits with '1' if no servers are running, ignore it just
671 # in case
672 swift-init --run-dir=${SWIFT_DATA_DIR}/run all restart || true
673 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100674 todo="object container account"
Sean Dague101b4242013-10-22 08:47:11 -0400675 fi
676 for type in proxy ${todo}; do
677 swift-init --run-dir=${SWIFT_DATA_DIR}/run ${type} stop || true
678 done
679 screen_it s-proxy "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONF_DIR}/proxy-server.conf -v"
680 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
681 for type in object container account; do
682 screen_it s-${type} "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-${type}-server ${SWIFT_CONF_DIR}/${type}-server/1.conf -v"
683 done
684 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100685}
686
687# stop_swift() - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +1100688function stop_swift {
zhang-hared98a5d02013-06-21 18:18:02 +0800689
690 if is_apache_enabled_service swift; then
691 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest stop && return 0
692 fi
693
Attila Fazekasece6a332012-11-29 14:19:41 +0100694 # screen normally killed by unstack.sh
Dean Troyer995eb922013-03-07 16:11:40 -0600695 if type -p swift-init >/dev/null; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100696 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
697 fi
Chmouel Boudjnahf36a9b22014-02-03 23:44:47 +0100698 # Dump all of the servers
Dean Troyer1eae3e12014-03-06 11:49:22 -0600699 # Maintain the iteration as screen_stop() has some desirable side-effects
700 for type in proxy object container account; do
701 screen_stop s-${type}
702 done
703 # Blast out any stragglers
Chmouel Boudjnahf36a9b22014-02-03 23:44:47 +0100704 pkill -f swift-
Attila Fazekasece6a332012-11-29 14:19:41 +0100705}
706
707# Restore xtrace
708$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400709
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100710# Tell emacs to use shell-script-mode
711## Local variables:
712## mode: shell-script
713## End: