blob: 44c230be93736b55f112c89bbb36e5529bd866b0 [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
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000319 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken cafile $KEYSTONE_SSL_CA
Attila Fazekasece6a332012-11-29 14:19:41 +0100320 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
321 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
322 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_user swift
323 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_password $SERVICE_PASSWORD
Dean Troyer64ab7742012-12-28 15:38:28 -0600324 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken signing_dir $SWIFT_AUTH_CACHE_DIR
Peter Portante8afc8932013-11-20 17:34:39 -0500325 # This causes the authtoken middleware to use the same python logging
326 # adapter provided by the swift proxy-server, so that request transaction
327 # IDs will included in all of its log messages.
328 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken log_name swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100329
330 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use
331 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles
332 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin"
333
334 if is_service_enabled swift3; then
335 cat <<EOF >>${SWIFT_CONFIG_PROXY_SERVER}
336# NOTE(chmou): s3token middleware is not updated yet to use only
337# username and password.
338[filter:s3token]
339paste.filter_factory = keystone.middleware.s3_token:filter_factory
340auth_port = ${KEYSTONE_AUTH_PORT}
341auth_host = ${KEYSTONE_AUTH_HOST}
342auth_protocol = ${KEYSTONE_AUTH_PROTOCOL}
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000343cafile = ${KEYSTONE_SSL_CA}
Attila Fazekasece6a332012-11-29 14:19:41 +0100344auth_token = ${SERVICE_TOKEN}
345admin_token = ${SERVICE_TOKEN}
346
347[filter:swift3]
348use = egg:swift3#swift3
349EOF
350 fi
351
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500352 cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONF_DIR}/swift.conf
353 iniset ${SWIFT_CONF_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH}
Attila Fazekasece6a332012-11-29 14:19:41 +0100354
Peter Portantecee4b3b2013-11-20 14:33:16 -0500355 # This function generates an object/container/account configuration
Attila Fazekasece6a332012-11-29 14:19:41 +0100356 # emulating 4 nodes on different ports
357 function generate_swift_config() {
358 local swift_node_config=$1
359 local node_id=$2
360 local bind_port=$3
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000361 local server_type=$4
Attila Fazekasece6a332012-11-29 14:19:41 +0100362
363 log_facility=$[ node_id - 1 ]
364 node_path=${SWIFT_DATA_DIR}/${node_number}
365
366 iniuncomment ${swift_node_config} DEFAULT user
Stephan Renatuse578eff2013-11-19 13:31:04 +0100367 iniset ${swift_node_config} DEFAULT user ${STACK_USER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100368
369 iniuncomment ${swift_node_config} DEFAULT bind_port
370 iniset ${swift_node_config} DEFAULT bind_port ${bind_port}
371
372 iniuncomment ${swift_node_config} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500373 iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100374
375 iniuncomment ${swift_node_config} DEFAULT devices
376 iniset ${swift_node_config} DEFAULT devices ${node_path}
377
378 iniuncomment ${swift_node_config} DEFAULT log_facility
379 iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility}
380
Chmouel Boudjnah63d9f3e2013-12-21 01:19:09 -0800381 iniuncomment ${swift_node_config} DEFAULT workers
382 iniset ${swift_node_config} DEFAULT workers 1
Chmouel Boudjnah86d9aed2013-12-10 12:24:16 +0000383
Chmouel Boudjnah82c09962013-07-16 07:16:07 +0000384 iniuncomment ${swift_node_config} DEFAULT disable_fallocate
385 iniset ${swift_node_config} DEFAULT disable_fallocate true
386
Attila Fazekasece6a332012-11-29 14:19:41 +0100387 iniuncomment ${swift_node_config} DEFAULT mount_check
388 iniset ${swift_node_config} DEFAULT mount_check false
389
390 iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode
391 iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes
392 }
393
394 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500395 swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100396 cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000397 generate_swift_config ${swift_node_config} ${node_number} $[OBJECT_PORT_BASE + 10 * (node_number - 1)] object
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000398 iniset ${swift_node_config} filter:recon recon_cache_path ${SWIFT_DATA_DIR}/cache
399 # Using a sed and not iniset/iniuncomment because we want to a global
400 # modification and make sure it works for new sections.
401 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100402
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500403 swift_node_config=${SWIFT_CONF_DIR}/container-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100404 cp ${SWIFT_DIR}/etc/container-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000405 generate_swift_config ${swift_node_config} ${node_number} $[CONTAINER_PORT_BASE + 10 * (node_number - 1)] container
Attila Fazekas83e10952012-11-30 23:28:07 +0100406 iniuncomment ${swift_node_config} app:container-server allow_versions
407 iniset ${swift_node_config} app:container-server allow_versions "true"
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000408 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100409
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500410 swift_node_config=${SWIFT_CONF_DIR}/account-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100411 cp ${SWIFT_DIR}/etc/account-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000412 generate_swift_config ${swift_node_config} ${node_number} $[ACCOUNT_PORT_BASE + 10 * (node_number - 1)] account
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000413 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100414 done
415
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000416 # Set new accounts in tempauth to match keystone tenant/user (to make testing easier)
417 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest1 "testing .admin"
418 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest2_swiftusertest2 "testing2 .admin"
419 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest3 "testing3 .admin"
420
421 testfile=${SWIFT_CONF_DIR}/test.conf
422 cp ${SWIFT_DIR}/test/sample.conf ${testfile}
423
424 # Set accounts for functional tests
425 iniset ${testfile} func_test account swifttenanttest1
426 iniset ${testfile} func_test username swiftusertest1
427 iniset ${testfile} func_test username3 swiftusertest3
428 iniset ${testfile} func_test account2 swifttenanttest2
429 iniset ${testfile} func_test username2 swiftusertest2
430
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000431 if is_service_enabled key;then
432 iniuncomment ${testfile} func_test auth_version
433 iniset ${testfile} func_test auth_host ${KEYSTONE_SERVICE_HOST}
434 iniset ${testfile} func_test auth_port ${KEYSTONE_AUTH_PORT}
435 iniset ${testfile} func_test auth_prefix /v2.0/
436 fi
437
Attila Fazekasece6a332012-11-29 14:19:41 +0100438 swift_log_dir=${SWIFT_DATA_DIR}/logs
439 rm -rf ${swift_log_dir}
440 mkdir -p ${swift_log_dir}/hourly
Stephan Renatuse578eff2013-11-19 13:31:04 +0100441 sudo chown -R ${STACK_USER}:adm ${swift_log_dir}
Attila Fazekasece6a332012-11-29 14:19:41 +0100442 sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \
443 tee /etc/rsyslog.d/10-swift.conf
zhang-hared98a5d02013-06-21 18:18:02 +0800444 if is_apache_enabled_service swift; then
445 _config_swift_apache_wsgi
446 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100447}
448
Dean Troyer1c6c1122013-03-27 17:40:53 -0500449# create_swift_disk - Create Swift backing disk
450function create_swift_disk() {
451 local node_number
452
453 # First do a bit of setup by creating the directories and
454 # changing the permissions so we can run it as our user.
455
Stephan Renatuse578eff2013-11-19 13:31:04 +0100456 USER_GROUP=$(id -g ${STACK_USER})
Dean Troyer1c6c1122013-03-27 17:40:53 -0500457 sudo mkdir -p ${SWIFT_DATA_DIR}/{drives,cache,run,logs}
Stephan Renatuse578eff2013-11-19 13:31:04 +0100458 sudo chown -R ${STACK_USER}:${USER_GROUP} ${SWIFT_DATA_DIR}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500459
460 # Create a loopback disk and format it to XFS.
Attila Fazekase6024412013-09-15 18:38:48 +0200461 if [[ -e ${SWIFT_DISK_IMAGE} ]]; then
Dean Troyer1c6c1122013-03-27 17:40:53 -0500462 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
463 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
Attila Fazekase6024412013-09-15 18:38:48 +0200464 sudo rm -f ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500465 fi
466 fi
467
468 mkdir -p ${SWIFT_DATA_DIR}/drives/images
Attila Fazekase6024412013-09-15 18:38:48 +0200469 sudo touch ${SWIFT_DISK_IMAGE}
Stephan Renatuse578eff2013-11-19 13:31:04 +0100470 sudo chown ${STACK_USER}: ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500471
Attila Fazekase6024412013-09-15 18:38:48 +0200472 truncate -s ${SWIFT_LOOPBACK_DISK_SIZE} ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500473
474 # Make a fresh XFS filesystem
Attila Fazekase6024412013-09-15 18:38:48 +0200475 mkfs.xfs -f -i size=1024 ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500476
477 # Mount the disk with mount options to make it as efficient as possible
478 mkdir -p ${SWIFT_DATA_DIR}/drives/sdb1
479 if ! egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
480 sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8 \
Attila Fazekase6024412013-09-15 18:38:48 +0200481 ${SWIFT_DISK_IMAGE} ${SWIFT_DATA_DIR}/drives/sdb1
Dean Troyer1c6c1122013-03-27 17:40:53 -0500482 fi
483
484 # Create a link to the above mount and
485 # create all of the directories needed to emulate a few different servers
486 for node_number in ${SWIFT_REPLICAS_SEQ}; do
487 sudo ln -sf ${SWIFT_DATA_DIR}/drives/sdb1/$node_number ${SWIFT_DATA_DIR}/$node_number;
488 drive=${SWIFT_DATA_DIR}/drives/sdb1/${node_number}
489 node=${SWIFT_DATA_DIR}/${node_number}/node
490 node_device=${node}/sdb1
491 [[ -d $node ]] && continue
492 [[ -d $drive ]] && continue
Stephan Renatuse578eff2013-11-19 13:31:04 +0100493 sudo install -o ${STACK_USER} -g $USER_GROUP -d $drive
494 sudo install -o ${STACK_USER} -g $USER_GROUP -d $node_device
495 sudo chown -R ${STACK_USER}: ${node}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500496 done
497}
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200498# create_swift_accounts() - Set up standard swift accounts and extra
499# one for tests we do this by attaching all words in the account name
500# since we want to make it compatible with tempauth which use
501# underscores for separators.
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000502
503# Tenant User Roles
504# ------------------------------------------------------------------
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200505# service swift service
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000506# swifttenanttest1 swiftusertest1 admin
507# swifttenanttest1 swiftusertest3 anotherrole
508# swifttenanttest2 swiftusertest2 admin
509
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000510function create_swift_accounts() {
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200511 KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql}
512
513 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
514 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
515
516 SWIFT_USER=$(keystone user-create --name=swift --pass="$SERVICE_PASSWORD" \
Dirk Mueller25049cd2014-01-09 13:53:52 +0100517 --tenant-id $SERVICE_TENANT --email=swift@example.com | grep " id " | get_field 2)
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200518 keystone user-role-add --tenant-id $SERVICE_TENANT --user-id $SWIFT_USER --role-id $ADMIN_ROLE
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200519
520 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
521 SWIFT_SERVICE=$(keystone service-create --name=swift --type="object-store" \
522 --description="Swift Service" | grep " id " | get_field 2)
523 keystone endpoint-create \
524 --region RegionOne \
525 --service_id $SWIFT_SERVICE \
526 --publicurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \
527 --adminurl "http://$SERVICE_HOST:8080" \
528 --internalurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s"
529 fi
530
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000531 SWIFT_TENANT_TEST1=$(keystone tenant-create --name=swifttenanttest1 | grep " id " | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500532 die_if_not_set $LINENO SWIFT_TENANT_TEST1 "Failure creating SWIFT_TENANT_TEST1"
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000533 SWIFT_USER_TEST1=$(keystone user-create --name=swiftusertest1 --pass=testing --email=test@example.com | grep " id " | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500534 die_if_not_set $LINENO SWIFT_USER_TEST1 "Failure creating SWIFT_USER_TEST1"
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200535 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 +0000536
537 SWIFT_USER_TEST3=$(keystone user-create --name=swiftusertest3 --pass=testing3 --email=test3@example.com | grep " id " | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500538 die_if_not_set $LINENO SWIFT_USER_TEST3 "Failure creating SWIFT_USER_TEST3"
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200539 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 +0000540
541 SWIFT_TENANT_TEST2=$(keystone tenant-create --name=swifttenanttest2 | grep " id " | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500542 die_if_not_set $LINENO SWIFT_TENANT_TEST2 "Failure creating SWIFT_TENANT_TEST2"
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000543 SWIFT_USER_TEST2=$(keystone user-create --name=swiftusertest2 --pass=testing2 --email=test2@example.com | grep " id " | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500544 die_if_not_set $LINENO SWIFT_USER_TEST2 "Failure creating SWIFT_USER_TEST2"
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200545 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 +0000546}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500547
Attila Fazekasece6a332012-11-29 14:19:41 +0100548# init_swift() - Initialize rings
549function init_swift() {
550 local node_number
551 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100552 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100553
Dean Troyer1c6c1122013-03-27 17:40:53 -0500554 # Forcibly re-create the backing filesystem
555 create_swift_disk
556
Attila Fazekasece6a332012-11-29 14:19:41 +0100557 # This is where we create three different rings for swift with
558 # different object servers binding on different ports.
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500559 pushd ${SWIFT_CONF_DIR} >/dev/null && {
Attila Fazekasece6a332012-11-29 14:19:41 +0100560
561 rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
562
563 swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
564 swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
565 swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
566
567 for node_number in ${SWIFT_REPLICAS_SEQ}; do
568 swift-ring-builder object.builder add z${node_number}-127.0.0.1:$[OBJECT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
569 swift-ring-builder container.builder add z${node_number}-127.0.0.1:$[CONTAINER_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
570 swift-ring-builder account.builder add z${node_number}-127.0.0.1:$[ACCOUNT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
571 done
572 swift-ring-builder object.builder rebalance
573 swift-ring-builder container.builder rebalance
574 swift-ring-builder account.builder rebalance
575 } && popd >/dev/null
576
Dean Troyer64ab7742012-12-28 15:38:28 -0600577 # Create cache dir
578 sudo mkdir -p $SWIFT_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100579 sudo chown $STACK_USER $SWIFT_AUTH_CACHE_DIR
Dean Troyer64ab7742012-12-28 15:38:28 -0600580 rm -f $SWIFT_AUTH_CACHE_DIR/*
Attila Fazekasece6a332012-11-29 14:19:41 +0100581}
582
583function install_swift() {
584 git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500585 setup_develop $SWIFT_DIR
zhang-hared98a5d02013-06-21 18:18:02 +0800586 if is_apache_enabled_service swift; then
587 install_apache_wsgi
588 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100589}
590
591function install_swiftclient() {
592 git_clone $SWIFTCLIENT_REPO $SWIFTCLIENT_DIR $SWIFTCLIENT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500593 setup_develop $SWIFTCLIENT_DIR
Attila Fazekasece6a332012-11-29 14:19:41 +0100594}
595
Attila Fazekasece6a332012-11-29 14:19:41 +0100596# start_swift() - Start running processes, including screen
597function start_swift() {
598 # (re)start rsyslog
599 restart_service rsyslog
Chmouel Boudjnah8ecbb382013-03-12 12:15:17 +0100600 # (re)start memcached to make sure we have a clean memcache.
601 restart_service memcached
602
Attila Fazekasece6a332012-11-29 14:19:41 +0100603 # Start rsync
Vincent Untzc18b9652012-12-04 12:36:34 +0100604 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100605 sudo /etc/init.d/rsync restart || :
606 else
607 sudo systemctl start xinetd.service
608 fi
609
zhang-hared98a5d02013-06-21 18:18:02 +0800610 if is_apache_enabled_service swift; then
zhang-hared98a5d02013-06-21 18:18:02 +0800611 restart_apache_server
612 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest start
613 screen_it s-proxy "cd $SWIFT_DIR && sudo tail -f /var/log/$APACHE_NAME/proxy-server"
614 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
615 for type in object container account; do
616 screen_it s-${type} "cd $SWIFT_DIR && sudo tail -f /var/log/$APACHE_NAME/${type}-server-1"
617 done
618 fi
619 return 0
620 fi
621
Sean Dague101b4242013-10-22 08:47:11 -0400622 # By default with only one replica we are launching the proxy,
623 # container, account and object server in screen in foreground and
624 # other services in background. If we have SWIFT_REPLICAS set to something
625 # greater than one we first spawn all the swift services then kill the proxy
626 # service so we can run it in foreground in screen. ``swift-init ...
627 # {stop|restart}`` exits with '1' if no servers are running, ignore it just
628 # in case
629 swift-init --run-dir=${SWIFT_DATA_DIR}/run all restart || true
630 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100631 todo="object container account"
Sean Dague101b4242013-10-22 08:47:11 -0400632 fi
633 for type in proxy ${todo}; do
634 swift-init --run-dir=${SWIFT_DATA_DIR}/run ${type} stop || true
635 done
636 screen_it s-proxy "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONF_DIR}/proxy-server.conf -v"
637 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
638 for type in object container account; do
639 screen_it s-${type} "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-${type}-server ${SWIFT_CONF_DIR}/${type}-server/1.conf -v"
640 done
641 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100642}
643
644# stop_swift() - Stop running processes (non-screen)
645function stop_swift() {
zhang-hared98a5d02013-06-21 18:18:02 +0800646
647 if is_apache_enabled_service swift; then
648 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest stop && return 0
649 fi
650
Attila Fazekasece6a332012-11-29 14:19:41 +0100651 # screen normally killed by unstack.sh
Dean Troyer995eb922013-03-07 16:11:40 -0600652 if type -p swift-init >/dev/null; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100653 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
654 fi
Dean Troyer995eb922013-03-07 16:11:40 -0600655 # Dump the proxy server
656 sudo pkill -f swift-proxy-server
Attila Fazekasece6a332012-11-29 14:19:41 +0100657}
658
659# Restore xtrace
660$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400661
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100662# Tell emacs to use shell-script-mode
663## Local variables:
664## mode: shell-script
665## End: