blob: baa03ec5b85eb4303bba7eef1ff0e91e3d405f43 [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
Chmouel Boudjnahf2c1a712014-01-29 21:38:14 +0000261 cp ${SWIFT_DIR}/etc/container-sync-realms.conf-sample ${SWIFT_CONF_DIR}/container-sync-realms.conf
262
Attila Fazekasece6a332012-11-29 14:19:41 +0100263 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user
Stephan Renatuse578eff2013-11-19 13:31:04 +0100264 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user ${STACK_USER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100265
266 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500267 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100268
269 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers
270 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1
271
272 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level
273 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level DEBUG
274
275 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port
276 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT:-8080}
277
Joe Gordond254da52013-11-19 21:06:29 -0800278 # Devstack is commonly run in a small slow environment, so bump the
279 # timeouts up.
280 # node_timeout is how long between read operations a node takes to
281 # respond to the proxy server
282 # conn_timeout is all about how long it takes a connect() system call to
283 # return
284 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server node_timeout 120
285 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server conn_timeout 20
286
Cyril Roelandtd9883402013-09-27 15:16:51 +0000287 # Configure Ceilometer
288 if is_service_enabled ceilometer; then
289 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer use "egg:ceilometer#swift"
290 SWIFT_EXTRAS_MIDDLEWARE_LAST="${SWIFT_EXTRAS_MIDDLEWARE_LAST} ceilometer"
291 fi
292
Peter Portantecee4b3b2013-11-20 14:33:16 -0500293 # Restrict the length of auth tokens in the swift proxy-server logs.
294 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:proxy-logging reveal_sensitive_prefix ${SWIFT_LOG_TOKEN_LENGTH}
295
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000296 # By default Swift will be installed with keystone and tempauth middleware
297 # and add the swift3 middleware if its configured for it. The token for
Adam Spierscb961592013-10-05 12:11:07 +0100298 # tempauth would be prefixed with the reseller_prefix setting `TEMPAUTH_` the
299 # token for keystoneauth would have the standard reseller_prefix `AUTH_`
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000300 if is_service_enabled swift3;then
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200301 swift_pipeline+=" swift3 s3token "
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100302 fi
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000303 swift_pipeline+=" authtoken keystoneauth tempauth "
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100304 sed -i "/^pipeline/ { s/tempauth/${swift_pipeline} ${SWIFT_EXTRAS_MIDDLEWARE}/ ;}" ${SWIFT_CONFIG_PROXY_SERVER}
Cyril Roelandtd9883402013-09-27 15:16:51 +0000305 sed -i "/^pipeline/ { s/proxy-server/${SWIFT_EXTRAS_MIDDLEWARE_LAST} proxy-server/ ; }" ${SWIFT_CONFIG_PROXY_SERVER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100306
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000307 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth account_autocreate
Attila Fazekasece6a332012-11-29 14:19:41 +0100308 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server account_autocreate true
309
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000310 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix
311 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix "TEMPAUTH"
312
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200313 # Configure Crossdomain
314 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:crossdomain use "egg:swift#crossdomain"
315
Attila Fazekasece6a332012-11-29 14:19:41 +0100316 # Configure Keystone
317 sed -i '/^# \[filter:authtoken\]/,/^# \[filter:keystoneauth\]$/ s/^#[ \t]*//' ${SWIFT_CONFIG_PROXY_SERVER}
318 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_host $KEYSTONE_AUTH_HOST
319 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_port $KEYSTONE_AUTH_PORT
320 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000321 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken cafile $KEYSTONE_SSL_CA
Attila Fazekasece6a332012-11-29 14:19:41 +0100322 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
323 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
324 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_user swift
325 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_password $SERVICE_PASSWORD
Dean Troyer64ab7742012-12-28 15:38:28 -0600326 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken signing_dir $SWIFT_AUTH_CACHE_DIR
Peter Portante8afc8932013-11-20 17:34:39 -0500327 # This causes the authtoken middleware to use the same python logging
328 # adapter provided by the swift proxy-server, so that request transaction
329 # IDs will included in all of its log messages.
330 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken log_name swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100331
332 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use
333 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles
334 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin"
335
336 if is_service_enabled swift3; then
337 cat <<EOF >>${SWIFT_CONFIG_PROXY_SERVER}
338# NOTE(chmou): s3token middleware is not updated yet to use only
339# username and password.
340[filter:s3token]
341paste.filter_factory = keystone.middleware.s3_token:filter_factory
342auth_port = ${KEYSTONE_AUTH_PORT}
343auth_host = ${KEYSTONE_AUTH_HOST}
344auth_protocol = ${KEYSTONE_AUTH_PROTOCOL}
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000345cafile = ${KEYSTONE_SSL_CA}
Attila Fazekasece6a332012-11-29 14:19:41 +0100346auth_token = ${SERVICE_TOKEN}
347admin_token = ${SERVICE_TOKEN}
348
349[filter:swift3]
350use = egg:swift3#swift3
351EOF
352 fi
353
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500354 cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONF_DIR}/swift.conf
355 iniset ${SWIFT_CONF_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH}
Attila Fazekasece6a332012-11-29 14:19:41 +0100356
Peter Portantecee4b3b2013-11-20 14:33:16 -0500357 # This function generates an object/container/account configuration
Attila Fazekasece6a332012-11-29 14:19:41 +0100358 # emulating 4 nodes on different ports
359 function generate_swift_config() {
360 local swift_node_config=$1
361 local node_id=$2
362 local bind_port=$3
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000363 local server_type=$4
Attila Fazekasece6a332012-11-29 14:19:41 +0100364
365 log_facility=$[ node_id - 1 ]
366 node_path=${SWIFT_DATA_DIR}/${node_number}
367
368 iniuncomment ${swift_node_config} DEFAULT user
Stephan Renatuse578eff2013-11-19 13:31:04 +0100369 iniset ${swift_node_config} DEFAULT user ${STACK_USER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100370
371 iniuncomment ${swift_node_config} DEFAULT bind_port
372 iniset ${swift_node_config} DEFAULT bind_port ${bind_port}
373
374 iniuncomment ${swift_node_config} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500375 iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100376
377 iniuncomment ${swift_node_config} DEFAULT devices
378 iniset ${swift_node_config} DEFAULT devices ${node_path}
379
380 iniuncomment ${swift_node_config} DEFAULT log_facility
381 iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility}
382
Chmouel Boudjnah63d9f3e2013-12-21 01:19:09 -0800383 iniuncomment ${swift_node_config} DEFAULT workers
384 iniset ${swift_node_config} DEFAULT workers 1
Chmouel Boudjnah86d9aed2013-12-10 12:24:16 +0000385
Chmouel Boudjnah82c09962013-07-16 07:16:07 +0000386 iniuncomment ${swift_node_config} DEFAULT disable_fallocate
387 iniset ${swift_node_config} DEFAULT disable_fallocate true
388
Attila Fazekasece6a332012-11-29 14:19:41 +0100389 iniuncomment ${swift_node_config} DEFAULT mount_check
390 iniset ${swift_node_config} DEFAULT mount_check false
391
392 iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode
393 iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes
394 }
395
396 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500397 swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100398 cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000399 generate_swift_config ${swift_node_config} ${node_number} $[OBJECT_PORT_BASE + 10 * (node_number - 1)] object
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000400 iniset ${swift_node_config} filter:recon recon_cache_path ${SWIFT_DATA_DIR}/cache
401 # Using a sed and not iniset/iniuncomment because we want to a global
402 # modification and make sure it works for new sections.
403 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100404
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500405 swift_node_config=${SWIFT_CONF_DIR}/container-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100406 cp ${SWIFT_DIR}/etc/container-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000407 generate_swift_config ${swift_node_config} ${node_number} $[CONTAINER_PORT_BASE + 10 * (node_number - 1)] container
Attila Fazekas83e10952012-11-30 23:28:07 +0100408 iniuncomment ${swift_node_config} app:container-server allow_versions
409 iniset ${swift_node_config} app:container-server allow_versions "true"
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000410 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100411
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500412 swift_node_config=${SWIFT_CONF_DIR}/account-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100413 cp ${SWIFT_DIR}/etc/account-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000414 generate_swift_config ${swift_node_config} ${node_number} $[ACCOUNT_PORT_BASE + 10 * (node_number - 1)] account
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000415 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100416 done
417
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000418 # Set new accounts in tempauth to match keystone tenant/user (to make testing easier)
419 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest1 "testing .admin"
420 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest2_swiftusertest2 "testing2 .admin"
421 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest3 "testing3 .admin"
422
423 testfile=${SWIFT_CONF_DIR}/test.conf
424 cp ${SWIFT_DIR}/test/sample.conf ${testfile}
425
426 # Set accounts for functional tests
427 iniset ${testfile} func_test account swifttenanttest1
428 iniset ${testfile} func_test username swiftusertest1
429 iniset ${testfile} func_test username3 swiftusertest3
430 iniset ${testfile} func_test account2 swifttenanttest2
431 iniset ${testfile} func_test username2 swiftusertest2
432
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000433 if is_service_enabled key;then
434 iniuncomment ${testfile} func_test auth_version
435 iniset ${testfile} func_test auth_host ${KEYSTONE_SERVICE_HOST}
436 iniset ${testfile} func_test auth_port ${KEYSTONE_AUTH_PORT}
437 iniset ${testfile} func_test auth_prefix /v2.0/
438 fi
439
Attila Fazekasece6a332012-11-29 14:19:41 +0100440 swift_log_dir=${SWIFT_DATA_DIR}/logs
441 rm -rf ${swift_log_dir}
442 mkdir -p ${swift_log_dir}/hourly
Stephan Renatuse578eff2013-11-19 13:31:04 +0100443 sudo chown -R ${STACK_USER}:adm ${swift_log_dir}
Attila Fazekasece6a332012-11-29 14:19:41 +0100444 sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \
445 tee /etc/rsyslog.d/10-swift.conf
zhang-hared98a5d02013-06-21 18:18:02 +0800446 if is_apache_enabled_service swift; then
447 _config_swift_apache_wsgi
448 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100449}
450
Dean Troyer1c6c1122013-03-27 17:40:53 -0500451# create_swift_disk - Create Swift backing disk
452function create_swift_disk() {
453 local node_number
454
455 # First do a bit of setup by creating the directories and
456 # changing the permissions so we can run it as our user.
457
Stephan Renatuse578eff2013-11-19 13:31:04 +0100458 USER_GROUP=$(id -g ${STACK_USER})
Dean Troyer1c6c1122013-03-27 17:40:53 -0500459 sudo mkdir -p ${SWIFT_DATA_DIR}/{drives,cache,run,logs}
Stephan Renatuse578eff2013-11-19 13:31:04 +0100460 sudo chown -R ${STACK_USER}:${USER_GROUP} ${SWIFT_DATA_DIR}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500461
462 # Create a loopback disk and format it to XFS.
Attila Fazekase6024412013-09-15 18:38:48 +0200463 if [[ -e ${SWIFT_DISK_IMAGE} ]]; then
Dean Troyer1c6c1122013-03-27 17:40:53 -0500464 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
465 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
Attila Fazekase6024412013-09-15 18:38:48 +0200466 sudo rm -f ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500467 fi
468 fi
469
470 mkdir -p ${SWIFT_DATA_DIR}/drives/images
Attila Fazekase6024412013-09-15 18:38:48 +0200471 sudo touch ${SWIFT_DISK_IMAGE}
Stephan Renatuse578eff2013-11-19 13:31:04 +0100472 sudo chown ${STACK_USER}: ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500473
Attila Fazekase6024412013-09-15 18:38:48 +0200474 truncate -s ${SWIFT_LOOPBACK_DISK_SIZE} ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500475
476 # Make a fresh XFS filesystem
Attila Fazekase6024412013-09-15 18:38:48 +0200477 mkfs.xfs -f -i size=1024 ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500478
479 # Mount the disk with mount options to make it as efficient as possible
480 mkdir -p ${SWIFT_DATA_DIR}/drives/sdb1
481 if ! egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
482 sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8 \
Attila Fazekase6024412013-09-15 18:38:48 +0200483 ${SWIFT_DISK_IMAGE} ${SWIFT_DATA_DIR}/drives/sdb1
Dean Troyer1c6c1122013-03-27 17:40:53 -0500484 fi
485
486 # Create a link to the above mount and
487 # create all of the directories needed to emulate a few different servers
488 for node_number in ${SWIFT_REPLICAS_SEQ}; do
489 sudo ln -sf ${SWIFT_DATA_DIR}/drives/sdb1/$node_number ${SWIFT_DATA_DIR}/$node_number;
490 drive=${SWIFT_DATA_DIR}/drives/sdb1/${node_number}
491 node=${SWIFT_DATA_DIR}/${node_number}/node
492 node_device=${node}/sdb1
493 [[ -d $node ]] && continue
494 [[ -d $drive ]] && continue
Stephan Renatuse578eff2013-11-19 13:31:04 +0100495 sudo install -o ${STACK_USER} -g $USER_GROUP -d $drive
496 sudo install -o ${STACK_USER} -g $USER_GROUP -d $node_device
497 sudo chown -R ${STACK_USER}: ${node}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500498 done
499}
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200500# create_swift_accounts() - Set up standard swift accounts and extra
501# one for tests we do this by attaching all words in the account name
502# since we want to make it compatible with tempauth which use
503# underscores for separators.
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000504
505# Tenant User Roles
506# ------------------------------------------------------------------
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200507# service swift service
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000508# swifttenanttest1 swiftusertest1 admin
509# swifttenanttest1 swiftusertest3 anotherrole
510# swifttenanttest2 swiftusertest2 admin
511
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000512function create_swift_accounts() {
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200513 KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql}
514
515 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
516 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
517
518 SWIFT_USER=$(keystone user-create --name=swift --pass="$SERVICE_PASSWORD" \
Dirk Mueller25049cd2014-01-09 13:53:52 +0100519 --tenant-id $SERVICE_TENANT --email=swift@example.com | grep " id " | get_field 2)
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200520 keystone user-role-add --tenant-id $SERVICE_TENANT --user-id $SWIFT_USER --role-id $ADMIN_ROLE
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200521
522 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
523 SWIFT_SERVICE=$(keystone service-create --name=swift --type="object-store" \
524 --description="Swift Service" | grep " id " | get_field 2)
525 keystone endpoint-create \
526 --region RegionOne \
527 --service_id $SWIFT_SERVICE \
528 --publicurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \
529 --adminurl "http://$SERVICE_HOST:8080" \
530 --internalurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s"
531 fi
532
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000533 SWIFT_TENANT_TEST1=$(keystone tenant-create --name=swifttenanttest1 | grep " id " | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500534 die_if_not_set $LINENO SWIFT_TENANT_TEST1 "Failure creating SWIFT_TENANT_TEST1"
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000535 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 -0500536 die_if_not_set $LINENO SWIFT_USER_TEST1 "Failure creating SWIFT_USER_TEST1"
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200537 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 +0000538
539 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 -0500540 die_if_not_set $LINENO SWIFT_USER_TEST3 "Failure creating SWIFT_USER_TEST3"
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200541 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 +0000542
543 SWIFT_TENANT_TEST2=$(keystone tenant-create --name=swifttenanttest2 | grep " id " | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500544 die_if_not_set $LINENO SWIFT_TENANT_TEST2 "Failure creating SWIFT_TENANT_TEST2"
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000545 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 -0500546 die_if_not_set $LINENO SWIFT_USER_TEST2 "Failure creating SWIFT_USER_TEST2"
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200547 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 +0000548}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500549
Attila Fazekasece6a332012-11-29 14:19:41 +0100550# init_swift() - Initialize rings
551function init_swift() {
552 local node_number
553 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100554 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100555
Dean Troyer1c6c1122013-03-27 17:40:53 -0500556 # Forcibly re-create the backing filesystem
557 create_swift_disk
558
Attila Fazekasece6a332012-11-29 14:19:41 +0100559 # This is where we create three different rings for swift with
560 # different object servers binding on different ports.
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500561 pushd ${SWIFT_CONF_DIR} >/dev/null && {
Attila Fazekasece6a332012-11-29 14:19:41 +0100562
563 rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
564
565 swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
566 swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
567 swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
568
569 for node_number in ${SWIFT_REPLICAS_SEQ}; do
570 swift-ring-builder object.builder add z${node_number}-127.0.0.1:$[OBJECT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
571 swift-ring-builder container.builder add z${node_number}-127.0.0.1:$[CONTAINER_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
572 swift-ring-builder account.builder add z${node_number}-127.0.0.1:$[ACCOUNT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
573 done
574 swift-ring-builder object.builder rebalance
575 swift-ring-builder container.builder rebalance
576 swift-ring-builder account.builder rebalance
577 } && popd >/dev/null
578
Dean Troyer64ab7742012-12-28 15:38:28 -0600579 # Create cache dir
580 sudo mkdir -p $SWIFT_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100581 sudo chown $STACK_USER $SWIFT_AUTH_CACHE_DIR
Dean Troyer64ab7742012-12-28 15:38:28 -0600582 rm -f $SWIFT_AUTH_CACHE_DIR/*
Attila Fazekasece6a332012-11-29 14:19:41 +0100583}
584
585function install_swift() {
586 git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500587 setup_develop $SWIFT_DIR
zhang-hared98a5d02013-06-21 18:18:02 +0800588 if is_apache_enabled_service swift; then
589 install_apache_wsgi
590 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100591}
592
593function install_swiftclient() {
594 git_clone $SWIFTCLIENT_REPO $SWIFTCLIENT_DIR $SWIFTCLIENT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500595 setup_develop $SWIFTCLIENT_DIR
Attila Fazekasece6a332012-11-29 14:19:41 +0100596}
597
Attila Fazekasece6a332012-11-29 14:19:41 +0100598# start_swift() - Start running processes, including screen
599function start_swift() {
600 # (re)start rsyslog
601 restart_service rsyslog
Chmouel Boudjnah8ecbb382013-03-12 12:15:17 +0100602 # (re)start memcached to make sure we have a clean memcache.
603 restart_service memcached
604
Attila Fazekasece6a332012-11-29 14:19:41 +0100605 # Start rsync
Vincent Untzc18b9652012-12-04 12:36:34 +0100606 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100607 sudo /etc/init.d/rsync restart || :
608 else
609 sudo systemctl start xinetd.service
610 fi
611
zhang-hared98a5d02013-06-21 18:18:02 +0800612 if is_apache_enabled_service swift; then
zhang-hared98a5d02013-06-21 18:18:02 +0800613 restart_apache_server
614 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest start
615 screen_it s-proxy "cd $SWIFT_DIR && sudo tail -f /var/log/$APACHE_NAME/proxy-server"
616 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
617 for type in object container account; do
618 screen_it s-${type} "cd $SWIFT_DIR && sudo tail -f /var/log/$APACHE_NAME/${type}-server-1"
619 done
620 fi
621 return 0
622 fi
623
Sean Dague101b4242013-10-22 08:47:11 -0400624 # By default with only one replica we are launching the proxy,
625 # container, account and object server in screen in foreground and
626 # other services in background. If we have SWIFT_REPLICAS set to something
627 # greater than one we first spawn all the swift services then kill the proxy
628 # service so we can run it in foreground in screen. ``swift-init ...
629 # {stop|restart}`` exits with '1' if no servers are running, ignore it just
630 # in case
631 swift-init --run-dir=${SWIFT_DATA_DIR}/run all restart || true
632 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100633 todo="object container account"
Sean Dague101b4242013-10-22 08:47:11 -0400634 fi
635 for type in proxy ${todo}; do
636 swift-init --run-dir=${SWIFT_DATA_DIR}/run ${type} stop || true
637 done
638 screen_it s-proxy "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONF_DIR}/proxy-server.conf -v"
639 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
640 for type in object container account; do
641 screen_it s-${type} "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-${type}-server ${SWIFT_CONF_DIR}/${type}-server/1.conf -v"
642 done
643 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100644}
645
646# stop_swift() - Stop running processes (non-screen)
647function stop_swift() {
zhang-hared98a5d02013-06-21 18:18:02 +0800648
649 if is_apache_enabled_service swift; then
650 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest stop && return 0
651 fi
652
Attila Fazekasece6a332012-11-29 14:19:41 +0100653 # screen normally killed by unstack.sh
Dean Troyer995eb922013-03-07 16:11:40 -0600654 if type -p swift-init >/dev/null; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100655 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
656 fi
Dean Troyerbb8227c2014-01-27 12:21:52 -0600657 for type in proxy object container account; do
658 # Dump all of the servers
659 pkill -f swift-
660 done
Attila Fazekasece6a332012-11-29 14:19:41 +0100661}
662
663# Restore xtrace
664$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400665
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100666# Tell emacs to use shell-script-mode
667## Local variables:
668## mode: shell-script
669## End: