blob: 03aa8f4a7c9ce5c4e214e8960b1e69601aca32e8 [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.
Chmouel Boudjnah1fba1aa2013-08-02 00:40:05 +020070# Default is ``staticweb, tempurl, formpost``
71SWIFT_EXTRAS_MIDDLEWARE=${SWIFT_EXTRAS_MIDDLEWARE:-tempurl 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
Attila Fazekasece6a332012-11-29 14:19:41 +0100106# Set ``OBJECT_PORT_BASE``, ``CONTAINER_PORT_BASE``, ``ACCOUNT_PORT_BASE``
107# Port bases used in port number calclution for the service "nodes"
108# The specified port number will be used, the additinal ports calculated by
109# base_port + node_num * 10
Dean Troyer1151d6f2013-03-29 14:06:52 -0500110OBJECT_PORT_BASE=${OBJECT_PORT_BASE:-6013}
111CONTAINER_PORT_BASE=${CONTAINER_PORT_BASE:-6011}
112ACCOUNT_PORT_BASE=${ACCOUNT_PORT_BASE:-6012}
Attila Fazekasece6a332012-11-29 14:19:41 +0100113
Dean Troyer6d04fd72012-12-21 11:03:37 -0600114
Dean Troyercc6b4432013-04-08 15:38:03 -0500115# Functions
116# ---------
Attila Fazekasece6a332012-11-29 14:19:41 +0100117
118# cleanup_swift() - Remove residual data files
119function cleanup_swift() {
Sean Dague101b4242013-10-22 08:47:11 -0400120 rm -f ${SWIFT_CONF_DIR}{*.builder,*.ring.gz,backups/*.builder,backups/*.ring.gz}
121 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
122 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
123 fi
124 if [[ -e ${SWIFT_DISK_IMAGE} ]]; then
125 rm ${SWIFT_DISK_IMAGE}
126 fi
127 rm -rf ${SWIFT_DATA_DIR}/run/
128 if is_apache_enabled_service swift; then
129 _cleanup_swift_apache_wsgi
130 fi
zhang-hared98a5d02013-06-21 18:18:02 +0800131}
132
133# _cleanup_swift_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
134function _cleanup_swift_apache_wsgi() {
135 sudo rm -f $SWIFT_APACHE_WSGI_DIR/*.wsgi
Jamie Lennox54707012013-09-17 12:07:48 +1000136 disable_apache_site proxy-server
zhang-hared98a5d02013-06-21 18:18:02 +0800137 for node_number in ${SWIFT_REPLICAS_SEQ}; do
138 for type in object container account; do
139 site_name=${type}-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000140 disable_apache_site ${site_name}
zhang-hared98a5d02013-06-21 18:18:02 +0800141 sudo rm -f /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site_name}
142 done
143 done
144}
145
146# _config_swift_apache_wsgi() - Set WSGI config files of Swift
147function _config_swift_apache_wsgi() {
148 sudo mkdir -p ${SWIFT_APACHE_WSGI_DIR}
149 local apache_vhost_dir=/etc/${APACHE_NAME}/$APACHE_CONF_DIR
150 local proxy_port=${SWIFT_DEFAULT_BIND_PORT:-8080}
151
152 # copy proxy vhost and wsgi file
153 sudo cp ${SWIFT_DIR}/examples/apache2/proxy-server.template ${apache_vhost_dir}/proxy-server
154 sudo sed -e "
155 /^#/d;/^$/d;
156 s/%PORT%/$proxy_port/g;
157 s/%SERVICENAME%/proxy-server/g;
158 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000159 s/%USER%/${STACK_USER}/g;
zhang-hared98a5d02013-06-21 18:18:02 +0800160 " -i ${apache_vhost_dir}/proxy-server
Jamie Lennox54707012013-09-17 12:07:48 +1000161 enable_apache_site proxy-server
zhang-hared98a5d02013-06-21 18:18:02 +0800162
163 sudo cp ${SWIFT_DIR}/examples/wsgi/proxy-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
164 sudo sed -e "
165 /^#/d;/^$/d;
166 s/%SERVICECONF%/proxy-server.conf/g;
167 " -i ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
zhang-hared98a5d02013-06-21 18:18:02 +0800168
169 # copy apache vhost file and set name and port
170 for node_number in ${SWIFT_REPLICAS_SEQ}; do
171 object_port=$[OBJECT_PORT_BASE + 10 * ($node_number - 1)]
172 container_port=$[CONTAINER_PORT_BASE + 10 * ($node_number - 1)]
173 account_port=$[ACCOUNT_PORT_BASE + 10 * ($node_number - 1)]
174
175 sudo cp ${SWIFT_DIR}/examples/apache2/object-server.template ${apache_vhost_dir}/object-server-${node_number}
176 sudo sed -e "
177 s/%PORT%/$object_port/g;
178 s/%SERVICENAME%/object-server-${node_number}/g;
179 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000180 s/%USER%/${STACK_USER}/g;
zhang-hared98a5d02013-06-21 18:18:02 +0800181 " -i ${apache_vhost_dir}/object-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000182 enable_apache_site object-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800183
184 sudo cp ${SWIFT_DIR}/examples/wsgi/object-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
185 sudo sed -e "
186 /^#/d;/^$/d;
187 s/%SERVICECONF%/object-server\/${node_number}.conf/g;
188 " -i ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
189
190 sudo cp ${SWIFT_DIR}/examples/apache2/container-server.template ${apache_vhost_dir}/container-server-${node_number}
191 sudo sed -e "
192 /^#/d;/^$/d;
193 s/%PORT%/$container_port/g;
194 s/%SERVICENAME%/container-server-${node_number}/g;
195 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000196 s/%USER%/${STACK_USER}/g;
zhang-hared98a5d02013-06-21 18:18:02 +0800197 " -i ${apache_vhost_dir}/container-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000198 enable_apache_site container-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800199
200 sudo cp ${SWIFT_DIR}/examples/wsgi/container-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
201 sudo sed -e "
202 /^#/d;/^$/d;
203 s/%SERVICECONF%/container-server\/${node_number}.conf/g;
204 " -i ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
205
206 sudo cp ${SWIFT_DIR}/examples/apache2/account-server.template ${apache_vhost_dir}/account-server-${node_number}
207 sudo sed -e "
Sean Dague101b4242013-10-22 08:47:11 -0400208 /^#/d;/^$/d;
zhang-hared98a5d02013-06-21 18:18:02 +0800209 s/%PORT%/$account_port/g;
210 s/%SERVICENAME%/account-server-${node_number}/g;
211 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000212 s/%USER%/${STACK_USER}/g;
zhang-hared98a5d02013-06-21 18:18:02 +0800213 " -i ${apache_vhost_dir}/account-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000214 enable_apache_site account-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800215
216 sudo cp ${SWIFT_DIR}/examples/wsgi/account-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
217 sudo sed -e "
Sean Dague101b4242013-10-22 08:47:11 -0400218 /^#/d;/^$/d;
zhang-hared98a5d02013-06-21 18:18:02 +0800219 s/%SERVICECONF%/account-server\/${node_number}.conf/g;
220 " -i ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
zhang-hared98a5d02013-06-21 18:18:02 +0800221 done
Attila Fazekasece6a332012-11-29 14:19:41 +0100222}
223
224# configure_swift() - Set config files, create data dirs and loop image
225function configure_swift() {
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200226 local swift_pipeline="${SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH}"
Attila Fazekasece6a332012-11-29 14:19:41 +0100227 local node_number
228 local swift_node_config
229 local swift_log_dir
230
Attila Fazekasece6a332012-11-29 14:19:41 +0100231 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100232 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100233
Dean Troyer1c6c1122013-03-27 17:40:53 -0500234 sudo mkdir -p ${SWIFT_CONF_DIR}/{object,container,account}-server
Stephan Renatuse578eff2013-11-19 13:31:04 +0100235 sudo chown -R ${STACK_USER}: ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100236
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500237 if [[ "$SWIFT_CONF_DIR" != "/etc/swift" ]]; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100238 # Some swift tools are hard-coded to use ``/etc/swift`` and are apparently not going to be fixed.
239 # Create a symlink if the config dir is moved
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500240 sudo ln -sf ${SWIFT_CONF_DIR} /etc/swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100241 fi
242
243 # Swift use rsync to synchronize between all the different
244 # partitions (which make more sense when you have a multi-node
245 # setup) we configure it with our version of rsync.
246 sed -e "
247 s/%GROUP%/${USER_GROUP}/;
Stephan Renatuse578eff2013-11-19 13:31:04 +0100248 s/%USER%/${STACK_USER}/;
Attila Fazekasece6a332012-11-29 14:19:41 +0100249 s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,;
250 " $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf
251 # rsyncd.conf just prepared for 4 nodes
Vincent Untzc18b9652012-12-04 12:36:34 +0100252 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100253 sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync
254 else
255 sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync
256 fi
257
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500258 SWIFT_CONFIG_PROXY_SERVER=${SWIFT_CONF_DIR}/proxy-server.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100259 cp ${SWIFT_DIR}/etc/proxy-server.conf-sample ${SWIFT_CONFIG_PROXY_SERVER}
260
261 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user
Stephan Renatuse578eff2013-11-19 13:31:04 +0100262 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user ${STACK_USER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100263
264 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500265 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100266
267 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers
268 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1
269
270 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level
271 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level DEBUG
272
273 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port
274 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT:-8080}
275
Joe Gordond254da52013-11-19 21:06:29 -0800276 # Devstack is commonly run in a small slow environment, so bump the
277 # timeouts up.
278 # node_timeout is how long between read operations a node takes to
279 # respond to the proxy server
280 # conn_timeout is all about how long it takes a connect() system call to
281 # return
282 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server node_timeout 120
283 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server conn_timeout 20
284
Cyril Roelandtd9883402013-09-27 15:16:51 +0000285 # Configure Ceilometer
286 if is_service_enabled ceilometer; then
287 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer use "egg:ceilometer#swift"
288 SWIFT_EXTRAS_MIDDLEWARE_LAST="${SWIFT_EXTRAS_MIDDLEWARE_LAST} ceilometer"
289 fi
290
Peter Portantecee4b3b2013-11-20 14:33:16 -0500291 # Restrict the length of auth tokens in the swift proxy-server logs.
292 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:proxy-logging reveal_sensitive_prefix ${SWIFT_LOG_TOKEN_LENGTH}
293
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000294 # By default Swift will be installed with keystone and tempauth middleware
295 # and add the swift3 middleware if its configured for it. The token for
Adam Spierscb961592013-10-05 12:11:07 +0100296 # tempauth would be prefixed with the reseller_prefix setting `TEMPAUTH_` the
297 # token for keystoneauth would have the standard reseller_prefix `AUTH_`
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000298 if is_service_enabled swift3;then
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200299 swift_pipeline+=" swift3 s3token "
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100300 fi
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000301 swift_pipeline+=" authtoken keystoneauth tempauth "
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100302 sed -i "/^pipeline/ { s/tempauth/${swift_pipeline} ${SWIFT_EXTRAS_MIDDLEWARE}/ ;}" ${SWIFT_CONFIG_PROXY_SERVER}
Cyril Roelandtd9883402013-09-27 15:16:51 +0000303 sed -i "/^pipeline/ { s/proxy-server/${SWIFT_EXTRAS_MIDDLEWARE_LAST} proxy-server/ ; }" ${SWIFT_CONFIG_PROXY_SERVER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100304
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000305 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth account_autocreate
Attila Fazekasece6a332012-11-29 14:19:41 +0100306 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server account_autocreate true
307
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000308 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix
309 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix "TEMPAUTH"
310
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200311 # Configure Crossdomain
312 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:crossdomain use "egg:swift#crossdomain"
313
Attila Fazekasece6a332012-11-29 14:19:41 +0100314 # Configure Keystone
315 sed -i '/^# \[filter:authtoken\]/,/^# \[filter:keystoneauth\]$/ s/^#[ \t]*//' ${SWIFT_CONFIG_PROXY_SERVER}
316 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_host $KEYSTONE_AUTH_HOST
317 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_port $KEYSTONE_AUTH_PORT
318 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
319 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
320 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
321 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_user swift
322 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_password $SERVICE_PASSWORD
Dean Troyer64ab7742012-12-28 15:38:28 -0600323 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken signing_dir $SWIFT_AUTH_CACHE_DIR
Peter Portante8afc8932013-11-20 17:34:39 -0500324 # This causes the authtoken middleware to use the same python logging
325 # adapter provided by the swift proxy-server, so that request transaction
326 # IDs will included in all of its log messages.
327 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken log_name swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100328
329 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use
330 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles
331 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin"
332
333 if is_service_enabled swift3; then
334 cat <<EOF >>${SWIFT_CONFIG_PROXY_SERVER}
335# NOTE(chmou): s3token middleware is not updated yet to use only
336# username and password.
337[filter:s3token]
338paste.filter_factory = keystone.middleware.s3_token:filter_factory
339auth_port = ${KEYSTONE_AUTH_PORT}
340auth_host = ${KEYSTONE_AUTH_HOST}
341auth_protocol = ${KEYSTONE_AUTH_PROTOCOL}
342auth_token = ${SERVICE_TOKEN}
343admin_token = ${SERVICE_TOKEN}
344
345[filter:swift3]
346use = egg:swift3#swift3
347EOF
348 fi
349
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500350 cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONF_DIR}/swift.conf
351 iniset ${SWIFT_CONF_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH}
Attila Fazekasece6a332012-11-29 14:19:41 +0100352
Peter Portantecee4b3b2013-11-20 14:33:16 -0500353 # This function generates an object/container/account configuration
Attila Fazekasece6a332012-11-29 14:19:41 +0100354 # emulating 4 nodes on different ports
355 function generate_swift_config() {
356 local swift_node_config=$1
357 local node_id=$2
358 local bind_port=$3
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000359 local server_type=$4
Attila Fazekasece6a332012-11-29 14:19:41 +0100360
361 log_facility=$[ node_id - 1 ]
362 node_path=${SWIFT_DATA_DIR}/${node_number}
363
364 iniuncomment ${swift_node_config} DEFAULT user
Stephan Renatuse578eff2013-11-19 13:31:04 +0100365 iniset ${swift_node_config} DEFAULT user ${STACK_USER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100366
367 iniuncomment ${swift_node_config} DEFAULT bind_port
368 iniset ${swift_node_config} DEFAULT bind_port ${bind_port}
369
370 iniuncomment ${swift_node_config} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500371 iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100372
373 iniuncomment ${swift_node_config} DEFAULT devices
374 iniset ${swift_node_config} DEFAULT devices ${node_path}
375
376 iniuncomment ${swift_node_config} DEFAULT log_facility
377 iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility}
378
Chmouel Boudjnah86d9aed2013-12-10 12:24:16 +0000379 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers
380 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1
381
Chmouel Boudjnah82c09962013-07-16 07:16:07 +0000382 iniuncomment ${swift_node_config} DEFAULT disable_fallocate
383 iniset ${swift_node_config} DEFAULT disable_fallocate true
384
Attila Fazekasece6a332012-11-29 14:19:41 +0100385 iniuncomment ${swift_node_config} DEFAULT mount_check
386 iniset ${swift_node_config} DEFAULT mount_check false
387
388 iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode
389 iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes
390 }
391
392 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500393 swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100394 cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000395 generate_swift_config ${swift_node_config} ${node_number} $[OBJECT_PORT_BASE + 10 * (node_number - 1)] object
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000396 iniset ${swift_node_config} filter:recon recon_cache_path ${SWIFT_DATA_DIR}/cache
397 # Using a sed and not iniset/iniuncomment because we want to a global
398 # modification and make sure it works for new sections.
399 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100400
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500401 swift_node_config=${SWIFT_CONF_DIR}/container-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100402 cp ${SWIFT_DIR}/etc/container-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000403 generate_swift_config ${swift_node_config} ${node_number} $[CONTAINER_PORT_BASE + 10 * (node_number - 1)] container
Attila Fazekas83e10952012-11-30 23:28:07 +0100404 iniuncomment ${swift_node_config} app:container-server allow_versions
405 iniset ${swift_node_config} app:container-server allow_versions "true"
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000406 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100407
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500408 swift_node_config=${SWIFT_CONF_DIR}/account-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100409 cp ${SWIFT_DIR}/etc/account-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000410 generate_swift_config ${swift_node_config} ${node_number} $[ACCOUNT_PORT_BASE + 10 * (node_number - 1)] account
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000411 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100412 done
413
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000414 # Set new accounts in tempauth to match keystone tenant/user (to make testing easier)
415 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest1 "testing .admin"
416 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest2_swiftusertest2 "testing2 .admin"
417 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest3 "testing3 .admin"
418
419 testfile=${SWIFT_CONF_DIR}/test.conf
420 cp ${SWIFT_DIR}/test/sample.conf ${testfile}
421
422 # Set accounts for functional tests
423 iniset ${testfile} func_test account swifttenanttest1
424 iniset ${testfile} func_test username swiftusertest1
425 iniset ${testfile} func_test username3 swiftusertest3
426 iniset ${testfile} func_test account2 swifttenanttest2
427 iniset ${testfile} func_test username2 swiftusertest2
428
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000429 if is_service_enabled key;then
430 iniuncomment ${testfile} func_test auth_version
431 iniset ${testfile} func_test auth_host ${KEYSTONE_SERVICE_HOST}
432 iniset ${testfile} func_test auth_port ${KEYSTONE_AUTH_PORT}
433 iniset ${testfile} func_test auth_prefix /v2.0/
434 fi
435
Attila Fazekasece6a332012-11-29 14:19:41 +0100436 swift_log_dir=${SWIFT_DATA_DIR}/logs
437 rm -rf ${swift_log_dir}
438 mkdir -p ${swift_log_dir}/hourly
Stephan Renatuse578eff2013-11-19 13:31:04 +0100439 sudo chown -R ${STACK_USER}:adm ${swift_log_dir}
Attila Fazekasece6a332012-11-29 14:19:41 +0100440 sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \
441 tee /etc/rsyslog.d/10-swift.conf
zhang-hared98a5d02013-06-21 18:18:02 +0800442 if is_apache_enabled_service swift; then
443 _config_swift_apache_wsgi
444 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100445}
446
Dean Troyer1c6c1122013-03-27 17:40:53 -0500447# create_swift_disk - Create Swift backing disk
448function create_swift_disk() {
449 local node_number
450
451 # First do a bit of setup by creating the directories and
452 # changing the permissions so we can run it as our user.
453
Stephan Renatuse578eff2013-11-19 13:31:04 +0100454 USER_GROUP=$(id -g ${STACK_USER})
Dean Troyer1c6c1122013-03-27 17:40:53 -0500455 sudo mkdir -p ${SWIFT_DATA_DIR}/{drives,cache,run,logs}
Stephan Renatuse578eff2013-11-19 13:31:04 +0100456 sudo chown -R ${STACK_USER}:${USER_GROUP} ${SWIFT_DATA_DIR}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500457
458 # Create a loopback disk and format it to XFS.
Attila Fazekase6024412013-09-15 18:38:48 +0200459 if [[ -e ${SWIFT_DISK_IMAGE} ]]; then
Dean Troyer1c6c1122013-03-27 17:40:53 -0500460 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
461 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
Attila Fazekase6024412013-09-15 18:38:48 +0200462 sudo rm -f ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500463 fi
464 fi
465
466 mkdir -p ${SWIFT_DATA_DIR}/drives/images
Attila Fazekase6024412013-09-15 18:38:48 +0200467 sudo touch ${SWIFT_DISK_IMAGE}
Stephan Renatuse578eff2013-11-19 13:31:04 +0100468 sudo chown ${STACK_USER}: ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500469
Attila Fazekase6024412013-09-15 18:38:48 +0200470 truncate -s ${SWIFT_LOOPBACK_DISK_SIZE} ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500471
472 # Make a fresh XFS filesystem
Attila Fazekase6024412013-09-15 18:38:48 +0200473 mkfs.xfs -f -i size=1024 ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500474
475 # Mount the disk with mount options to make it as efficient as possible
476 mkdir -p ${SWIFT_DATA_DIR}/drives/sdb1
477 if ! egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
478 sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8 \
Attila Fazekase6024412013-09-15 18:38:48 +0200479 ${SWIFT_DISK_IMAGE} ${SWIFT_DATA_DIR}/drives/sdb1
Dean Troyer1c6c1122013-03-27 17:40:53 -0500480 fi
481
482 # Create a link to the above mount and
483 # create all of the directories needed to emulate a few different servers
484 for node_number in ${SWIFT_REPLICAS_SEQ}; do
485 sudo ln -sf ${SWIFT_DATA_DIR}/drives/sdb1/$node_number ${SWIFT_DATA_DIR}/$node_number;
486 drive=${SWIFT_DATA_DIR}/drives/sdb1/${node_number}
487 node=${SWIFT_DATA_DIR}/${node_number}/node
488 node_device=${node}/sdb1
489 [[ -d $node ]] && continue
490 [[ -d $drive ]] && continue
Stephan Renatuse578eff2013-11-19 13:31:04 +0100491 sudo install -o ${STACK_USER} -g $USER_GROUP -d $drive
492 sudo install -o ${STACK_USER} -g $USER_GROUP -d $node_device
493 sudo chown -R ${STACK_USER}: ${node}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500494 done
495}
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200496# create_swift_accounts() - Set up standard swift accounts and extra
497# one for tests we do this by attaching all words in the account name
498# since we want to make it compatible with tempauth which use
499# underscores for separators.
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000500
501# Tenant User Roles
502# ------------------------------------------------------------------
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200503# service swift service
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000504# swifttenanttest1 swiftusertest1 admin
505# swifttenanttest1 swiftusertest3 anotherrole
506# swifttenanttest2 swiftusertest2 admin
507
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000508function create_swift_accounts() {
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200509 KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql}
510
511 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
512 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
513
514 SWIFT_USER=$(keystone user-create --name=swift --pass="$SERVICE_PASSWORD" \
515 --tenant_id $SERVICE_TENANT --email=swift@example.com | grep " id " | get_field 2)
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200516 keystone user-role-add --tenant-id $SERVICE_TENANT --user-id $SWIFT_USER --role-id $ADMIN_ROLE
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200517
518 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
519 SWIFT_SERVICE=$(keystone service-create --name=swift --type="object-store" \
520 --description="Swift Service" | grep " id " | get_field 2)
521 keystone endpoint-create \
522 --region RegionOne \
523 --service_id $SWIFT_SERVICE \
524 --publicurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \
525 --adminurl "http://$SERVICE_HOST:8080" \
526 --internalurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s"
527 fi
528
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000529 SWIFT_TENANT_TEST1=$(keystone tenant-create --name=swifttenanttest1 | grep " id " | get_field 2)
530 SWIFT_USER_TEST1=$(keystone user-create --name=swiftusertest1 --pass=testing --email=test@example.com | grep " id " | get_field 2)
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200531 keystone user-role-add --user-id $SWIFT_USER_TEST1 --role-id $ADMIN_ROLE --tenant-id $SWIFT_TENANT_TEST1
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000532
533 SWIFT_USER_TEST3=$(keystone user-create --name=swiftusertest3 --pass=testing3 --email=test3@example.com | grep " id " | get_field 2)
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200534 keystone user-role-add --user-id $SWIFT_USER_TEST3 --role-id $ANOTHER_ROLE --tenant-id $SWIFT_TENANT_TEST1
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000535
536 SWIFT_TENANT_TEST2=$(keystone tenant-create --name=swifttenanttest2 | grep " id " | get_field 2)
537 SWIFT_USER_TEST2=$(keystone user-create --name=swiftusertest2 --pass=testing2 --email=test2@example.com | grep " id " | get_field 2)
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200538 keystone user-role-add --user-id $SWIFT_USER_TEST2 --role-id $ADMIN_ROLE --tenant-id $SWIFT_TENANT_TEST2
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000539}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500540
Attila Fazekasece6a332012-11-29 14:19:41 +0100541# init_swift() - Initialize rings
542function init_swift() {
543 local node_number
544 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100545 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100546
Dean Troyer1c6c1122013-03-27 17:40:53 -0500547 # Forcibly re-create the backing filesystem
548 create_swift_disk
549
Attila Fazekasece6a332012-11-29 14:19:41 +0100550 # This is where we create three different rings for swift with
551 # different object servers binding on different ports.
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500552 pushd ${SWIFT_CONF_DIR} >/dev/null && {
Attila Fazekasece6a332012-11-29 14:19:41 +0100553
554 rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
555
556 swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
557 swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
558 swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
559
560 for node_number in ${SWIFT_REPLICAS_SEQ}; do
561 swift-ring-builder object.builder add z${node_number}-127.0.0.1:$[OBJECT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
562 swift-ring-builder container.builder add z${node_number}-127.0.0.1:$[CONTAINER_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
563 swift-ring-builder account.builder add z${node_number}-127.0.0.1:$[ACCOUNT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
564 done
565 swift-ring-builder object.builder rebalance
566 swift-ring-builder container.builder rebalance
567 swift-ring-builder account.builder rebalance
568 } && popd >/dev/null
569
Dean Troyer64ab7742012-12-28 15:38:28 -0600570 # Create cache dir
571 sudo mkdir -p $SWIFT_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100572 sudo chown $STACK_USER $SWIFT_AUTH_CACHE_DIR
Dean Troyer64ab7742012-12-28 15:38:28 -0600573 rm -f $SWIFT_AUTH_CACHE_DIR/*
Attila Fazekasece6a332012-11-29 14:19:41 +0100574}
575
576function install_swift() {
577 git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500578 setup_develop $SWIFT_DIR
zhang-hared98a5d02013-06-21 18:18:02 +0800579 if is_apache_enabled_service swift; then
580 install_apache_wsgi
581 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100582}
583
584function install_swiftclient() {
585 git_clone $SWIFTCLIENT_REPO $SWIFTCLIENT_DIR $SWIFTCLIENT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500586 setup_develop $SWIFTCLIENT_DIR
Attila Fazekasece6a332012-11-29 14:19:41 +0100587}
588
Attila Fazekasece6a332012-11-29 14:19:41 +0100589# start_swift() - Start running processes, including screen
590function start_swift() {
591 # (re)start rsyslog
592 restart_service rsyslog
Chmouel Boudjnah8ecbb382013-03-12 12:15:17 +0100593 # (re)start memcached to make sure we have a clean memcache.
594 restart_service memcached
595
Attila Fazekasece6a332012-11-29 14:19:41 +0100596 # Start rsync
Vincent Untzc18b9652012-12-04 12:36:34 +0100597 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100598 sudo /etc/init.d/rsync restart || :
599 else
600 sudo systemctl start xinetd.service
601 fi
602
zhang-hared98a5d02013-06-21 18:18:02 +0800603 if is_apache_enabled_service swift; then
zhang-hared98a5d02013-06-21 18:18:02 +0800604 restart_apache_server
605 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest start
606 screen_it s-proxy "cd $SWIFT_DIR && sudo tail -f /var/log/$APACHE_NAME/proxy-server"
607 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
608 for type in object container account; do
609 screen_it s-${type} "cd $SWIFT_DIR && sudo tail -f /var/log/$APACHE_NAME/${type}-server-1"
610 done
611 fi
612 return 0
613 fi
614
Sean Dague101b4242013-10-22 08:47:11 -0400615 # By default with only one replica we are launching the proxy,
616 # container, account and object server in screen in foreground and
617 # other services in background. If we have SWIFT_REPLICAS set to something
618 # greater than one we first spawn all the swift services then kill the proxy
619 # service so we can run it in foreground in screen. ``swift-init ...
620 # {stop|restart}`` exits with '1' if no servers are running, ignore it just
621 # in case
622 swift-init --run-dir=${SWIFT_DATA_DIR}/run all restart || true
623 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100624 todo="object container account"
Sean Dague101b4242013-10-22 08:47:11 -0400625 fi
626 for type in proxy ${todo}; do
627 swift-init --run-dir=${SWIFT_DATA_DIR}/run ${type} stop || true
628 done
629 screen_it s-proxy "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONF_DIR}/proxy-server.conf -v"
630 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
631 for type in object container account; do
632 screen_it s-${type} "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-${type}-server ${SWIFT_CONF_DIR}/${type}-server/1.conf -v"
633 done
634 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100635}
636
637# stop_swift() - Stop running processes (non-screen)
638function stop_swift() {
zhang-hared98a5d02013-06-21 18:18:02 +0800639
640 if is_apache_enabled_service swift; then
641 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest stop && return 0
642 fi
643
Attila Fazekasece6a332012-11-29 14:19:41 +0100644 # screen normally killed by unstack.sh
Dean Troyer995eb922013-03-07 16:11:40 -0600645 if type -p swift-init >/dev/null; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100646 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
647 fi
Dean Troyer995eb922013-03-07 16:11:40 -0600648 # Dump the proxy server
649 sudo pkill -f swift-proxy-server
Attila Fazekasece6a332012-11-29 14:19:41 +0100650}
651
652# Restore xtrace
653$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400654
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100655# Tell emacs to use shell-script-mode
656## Local variables:
657## mode: shell-script
658## End: