blob: 0febb00f60be887786612d213cc555482de221de [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 Troyer4237f592014-01-29 16:22:11 -0600114# Tell Tempest this project is present
115TEMPEST_SERVICES+=,swift
116
Dean Troyer6d04fd72012-12-21 11:03:37 -0600117
Dean Troyercc6b4432013-04-08 15:38:03 -0500118# Functions
119# ---------
Attila Fazekasece6a332012-11-29 14:19:41 +0100120
Dean Troyere4fa7212014-01-15 15:04:49 -0600121# Test if any Swift services are enabled
122# is_swift_enabled
123function is_swift_enabled {
124 [[ ,${ENABLED_SERVICES} =~ ,"s-" ]] && return 0
125 return 1
126}
127
Attila Fazekasece6a332012-11-29 14:19:41 +0100128# cleanup_swift() - Remove residual data files
129function cleanup_swift() {
Sean Dague101b4242013-10-22 08:47:11 -0400130 rm -f ${SWIFT_CONF_DIR}{*.builder,*.ring.gz,backups/*.builder,backups/*.ring.gz}
131 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
132 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
133 fi
134 if [[ -e ${SWIFT_DISK_IMAGE} ]]; then
135 rm ${SWIFT_DISK_IMAGE}
136 fi
137 rm -rf ${SWIFT_DATA_DIR}/run/
138 if is_apache_enabled_service swift; then
139 _cleanup_swift_apache_wsgi
140 fi
zhang-hared98a5d02013-06-21 18:18:02 +0800141}
142
143# _cleanup_swift_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
144function _cleanup_swift_apache_wsgi() {
145 sudo rm -f $SWIFT_APACHE_WSGI_DIR/*.wsgi
Jamie Lennox54707012013-09-17 12:07:48 +1000146 disable_apache_site proxy-server
zhang-hared98a5d02013-06-21 18:18:02 +0800147 for node_number in ${SWIFT_REPLICAS_SEQ}; do
148 for type in object container account; do
149 site_name=${type}-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000150 disable_apache_site ${site_name}
zhang-hared98a5d02013-06-21 18:18:02 +0800151 sudo rm -f /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site_name}
152 done
153 done
154}
155
156# _config_swift_apache_wsgi() - Set WSGI config files of Swift
157function _config_swift_apache_wsgi() {
158 sudo mkdir -p ${SWIFT_APACHE_WSGI_DIR}
159 local apache_vhost_dir=/etc/${APACHE_NAME}/$APACHE_CONF_DIR
160 local proxy_port=${SWIFT_DEFAULT_BIND_PORT:-8080}
161
162 # copy proxy vhost and wsgi file
163 sudo cp ${SWIFT_DIR}/examples/apache2/proxy-server.template ${apache_vhost_dir}/proxy-server
164 sudo sed -e "
165 /^#/d;/^$/d;
166 s/%PORT%/$proxy_port/g;
167 s/%SERVICENAME%/proxy-server/g;
168 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000169 s/%USER%/${STACK_USER}/g;
zhang-hared98a5d02013-06-21 18:18:02 +0800170 " -i ${apache_vhost_dir}/proxy-server
Jamie Lennox54707012013-09-17 12:07:48 +1000171 enable_apache_site proxy-server
zhang-hared98a5d02013-06-21 18:18:02 +0800172
173 sudo cp ${SWIFT_DIR}/examples/wsgi/proxy-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
174 sudo sed -e "
175 /^#/d;/^$/d;
176 s/%SERVICECONF%/proxy-server.conf/g;
177 " -i ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
zhang-hared98a5d02013-06-21 18:18:02 +0800178
179 # copy apache vhost file and set name and port
180 for node_number in ${SWIFT_REPLICAS_SEQ}; do
181 object_port=$[OBJECT_PORT_BASE + 10 * ($node_number - 1)]
182 container_port=$[CONTAINER_PORT_BASE + 10 * ($node_number - 1)]
183 account_port=$[ACCOUNT_PORT_BASE + 10 * ($node_number - 1)]
184
185 sudo cp ${SWIFT_DIR}/examples/apache2/object-server.template ${apache_vhost_dir}/object-server-${node_number}
186 sudo sed -e "
187 s/%PORT%/$object_port/g;
188 s/%SERVICENAME%/object-server-${node_number}/g;
189 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000190 s/%USER%/${STACK_USER}/g;
zhang-hared98a5d02013-06-21 18:18:02 +0800191 " -i ${apache_vhost_dir}/object-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000192 enable_apache_site object-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800193
194 sudo cp ${SWIFT_DIR}/examples/wsgi/object-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
195 sudo sed -e "
196 /^#/d;/^$/d;
197 s/%SERVICECONF%/object-server\/${node_number}.conf/g;
198 " -i ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
199
200 sudo cp ${SWIFT_DIR}/examples/apache2/container-server.template ${apache_vhost_dir}/container-server-${node_number}
201 sudo sed -e "
202 /^#/d;/^$/d;
203 s/%PORT%/$container_port/g;
204 s/%SERVICENAME%/container-server-${node_number}/g;
205 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000206 s/%USER%/${STACK_USER}/g;
zhang-hared98a5d02013-06-21 18:18:02 +0800207 " -i ${apache_vhost_dir}/container-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000208 enable_apache_site container-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800209
210 sudo cp ${SWIFT_DIR}/examples/wsgi/container-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
211 sudo sed -e "
212 /^#/d;/^$/d;
213 s/%SERVICECONF%/container-server\/${node_number}.conf/g;
214 " -i ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
215
216 sudo cp ${SWIFT_DIR}/examples/apache2/account-server.template ${apache_vhost_dir}/account-server-${node_number}
217 sudo sed -e "
Sean Dague101b4242013-10-22 08:47:11 -0400218 /^#/d;/^$/d;
zhang-hared98a5d02013-06-21 18:18:02 +0800219 s/%PORT%/$account_port/g;
220 s/%SERVICENAME%/account-server-${node_number}/g;
221 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000222 s/%USER%/${STACK_USER}/g;
zhang-hared98a5d02013-06-21 18:18:02 +0800223 " -i ${apache_vhost_dir}/account-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000224 enable_apache_site account-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800225
226 sudo cp ${SWIFT_DIR}/examples/wsgi/account-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
227 sudo sed -e "
Sean Dague101b4242013-10-22 08:47:11 -0400228 /^#/d;/^$/d;
zhang-hared98a5d02013-06-21 18:18:02 +0800229 s/%SERVICECONF%/account-server\/${node_number}.conf/g;
230 " -i ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
zhang-hared98a5d02013-06-21 18:18:02 +0800231 done
Attila Fazekasece6a332012-11-29 14:19:41 +0100232}
233
234# configure_swift() - Set config files, create data dirs and loop image
235function configure_swift() {
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200236 local swift_pipeline="${SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH}"
Attila Fazekasece6a332012-11-29 14:19:41 +0100237 local node_number
238 local swift_node_config
239 local swift_log_dir
240
Attila Fazekasece6a332012-11-29 14:19:41 +0100241 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100242 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100243
Dean Troyer1c6c1122013-03-27 17:40:53 -0500244 sudo mkdir -p ${SWIFT_CONF_DIR}/{object,container,account}-server
Stephan Renatuse578eff2013-11-19 13:31:04 +0100245 sudo chown -R ${STACK_USER}: ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100246
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500247 if [[ "$SWIFT_CONF_DIR" != "/etc/swift" ]]; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100248 # Some swift tools are hard-coded to use ``/etc/swift`` and are apparently not going to be fixed.
249 # Create a symlink if the config dir is moved
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500250 sudo ln -sf ${SWIFT_CONF_DIR} /etc/swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100251 fi
252
253 # Swift use rsync to synchronize between all the different
254 # partitions (which make more sense when you have a multi-node
255 # setup) we configure it with our version of rsync.
256 sed -e "
257 s/%GROUP%/${USER_GROUP}/;
Stephan Renatuse578eff2013-11-19 13:31:04 +0100258 s/%USER%/${STACK_USER}/;
Attila Fazekasece6a332012-11-29 14:19:41 +0100259 s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,;
260 " $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf
261 # rsyncd.conf just prepared for 4 nodes
Vincent Untzc18b9652012-12-04 12:36:34 +0100262 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100263 sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync
264 else
265 sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync
266 fi
267
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500268 SWIFT_CONFIG_PROXY_SERVER=${SWIFT_CONF_DIR}/proxy-server.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100269 cp ${SWIFT_DIR}/etc/proxy-server.conf-sample ${SWIFT_CONFIG_PROXY_SERVER}
270
Chmouel Boudjnahf2c1a712014-01-29 21:38:14 +0000271 cp ${SWIFT_DIR}/etc/container-sync-realms.conf-sample ${SWIFT_CONF_DIR}/container-sync-realms.conf
272
Attila Fazekasece6a332012-11-29 14:19:41 +0100273 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user
Stephan Renatuse578eff2013-11-19 13:31:04 +0100274 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user ${STACK_USER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100275
276 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500277 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100278
279 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers
280 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1
281
282 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level
283 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level DEBUG
284
285 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port
286 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT:-8080}
287
Joe Gordond254da52013-11-19 21:06:29 -0800288 # Devstack is commonly run in a small slow environment, so bump the
289 # timeouts up.
290 # node_timeout is how long between read operations a node takes to
291 # respond to the proxy server
292 # conn_timeout is all about how long it takes a connect() system call to
293 # return
294 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server node_timeout 120
295 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server conn_timeout 20
296
Cyril Roelandtd9883402013-09-27 15:16:51 +0000297 # Configure Ceilometer
298 if is_service_enabled ceilometer; then
299 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer use "egg:ceilometer#swift"
300 SWIFT_EXTRAS_MIDDLEWARE_LAST="${SWIFT_EXTRAS_MIDDLEWARE_LAST} ceilometer"
301 fi
302
Peter Portantecee4b3b2013-11-20 14:33:16 -0500303 # Restrict the length of auth tokens in the swift proxy-server logs.
304 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:proxy-logging reveal_sensitive_prefix ${SWIFT_LOG_TOKEN_LENGTH}
305
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000306 # By default Swift will be installed with keystone and tempauth middleware
307 # and add the swift3 middleware if its configured for it. The token for
Adam Spierscb961592013-10-05 12:11:07 +0100308 # tempauth would be prefixed with the reseller_prefix setting `TEMPAUTH_` the
309 # token for keystoneauth would have the standard reseller_prefix `AUTH_`
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000310 if is_service_enabled swift3;then
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200311 swift_pipeline+=" swift3 s3token "
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100312 fi
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000313 swift_pipeline+=" authtoken keystoneauth tempauth "
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100314 sed -i "/^pipeline/ { s/tempauth/${swift_pipeline} ${SWIFT_EXTRAS_MIDDLEWARE}/ ;}" ${SWIFT_CONFIG_PROXY_SERVER}
Cyril Roelandtd9883402013-09-27 15:16:51 +0000315 sed -i "/^pipeline/ { s/proxy-server/${SWIFT_EXTRAS_MIDDLEWARE_LAST} proxy-server/ ; }" ${SWIFT_CONFIG_PROXY_SERVER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100316
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000317 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth account_autocreate
Attila Fazekasece6a332012-11-29 14:19:41 +0100318 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server account_autocreate true
319
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000320 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix
321 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix "TEMPAUTH"
322
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200323 # Configure Crossdomain
324 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:crossdomain use "egg:swift#crossdomain"
325
Attila Fazekasece6a332012-11-29 14:19:41 +0100326 # Configure Keystone
327 sed -i '/^# \[filter:authtoken\]/,/^# \[filter:keystoneauth\]$/ s/^#[ \t]*//' ${SWIFT_CONFIG_PROXY_SERVER}
328 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_host $KEYSTONE_AUTH_HOST
329 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_port $KEYSTONE_AUTH_PORT
330 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000331 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken cafile $KEYSTONE_SSL_CA
Attila Fazekasece6a332012-11-29 14:19:41 +0100332 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
333 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
334 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_user swift
335 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_password $SERVICE_PASSWORD
Dean Troyer64ab7742012-12-28 15:38:28 -0600336 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken signing_dir $SWIFT_AUTH_CACHE_DIR
Peter Portante8afc8932013-11-20 17:34:39 -0500337 # This causes the authtoken middleware to use the same python logging
338 # adapter provided by the swift proxy-server, so that request transaction
339 # IDs will included in all of its log messages.
340 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken log_name swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100341
342 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use
343 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles
344 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin"
345
346 if is_service_enabled swift3; then
347 cat <<EOF >>${SWIFT_CONFIG_PROXY_SERVER}
348# NOTE(chmou): s3token middleware is not updated yet to use only
349# username and password.
350[filter:s3token]
Chmouel Boudjnah891277f2014-02-03 21:07:03 +0000351paste.filter_factory = keystoneclient.middleware.s3_token:filter_factory
Attila Fazekasece6a332012-11-29 14:19:41 +0100352auth_port = ${KEYSTONE_AUTH_PORT}
353auth_host = ${KEYSTONE_AUTH_HOST}
354auth_protocol = ${KEYSTONE_AUTH_PROTOCOL}
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000355cafile = ${KEYSTONE_SSL_CA}
Attila Fazekasece6a332012-11-29 14:19:41 +0100356auth_token = ${SERVICE_TOKEN}
357admin_token = ${SERVICE_TOKEN}
358
359[filter:swift3]
360use = egg:swift3#swift3
361EOF
362 fi
363
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500364 cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONF_DIR}/swift.conf
365 iniset ${SWIFT_CONF_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH}
Attila Fazekasece6a332012-11-29 14:19:41 +0100366
Peter Portantecee4b3b2013-11-20 14:33:16 -0500367 # This function generates an object/container/account configuration
Attila Fazekasece6a332012-11-29 14:19:41 +0100368 # emulating 4 nodes on different ports
369 function generate_swift_config() {
370 local swift_node_config=$1
371 local node_id=$2
372 local bind_port=$3
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000373 local server_type=$4
Attila Fazekasece6a332012-11-29 14:19:41 +0100374
375 log_facility=$[ node_id - 1 ]
376 node_path=${SWIFT_DATA_DIR}/${node_number}
377
378 iniuncomment ${swift_node_config} DEFAULT user
Stephan Renatuse578eff2013-11-19 13:31:04 +0100379 iniset ${swift_node_config} DEFAULT user ${STACK_USER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100380
381 iniuncomment ${swift_node_config} DEFAULT bind_port
382 iniset ${swift_node_config} DEFAULT bind_port ${bind_port}
383
384 iniuncomment ${swift_node_config} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500385 iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100386
387 iniuncomment ${swift_node_config} DEFAULT devices
388 iniset ${swift_node_config} DEFAULT devices ${node_path}
389
390 iniuncomment ${swift_node_config} DEFAULT log_facility
391 iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility}
392
Chmouel Boudjnah63d9f3e2013-12-21 01:19:09 -0800393 iniuncomment ${swift_node_config} DEFAULT workers
394 iniset ${swift_node_config} DEFAULT workers 1
Chmouel Boudjnah86d9aed2013-12-10 12:24:16 +0000395
Chmouel Boudjnah82c09962013-07-16 07:16:07 +0000396 iniuncomment ${swift_node_config} DEFAULT disable_fallocate
397 iniset ${swift_node_config} DEFAULT disable_fallocate true
398
Attila Fazekasece6a332012-11-29 14:19:41 +0100399 iniuncomment ${swift_node_config} DEFAULT mount_check
400 iniset ${swift_node_config} DEFAULT mount_check false
401
402 iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode
403 iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes
404 }
405
406 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500407 swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100408 cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000409 generate_swift_config ${swift_node_config} ${node_number} $[OBJECT_PORT_BASE + 10 * (node_number - 1)] object
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000410 iniset ${swift_node_config} filter:recon recon_cache_path ${SWIFT_DATA_DIR}/cache
411 # Using a sed and not iniset/iniuncomment because we want to a global
412 # modification and make sure it works for new sections.
413 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
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500415 swift_node_config=${SWIFT_CONF_DIR}/container-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100416 cp ${SWIFT_DIR}/etc/container-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000417 generate_swift_config ${swift_node_config} ${node_number} $[CONTAINER_PORT_BASE + 10 * (node_number - 1)] container
Attila Fazekas83e10952012-11-30 23:28:07 +0100418 iniuncomment ${swift_node_config} app:container-server allow_versions
419 iniset ${swift_node_config} app:container-server allow_versions "true"
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000420 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100421
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500422 swift_node_config=${SWIFT_CONF_DIR}/account-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100423 cp ${SWIFT_DIR}/etc/account-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000424 generate_swift_config ${swift_node_config} ${node_number} $[ACCOUNT_PORT_BASE + 10 * (node_number - 1)] account
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000425 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100426 done
427
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000428 # Set new accounts in tempauth to match keystone tenant/user (to make testing easier)
429 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest1 "testing .admin"
430 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest2_swiftusertest2 "testing2 .admin"
431 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest3 "testing3 .admin"
432
433 testfile=${SWIFT_CONF_DIR}/test.conf
434 cp ${SWIFT_DIR}/test/sample.conf ${testfile}
435
436 # Set accounts for functional tests
437 iniset ${testfile} func_test account swifttenanttest1
438 iniset ${testfile} func_test username swiftusertest1
439 iniset ${testfile} func_test username3 swiftusertest3
440 iniset ${testfile} func_test account2 swifttenanttest2
441 iniset ${testfile} func_test username2 swiftusertest2
442
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000443 if is_service_enabled key;then
444 iniuncomment ${testfile} func_test auth_version
445 iniset ${testfile} func_test auth_host ${KEYSTONE_SERVICE_HOST}
446 iniset ${testfile} func_test auth_port ${KEYSTONE_AUTH_PORT}
447 iniset ${testfile} func_test auth_prefix /v2.0/
448 fi
449
Attila Fazekasece6a332012-11-29 14:19:41 +0100450 swift_log_dir=${SWIFT_DATA_DIR}/logs
451 rm -rf ${swift_log_dir}
452 mkdir -p ${swift_log_dir}/hourly
Stephan Renatuse578eff2013-11-19 13:31:04 +0100453 sudo chown -R ${STACK_USER}:adm ${swift_log_dir}
Attila Fazekasece6a332012-11-29 14:19:41 +0100454 sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \
455 tee /etc/rsyslog.d/10-swift.conf
zhang-hared98a5d02013-06-21 18:18:02 +0800456 if is_apache_enabled_service swift; then
457 _config_swift_apache_wsgi
458 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100459}
460
Dean Troyer1c6c1122013-03-27 17:40:53 -0500461# create_swift_disk - Create Swift backing disk
462function create_swift_disk() {
463 local node_number
464
465 # First do a bit of setup by creating the directories and
466 # changing the permissions so we can run it as our user.
467
Stephan Renatuse578eff2013-11-19 13:31:04 +0100468 USER_GROUP=$(id -g ${STACK_USER})
Dean Troyer1c6c1122013-03-27 17:40:53 -0500469 sudo mkdir -p ${SWIFT_DATA_DIR}/{drives,cache,run,logs}
Stephan Renatuse578eff2013-11-19 13:31:04 +0100470 sudo chown -R ${STACK_USER}:${USER_GROUP} ${SWIFT_DATA_DIR}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500471
472 # Create a loopback disk and format it to XFS.
Attila Fazekase6024412013-09-15 18:38:48 +0200473 if [[ -e ${SWIFT_DISK_IMAGE} ]]; then
Dean Troyer1c6c1122013-03-27 17:40:53 -0500474 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
475 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
Attila Fazekase6024412013-09-15 18:38:48 +0200476 sudo rm -f ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500477 fi
478 fi
479
480 mkdir -p ${SWIFT_DATA_DIR}/drives/images
Attila Fazekase6024412013-09-15 18:38:48 +0200481 sudo touch ${SWIFT_DISK_IMAGE}
Stephan Renatuse578eff2013-11-19 13:31:04 +0100482 sudo chown ${STACK_USER}: ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500483
Attila Fazekase6024412013-09-15 18:38:48 +0200484 truncate -s ${SWIFT_LOOPBACK_DISK_SIZE} ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500485
486 # Make a fresh XFS filesystem
Attila Fazekase6024412013-09-15 18:38:48 +0200487 mkfs.xfs -f -i size=1024 ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500488
489 # Mount the disk with mount options to make it as efficient as possible
490 mkdir -p ${SWIFT_DATA_DIR}/drives/sdb1
491 if ! egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
492 sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8 \
Attila Fazekase6024412013-09-15 18:38:48 +0200493 ${SWIFT_DISK_IMAGE} ${SWIFT_DATA_DIR}/drives/sdb1
Dean Troyer1c6c1122013-03-27 17:40:53 -0500494 fi
495
496 # Create a link to the above mount and
497 # create all of the directories needed to emulate a few different servers
498 for node_number in ${SWIFT_REPLICAS_SEQ}; do
499 sudo ln -sf ${SWIFT_DATA_DIR}/drives/sdb1/$node_number ${SWIFT_DATA_DIR}/$node_number;
500 drive=${SWIFT_DATA_DIR}/drives/sdb1/${node_number}
501 node=${SWIFT_DATA_DIR}/${node_number}/node
502 node_device=${node}/sdb1
503 [[ -d $node ]] && continue
504 [[ -d $drive ]] && continue
Stephan Renatuse578eff2013-11-19 13:31:04 +0100505 sudo install -o ${STACK_USER} -g $USER_GROUP -d $drive
506 sudo install -o ${STACK_USER} -g $USER_GROUP -d $node_device
507 sudo chown -R ${STACK_USER}: ${node}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500508 done
509}
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200510# create_swift_accounts() - Set up standard swift accounts and extra
511# one for tests we do this by attaching all words in the account name
512# since we want to make it compatible with tempauth which use
513# underscores for separators.
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000514
515# Tenant User Roles
516# ------------------------------------------------------------------
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200517# service swift service
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000518# swifttenanttest1 swiftusertest1 admin
519# swifttenanttest1 swiftusertest3 anotherrole
520# swifttenanttest2 swiftusertest2 admin
521
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000522function create_swift_accounts() {
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200523 KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql}
524
525 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
526 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
527
528 SWIFT_USER=$(keystone user-create --name=swift --pass="$SERVICE_PASSWORD" \
Dirk Mueller25049cd2014-01-09 13:53:52 +0100529 --tenant-id $SERVICE_TENANT --email=swift@example.com | grep " id " | get_field 2)
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200530 keystone user-role-add --tenant-id $SERVICE_TENANT --user-id $SWIFT_USER --role-id $ADMIN_ROLE
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200531
532 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
533 SWIFT_SERVICE=$(keystone service-create --name=swift --type="object-store" \
534 --description="Swift Service" | grep " id " | get_field 2)
535 keystone endpoint-create \
536 --region RegionOne \
537 --service_id $SWIFT_SERVICE \
538 --publicurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \
539 --adminurl "http://$SERVICE_HOST:8080" \
540 --internalurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s"
541 fi
542
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000543 SWIFT_TENANT_TEST1=$(keystone tenant-create --name=swifttenanttest1 | grep " id " | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500544 die_if_not_set $LINENO SWIFT_TENANT_TEST1 "Failure creating SWIFT_TENANT_TEST1"
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000545 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 -0500546 die_if_not_set $LINENO SWIFT_USER_TEST1 "Failure creating SWIFT_USER_TEST1"
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200547 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 +0000548
549 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 -0500550 die_if_not_set $LINENO SWIFT_USER_TEST3 "Failure creating SWIFT_USER_TEST3"
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200551 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 +0000552
553 SWIFT_TENANT_TEST2=$(keystone tenant-create --name=swifttenanttest2 | grep " id " | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500554 die_if_not_set $LINENO SWIFT_TENANT_TEST2 "Failure creating SWIFT_TENANT_TEST2"
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000555 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 -0500556 die_if_not_set $LINENO SWIFT_USER_TEST2 "Failure creating SWIFT_USER_TEST2"
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200557 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 +0000558}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500559
Attila Fazekasece6a332012-11-29 14:19:41 +0100560# init_swift() - Initialize rings
561function init_swift() {
562 local node_number
563 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100564 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100565
Dean Troyer1c6c1122013-03-27 17:40:53 -0500566 # Forcibly re-create the backing filesystem
567 create_swift_disk
568
Attila Fazekasece6a332012-11-29 14:19:41 +0100569 # This is where we create three different rings for swift with
570 # different object servers binding on different ports.
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500571 pushd ${SWIFT_CONF_DIR} >/dev/null && {
Attila Fazekasece6a332012-11-29 14:19:41 +0100572
573 rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
574
575 swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
576 swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
577 swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
578
579 for node_number in ${SWIFT_REPLICAS_SEQ}; do
580 swift-ring-builder object.builder add z${node_number}-127.0.0.1:$[OBJECT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
581 swift-ring-builder container.builder add z${node_number}-127.0.0.1:$[CONTAINER_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
582 swift-ring-builder account.builder add z${node_number}-127.0.0.1:$[ACCOUNT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
583 done
584 swift-ring-builder object.builder rebalance
585 swift-ring-builder container.builder rebalance
586 swift-ring-builder account.builder rebalance
587 } && popd >/dev/null
588
Dean Troyer64ab7742012-12-28 15:38:28 -0600589 # Create cache dir
590 sudo mkdir -p $SWIFT_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100591 sudo chown $STACK_USER $SWIFT_AUTH_CACHE_DIR
Dean Troyer64ab7742012-12-28 15:38:28 -0600592 rm -f $SWIFT_AUTH_CACHE_DIR/*
Attila Fazekasece6a332012-11-29 14:19:41 +0100593}
594
595function install_swift() {
596 git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500597 setup_develop $SWIFT_DIR
zhang-hared98a5d02013-06-21 18:18:02 +0800598 if is_apache_enabled_service swift; then
599 install_apache_wsgi
600 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100601}
602
603function install_swiftclient() {
604 git_clone $SWIFTCLIENT_REPO $SWIFTCLIENT_DIR $SWIFTCLIENT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500605 setup_develop $SWIFTCLIENT_DIR
Attila Fazekasece6a332012-11-29 14:19:41 +0100606}
607
Attila Fazekasece6a332012-11-29 14:19:41 +0100608# start_swift() - Start running processes, including screen
609function start_swift() {
610 # (re)start rsyslog
611 restart_service rsyslog
Chmouel Boudjnah8ecbb382013-03-12 12:15:17 +0100612 # (re)start memcached to make sure we have a clean memcache.
613 restart_service memcached
614
Attila Fazekasece6a332012-11-29 14:19:41 +0100615 # Start rsync
Vincent Untzc18b9652012-12-04 12:36:34 +0100616 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100617 sudo /etc/init.d/rsync restart || :
618 else
619 sudo systemctl start xinetd.service
620 fi
621
zhang-hared98a5d02013-06-21 18:18:02 +0800622 if is_apache_enabled_service swift; then
zhang-hared98a5d02013-06-21 18:18:02 +0800623 restart_apache_server
624 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest start
625 screen_it s-proxy "cd $SWIFT_DIR && sudo tail -f /var/log/$APACHE_NAME/proxy-server"
626 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
627 for type in object container account; do
628 screen_it s-${type} "cd $SWIFT_DIR && sudo tail -f /var/log/$APACHE_NAME/${type}-server-1"
629 done
630 fi
631 return 0
632 fi
633
Sean Dague101b4242013-10-22 08:47:11 -0400634 # By default with only one replica we are launching the proxy,
635 # container, account and object server in screen in foreground and
636 # other services in background. If we have SWIFT_REPLICAS set to something
637 # greater than one we first spawn all the swift services then kill the proxy
638 # service so we can run it in foreground in screen. ``swift-init ...
639 # {stop|restart}`` exits with '1' if no servers are running, ignore it just
640 # in case
641 swift-init --run-dir=${SWIFT_DATA_DIR}/run all restart || true
642 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100643 todo="object container account"
Sean Dague101b4242013-10-22 08:47:11 -0400644 fi
645 for type in proxy ${todo}; do
646 swift-init --run-dir=${SWIFT_DATA_DIR}/run ${type} stop || true
647 done
648 screen_it s-proxy "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONF_DIR}/proxy-server.conf -v"
649 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
650 for type in object container account; do
651 screen_it s-${type} "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-${type}-server ${SWIFT_CONF_DIR}/${type}-server/1.conf -v"
652 done
653 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100654}
655
656# stop_swift() - Stop running processes (non-screen)
657function stop_swift() {
zhang-hared98a5d02013-06-21 18:18:02 +0800658
659 if is_apache_enabled_service swift; then
660 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest stop && return 0
661 fi
662
Attila Fazekasece6a332012-11-29 14:19:41 +0100663 # screen normally killed by unstack.sh
Dean Troyer995eb922013-03-07 16:11:40 -0600664 if type -p swift-init >/dev/null; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100665 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
666 fi
Chmouel Boudjnahf36a9b22014-02-03 23:44:47 +0100667 # Dump all of the servers
668 pkill -f swift-
Attila Fazekasece6a332012-11-29 14:19:41 +0100669}
670
671# Restore xtrace
672$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400673
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100674# Tell emacs to use shell-script-mode
675## Local variables:
676## mode: shell-script
677## End: