blob: 9c80802ba9d545c59fe7dd9506097614c4a22b5f [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:
5# ``functions`` file
zhang-hared98a5d02013-06-21 18:18:02 +08006# ``apache`` file
Attila Fazekasece6a332012-11-29 14:19:41 +01007# ``DEST``, ``SCREEN_NAME``, `SWIFT_HASH` must be defined
Attila Fazekas91b8d132013-01-06 22:40:09 +01008# ``STACK_USER`` must be defined
Attila Fazekasece6a332012-11-29 14:19:41 +01009# ``SWIFT_DATA_DIR`` or ``DATA_DIR`` must be defined
10# ``lib/keystone`` file
11# ``stack.sh`` calls the entry points in this order:
12#
13# install_swift
zhang-hared98a5d02013-06-21 18:18:02 +080014# _config_swift_apache_wsgi
Attila Fazekasece6a332012-11-29 14:19:41 +010015# configure_swift
16# init_swift
17# start_swift
18# stop_swift
19# cleanup_swift
zhang-hared98a5d02013-06-21 18:18:02 +080020# _cleanup_swift_apache_wsgi
Attila Fazekasece6a332012-11-29 14:19:41 +010021
22# Save trace setting
23XTRACE=$(set +o | grep xtrace)
24set +o xtrace
25
26
27# Defaults
28# --------
29
Attila Fazekasece6a332012-11-29 14:19:41 +010030# Set up default directories
Attila Fazekasece6a332012-11-29 14:19:41 +010031SWIFT_DIR=$DEST/swift
32SWIFTCLIENT_DIR=$DEST/python-swiftclient
Dean Troyer64ab7742012-12-28 15:38:28 -060033SWIFT_AUTH_CACHE_DIR=${SWIFT_AUTH_CACHE_DIR:-/var/cache/swift}
zhang-hared98a5d02013-06-21 18:18:02 +080034SWIFT_APACHE_WSGI_DIR=${SWIFT_APACHE_WSGI_DIR:-/var/www/swift}
Dean Troyerb7490da2013-03-18 16:07:56 -050035SWIFT3_DIR=$DEST/swift3
Attila Fazekasece6a332012-11-29 14:19:41 +010036
37# TODO: add logging to different location.
38
39# Set ``SWIFT_DATA_DIR`` to the location of swift drives and objects.
40# Default is the common DevStack data directory.
41SWIFT_DATA_DIR=${SWIFT_DATA_DIR:-${DATA_DIR}/swift}
42
Dean Troyer6ec72fa2013-03-13 11:44:53 -050043# Set ``SWIFT_CONF_DIR`` to the location of the configuration files.
Attila Fazekasece6a332012-11-29 14:19:41 +010044# Default is ``/etc/swift``.
Dean Troyer6ec72fa2013-03-13 11:44:53 -050045# TODO(dtroyer): remove SWIFT_CONFIG_DIR after cutting stable/grizzly
46SWIFT_CONF_DIR=${SWIFT_CONF_DIR:-${SWIFT_CONFIG_DIR:-/etc/swift}}
Attila Fazekasece6a332012-11-29 14:19:41 +010047
Dean Troyerb7490da2013-03-18 16:07:56 -050048if is_service_enabled s-proxy && is_service_enabled swift3; then
49 # If we are using swift3, we can default the s3 port to swift instead
50 # of nova-objectstore
51 S3_SERVICE_PORT=${S3_SERVICE_PORT:-8080}
52fi
53
Attila Fazekasece6a332012-11-29 14:19:41 +010054# DevStack will create a loop-back disk formatted as XFS to store the
Kevin Lydad66c9652013-01-09 13:39:57 +000055# swift data. Set ``SWIFT_LOOPBACK_DISK_SIZE`` to the disk size in
56# kilobytes.
Attila Fazekasece6a332012-11-29 14:19:41 +010057# Default is 1 gigabyte.
Attila Fazekas3418c1c2013-09-16 18:35:49 +020058SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=1048576
59# if tempest enabled the default size is 4 Gigabyte.
60if is_service_enabled tempest; then
61 SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=${SWIFT_LOOPBACK_DISK_SIZE:-4194304}
62fi
63
64SWIFT_LOOPBACK_DISK_SIZE=${SWIFT_LOOPBACK_DISK_SIZE:-$SWIFT_LOOPBACK_DISK_SIZE_DEFAULT}
Attila Fazekasece6a332012-11-29 14:19:41 +010065
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010066# Set ``SWIFT_EXTRAS_MIDDLEWARE`` to extras middlewares.
Chmouel Boudjnah1fba1aa2013-08-02 00:40:05 +020067# Default is ``staticweb, tempurl, formpost``
68SWIFT_EXTRAS_MIDDLEWARE=${SWIFT_EXTRAS_MIDDLEWARE:-tempurl formpost staticweb}
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010069
Attila Fazekasece6a332012-11-29 14:19:41 +010070# The ring uses a configurable number of bits from a path’s MD5 hash as
71# a partition index that designates a device. The number of bits kept
72# from the hash is known as the partition power, and 2 to the partition
73# power indicates the partition count. Partitioning the full MD5 hash
74# ring allows other parts of the cluster to work in batches of items at
75# once which ends up either more efficient or at least less complex than
76# working with each item separately or the entire cluster all at once.
77# By default we define 9 for the partition count (which mean 512).
78SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9}
79
80# Set ``SWIFT_REPLICAS`` to configure how many replicas are to be
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +010081# configured for your Swift cluster. By default we are configuring
82# only one replica since this is way less CPU and memory intensive. If
83# you are planning to test swift replication you may want to set this
84# up to 3.
85SWIFT_REPLICAS=${SWIFT_REPLICAS:-1}
Attila Fazekasece6a332012-11-29 14:19:41 +010086SWIFT_REPLICAS_SEQ=$(seq ${SWIFT_REPLICAS})
87
88# Set ``OBJECT_PORT_BASE``, ``CONTAINER_PORT_BASE``, ``ACCOUNT_PORT_BASE``
89# Port bases used in port number calclution for the service "nodes"
90# The specified port number will be used, the additinal ports calculated by
91# base_port + node_num * 10
Dean Troyer1151d6f2013-03-29 14:06:52 -050092OBJECT_PORT_BASE=${OBJECT_PORT_BASE:-6013}
93CONTAINER_PORT_BASE=${CONTAINER_PORT_BASE:-6011}
94ACCOUNT_PORT_BASE=${ACCOUNT_PORT_BASE:-6012}
Attila Fazekasece6a332012-11-29 14:19:41 +010095
Dean Troyer6d04fd72012-12-21 11:03:37 -060096
Dean Troyercc6b4432013-04-08 15:38:03 -050097# Functions
98# ---------
Attila Fazekasece6a332012-11-29 14:19:41 +010099
100# cleanup_swift() - Remove residual data files
101function cleanup_swift() {
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500102 rm -f ${SWIFT_CONF_DIR}{*.builder,*.ring.gz,backups/*.builder,backups/*.ring.gz}
Attila Fazekasece6a332012-11-29 14:19:41 +0100103 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
104 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
105 fi
106 if [[ -e ${SWIFT_DATA_DIR}/drives/images/swift.img ]]; then
107 rm ${SWIFT_DATA_DIR}/drives/images/swift.img
108 fi
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100109 rm -rf ${SWIFT_DATA_DIR}/run/
zhang-hared98a5d02013-06-21 18:18:02 +0800110 if is_apache_enabled_service swift; then
111 _cleanup_swift_apache_wsgi
112 fi
113}
114
115# _cleanup_swift_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
116function _cleanup_swift_apache_wsgi() {
117 sudo rm -f $SWIFT_APACHE_WSGI_DIR/*.wsgi
Jamie Lennox54707012013-09-17 12:07:48 +1000118 disable_apache_site proxy-server
zhang-hared98a5d02013-06-21 18:18:02 +0800119 for node_number in ${SWIFT_REPLICAS_SEQ}; do
120 for type in object container account; do
121 site_name=${type}-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000122 disable_apache_site ${site_name}
zhang-hared98a5d02013-06-21 18:18:02 +0800123 sudo rm -f /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site_name}
124 done
125 done
126}
127
128# _config_swift_apache_wsgi() - Set WSGI config files of Swift
129function _config_swift_apache_wsgi() {
130 sudo mkdir -p ${SWIFT_APACHE_WSGI_DIR}
131 local apache_vhost_dir=/etc/${APACHE_NAME}/$APACHE_CONF_DIR
132 local proxy_port=${SWIFT_DEFAULT_BIND_PORT:-8080}
133
134 # copy proxy vhost and wsgi file
135 sudo cp ${SWIFT_DIR}/examples/apache2/proxy-server.template ${apache_vhost_dir}/proxy-server
136 sudo sed -e "
137 /^#/d;/^$/d;
138 s/%PORT%/$proxy_port/g;
139 s/%SERVICENAME%/proxy-server/g;
140 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000141 s/%USER%/${STACK_USER}/g;
zhang-hared98a5d02013-06-21 18:18:02 +0800142 " -i ${apache_vhost_dir}/proxy-server
Jamie Lennox54707012013-09-17 12:07:48 +1000143 enable_apache_site proxy-server
zhang-hared98a5d02013-06-21 18:18:02 +0800144
145 sudo cp ${SWIFT_DIR}/examples/wsgi/proxy-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
146 sudo sed -e "
147 /^#/d;/^$/d;
148 s/%SERVICECONF%/proxy-server.conf/g;
149 " -i ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
zhang-hared98a5d02013-06-21 18:18:02 +0800150
151 # copy apache vhost file and set name and port
152 for node_number in ${SWIFT_REPLICAS_SEQ}; do
153 object_port=$[OBJECT_PORT_BASE + 10 * ($node_number - 1)]
154 container_port=$[CONTAINER_PORT_BASE + 10 * ($node_number - 1)]
155 account_port=$[ACCOUNT_PORT_BASE + 10 * ($node_number - 1)]
156
157 sudo cp ${SWIFT_DIR}/examples/apache2/object-server.template ${apache_vhost_dir}/object-server-${node_number}
158 sudo sed -e "
159 s/%PORT%/$object_port/g;
160 s/%SERVICENAME%/object-server-${node_number}/g;
161 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000162 s/%USER%/${STACK_USER}/g;
zhang-hared98a5d02013-06-21 18:18:02 +0800163 " -i ${apache_vhost_dir}/object-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000164 enable_apache_site object-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800165
166 sudo cp ${SWIFT_DIR}/examples/wsgi/object-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
167 sudo sed -e "
168 /^#/d;/^$/d;
169 s/%SERVICECONF%/object-server\/${node_number}.conf/g;
170 " -i ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
171
172 sudo cp ${SWIFT_DIR}/examples/apache2/container-server.template ${apache_vhost_dir}/container-server-${node_number}
173 sudo sed -e "
174 /^#/d;/^$/d;
175 s/%PORT%/$container_port/g;
176 s/%SERVICENAME%/container-server-${node_number}/g;
177 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000178 s/%USER%/${STACK_USER}/g;
zhang-hared98a5d02013-06-21 18:18:02 +0800179 " -i ${apache_vhost_dir}/container-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000180 enable_apache_site container-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800181
182 sudo cp ${SWIFT_DIR}/examples/wsgi/container-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
183 sudo sed -e "
184 /^#/d;/^$/d;
185 s/%SERVICECONF%/container-server\/${node_number}.conf/g;
186 " -i ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
187
188 sudo cp ${SWIFT_DIR}/examples/apache2/account-server.template ${apache_vhost_dir}/account-server-${node_number}
189 sudo sed -e "
190 /^#/d;/^$/d;
191 s/%PORT%/$account_port/g;
192 s/%SERVICENAME%/account-server-${node_number}/g;
193 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000194 s/%USER%/${STACK_USER}/g;
zhang-hared98a5d02013-06-21 18:18:02 +0800195 " -i ${apache_vhost_dir}/account-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000196 enable_apache_site account-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800197
198 sudo cp ${SWIFT_DIR}/examples/wsgi/account-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
199 sudo sed -e "
200 /^#/d;/^$/d;
201 s/%SERVICECONF%/account-server\/${node_number}.conf/g;
202 " -i ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
zhang-hared98a5d02013-06-21 18:18:02 +0800203 done
Attila Fazekasece6a332012-11-29 14:19:41 +0100204}
205
206# configure_swift() - Set config files, create data dirs and loop image
207function configure_swift() {
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100208 local swift_pipeline=" "
Attila Fazekasece6a332012-11-29 14:19:41 +0100209 local node_number
210 local swift_node_config
211 local swift_log_dir
212
Attila Fazekasece6a332012-11-29 14:19:41 +0100213 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100214 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100215
Dean Troyer1c6c1122013-03-27 17:40:53 -0500216 sudo mkdir -p ${SWIFT_CONF_DIR}/{object,container,account}-server
217 sudo chown -R $USER: ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100218
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500219 if [[ "$SWIFT_CONF_DIR" != "/etc/swift" ]]; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100220 # Some swift tools are hard-coded to use ``/etc/swift`` and are apparently not going to be fixed.
221 # Create a symlink if the config dir is moved
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500222 sudo ln -sf ${SWIFT_CONF_DIR} /etc/swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100223 fi
224
225 # Swift use rsync to synchronize between all the different
226 # partitions (which make more sense when you have a multi-node
227 # setup) we configure it with our version of rsync.
228 sed -e "
229 s/%GROUP%/${USER_GROUP}/;
230 s/%USER%/$USER/;
231 s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,;
232 " $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf
233 # rsyncd.conf just prepared for 4 nodes
Vincent Untzc18b9652012-12-04 12:36:34 +0100234 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100235 sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync
236 else
237 sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync
238 fi
239
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500240 SWIFT_CONFIG_PROXY_SERVER=${SWIFT_CONF_DIR}/proxy-server.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100241 cp ${SWIFT_DIR}/etc/proxy-server.conf-sample ${SWIFT_CONFIG_PROXY_SERVER}
242
243 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user
244 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user ${USER}
245
246 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500247 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100248
249 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers
250 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1
251
252 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level
253 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level DEBUG
254
255 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port
256 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT:-8080}
257
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000258 # By default Swift will be installed with keystone and tempauth middleware
259 # and add the swift3 middleware if its configured for it. The token for
260 # tempauth would be prefixed with the reseller_prefix setting TEMPAUTH_ the
261 # token for keystoneauth would have the standard reseller_prefix AUTH_
262 if is_service_enabled swift3;then
263 swift_pipeline=" swift3 s3token "
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100264 fi
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000265 swift_pipeline+=" authtoken keystoneauth tempauth "
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100266 sed -i "/^pipeline/ { s/tempauth/${swift_pipeline} ${SWIFT_EXTRAS_MIDDLEWARE}/ ;}" ${SWIFT_CONFIG_PROXY_SERVER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100267
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000268 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth account_autocreate
Attila Fazekasece6a332012-11-29 14:19:41 +0100269 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server account_autocreate true
270
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000271 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix
272 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix "TEMPAUTH"
273
Attila Fazekasece6a332012-11-29 14:19:41 +0100274 # Configure Keystone
275 sed -i '/^# \[filter:authtoken\]/,/^# \[filter:keystoneauth\]$/ s/^#[ \t]*//' ${SWIFT_CONFIG_PROXY_SERVER}
276 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_host $KEYSTONE_AUTH_HOST
277 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_port $KEYSTONE_AUTH_PORT
278 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
279 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
280 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
281 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_user swift
282 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_password $SERVICE_PASSWORD
Dean Troyer64ab7742012-12-28 15:38:28 -0600283 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken signing_dir $SWIFT_AUTH_CACHE_DIR
Attila Fazekasece6a332012-11-29 14:19:41 +0100284
285 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use
286 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles
287 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin"
288
289 if is_service_enabled swift3; then
290 cat <<EOF >>${SWIFT_CONFIG_PROXY_SERVER}
291# NOTE(chmou): s3token middleware is not updated yet to use only
292# username and password.
293[filter:s3token]
294paste.filter_factory = keystone.middleware.s3_token:filter_factory
295auth_port = ${KEYSTONE_AUTH_PORT}
296auth_host = ${KEYSTONE_AUTH_HOST}
297auth_protocol = ${KEYSTONE_AUTH_PROTOCOL}
298auth_token = ${SERVICE_TOKEN}
299admin_token = ${SERVICE_TOKEN}
300
301[filter:swift3]
302use = egg:swift3#swift3
303EOF
304 fi
305
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500306 cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONF_DIR}/swift.conf
307 iniset ${SWIFT_CONF_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH}
Attila Fazekasece6a332012-11-29 14:19:41 +0100308
309 # This function generates an object/account/proxy configuration
310 # emulating 4 nodes on different ports
311 function generate_swift_config() {
312 local swift_node_config=$1
313 local node_id=$2
314 local bind_port=$3
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000315 local server_type=$4
Attila Fazekasece6a332012-11-29 14:19:41 +0100316
317 log_facility=$[ node_id - 1 ]
318 node_path=${SWIFT_DATA_DIR}/${node_number}
319
320 iniuncomment ${swift_node_config} DEFAULT user
321 iniset ${swift_node_config} DEFAULT user ${USER}
322
323 iniuncomment ${swift_node_config} DEFAULT bind_port
324 iniset ${swift_node_config} DEFAULT bind_port ${bind_port}
325
326 iniuncomment ${swift_node_config} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500327 iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100328
329 iniuncomment ${swift_node_config} DEFAULT devices
330 iniset ${swift_node_config} DEFAULT devices ${node_path}
331
332 iniuncomment ${swift_node_config} DEFAULT log_facility
333 iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility}
334
Chmouel Boudjnah82c09962013-07-16 07:16:07 +0000335 iniuncomment ${swift_node_config} DEFAULT disable_fallocate
336 iniset ${swift_node_config} DEFAULT disable_fallocate true
337
Attila Fazekasece6a332012-11-29 14:19:41 +0100338 iniuncomment ${swift_node_config} DEFAULT mount_check
339 iniset ${swift_node_config} DEFAULT mount_check false
340
341 iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode
342 iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes
343 }
344
345 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500346 swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100347 cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000348 generate_swift_config ${swift_node_config} ${node_number} $[OBJECT_PORT_BASE + 10 * (node_number - 1)] object
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000349 iniset ${swift_node_config} filter:recon recon_cache_path ${SWIFT_DATA_DIR}/cache
350 # Using a sed and not iniset/iniuncomment because we want to a global
351 # modification and make sure it works for new sections.
352 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100353
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500354 swift_node_config=${SWIFT_CONF_DIR}/container-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100355 cp ${SWIFT_DIR}/etc/container-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000356 generate_swift_config ${swift_node_config} ${node_number} $[CONTAINER_PORT_BASE + 10 * (node_number - 1)] container
Attila Fazekas83e10952012-11-30 23:28:07 +0100357 iniuncomment ${swift_node_config} app:container-server allow_versions
358 iniset ${swift_node_config} app:container-server allow_versions "true"
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000359 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100360
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500361 swift_node_config=${SWIFT_CONF_DIR}/account-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100362 cp ${SWIFT_DIR}/etc/account-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000363 generate_swift_config ${swift_node_config} ${node_number} $[ACCOUNT_PORT_BASE + 10 * (node_number - 1)] account
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000364 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100365 done
366
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000367 # Set new accounts in tempauth to match keystone tenant/user (to make testing easier)
368 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest1 "testing .admin"
369 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest2_swiftusertest2 "testing2 .admin"
370 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest3 "testing3 .admin"
371
372 testfile=${SWIFT_CONF_DIR}/test.conf
373 cp ${SWIFT_DIR}/test/sample.conf ${testfile}
374
375 # Set accounts for functional tests
376 iniset ${testfile} func_test account swifttenanttest1
377 iniset ${testfile} func_test username swiftusertest1
378 iniset ${testfile} func_test username3 swiftusertest3
379 iniset ${testfile} func_test account2 swifttenanttest2
380 iniset ${testfile} func_test username2 swiftusertest2
381
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000382 if is_service_enabled key;then
383 iniuncomment ${testfile} func_test auth_version
384 iniset ${testfile} func_test auth_host ${KEYSTONE_SERVICE_HOST}
385 iniset ${testfile} func_test auth_port ${KEYSTONE_AUTH_PORT}
386 iniset ${testfile} func_test auth_prefix /v2.0/
387 fi
388
Attila Fazekasece6a332012-11-29 14:19:41 +0100389 swift_log_dir=${SWIFT_DATA_DIR}/logs
390 rm -rf ${swift_log_dir}
391 mkdir -p ${swift_log_dir}/hourly
392 sudo chown -R $USER:adm ${swift_log_dir}
393 sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \
394 tee /etc/rsyslog.d/10-swift.conf
zhang-hared98a5d02013-06-21 18:18:02 +0800395 if is_apache_enabled_service swift; then
396 _config_swift_apache_wsgi
397 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100398}
399
Dean Troyer1c6c1122013-03-27 17:40:53 -0500400# create_swift_disk - Create Swift backing disk
401function create_swift_disk() {
402 local node_number
403
404 # First do a bit of setup by creating the directories and
405 # changing the permissions so we can run it as our user.
406
407 USER_GROUP=$(id -g)
408 sudo mkdir -p ${SWIFT_DATA_DIR}/{drives,cache,run,logs}
409 sudo chown -R $USER:${USER_GROUP} ${SWIFT_DATA_DIR}
410
411 # Create a loopback disk and format it to XFS.
412 if [[ -e ${SWIFT_DATA_DIR}/drives/images/swift.img ]]; then
413 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
414 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
415 sudo rm -f ${SWIFT_DATA_DIR}/drives/images/swift.img
416 fi
417 fi
418
419 mkdir -p ${SWIFT_DATA_DIR}/drives/images
420 sudo touch ${SWIFT_DATA_DIR}/drives/images/swift.img
421 sudo chown $USER: ${SWIFT_DATA_DIR}/drives/images/swift.img
422
423 dd if=/dev/zero of=${SWIFT_DATA_DIR}/drives/images/swift.img \
424 bs=1024 count=0 seek=${SWIFT_LOOPBACK_DISK_SIZE}
425
426 # Make a fresh XFS filesystem
427 mkfs.xfs -f -i size=1024 ${SWIFT_DATA_DIR}/drives/images/swift.img
428
429 # Mount the disk with mount options to make it as efficient as possible
430 mkdir -p ${SWIFT_DATA_DIR}/drives/sdb1
431 if ! egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
432 sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8 \
433 ${SWIFT_DATA_DIR}/drives/images/swift.img ${SWIFT_DATA_DIR}/drives/sdb1
434 fi
435
436 # Create a link to the above mount and
437 # create all of the directories needed to emulate a few different servers
438 for node_number in ${SWIFT_REPLICAS_SEQ}; do
439 sudo ln -sf ${SWIFT_DATA_DIR}/drives/sdb1/$node_number ${SWIFT_DATA_DIR}/$node_number;
440 drive=${SWIFT_DATA_DIR}/drives/sdb1/${node_number}
441 node=${SWIFT_DATA_DIR}/${node_number}/node
442 node_device=${node}/sdb1
443 [[ -d $node ]] && continue
444 [[ -d $drive ]] && continue
445 sudo install -o ${USER} -g $USER_GROUP -d $drive
446 sudo install -o ${USER} -g $USER_GROUP -d $node_device
447 sudo chown -R $USER: ${node}
448 done
449}
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200450# create_swift_accounts() - Set up standard swift accounts and extra
451# one for tests we do this by attaching all words in the account name
452# since we want to make it compatible with tempauth which use
453# underscores for separators.
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000454
455# Tenant User Roles
456# ------------------------------------------------------------------
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200457# service swift service
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000458# swifttenanttest1 swiftusertest1 admin
459# swifttenanttest1 swiftusertest3 anotherrole
460# swifttenanttest2 swiftusertest2 admin
461
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000462function create_swift_accounts() {
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200463 KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql}
464
465 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
466 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
467
468 SWIFT_USER=$(keystone user-create --name=swift --pass="$SERVICE_PASSWORD" \
469 --tenant_id $SERVICE_TENANT --email=swift@example.com | grep " id " | get_field 2)
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200470 keystone user-role-add --tenant-id $SERVICE_TENANT --user-id $SWIFT_USER --role-id $ADMIN_ROLE
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200471
472 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
473 SWIFT_SERVICE=$(keystone service-create --name=swift --type="object-store" \
474 --description="Swift Service" | grep " id " | get_field 2)
475 keystone endpoint-create \
476 --region RegionOne \
477 --service_id $SWIFT_SERVICE \
478 --publicurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \
479 --adminurl "http://$SERVICE_HOST:8080" \
480 --internalurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s"
481 fi
482
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000483 SWIFT_TENANT_TEST1=$(keystone tenant-create --name=swifttenanttest1 | grep " id " | get_field 2)
484 SWIFT_USER_TEST1=$(keystone user-create --name=swiftusertest1 --pass=testing --email=test@example.com | grep " id " | get_field 2)
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200485 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 +0000486
487 SWIFT_USER_TEST3=$(keystone user-create --name=swiftusertest3 --pass=testing3 --email=test3@example.com | grep " id " | get_field 2)
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200488 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 +0000489
490 SWIFT_TENANT_TEST2=$(keystone tenant-create --name=swifttenanttest2 | grep " id " | get_field 2)
491 SWIFT_USER_TEST2=$(keystone user-create --name=swiftusertest2 --pass=testing2 --email=test2@example.com | grep " id " | get_field 2)
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200492 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 +0000493}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500494
Attila Fazekasece6a332012-11-29 14:19:41 +0100495# init_swift() - Initialize rings
496function init_swift() {
497 local node_number
498 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100499 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100500
Dean Troyer1c6c1122013-03-27 17:40:53 -0500501 # Forcibly re-create the backing filesystem
502 create_swift_disk
503
Attila Fazekasece6a332012-11-29 14:19:41 +0100504 # This is where we create three different rings for swift with
505 # different object servers binding on different ports.
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500506 pushd ${SWIFT_CONF_DIR} >/dev/null && {
Attila Fazekasece6a332012-11-29 14:19:41 +0100507
508 rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
509
510 swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
511 swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
512 swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
513
514 for node_number in ${SWIFT_REPLICAS_SEQ}; do
515 swift-ring-builder object.builder add z${node_number}-127.0.0.1:$[OBJECT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
516 swift-ring-builder container.builder add z${node_number}-127.0.0.1:$[CONTAINER_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
517 swift-ring-builder account.builder add z${node_number}-127.0.0.1:$[ACCOUNT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
518 done
519 swift-ring-builder object.builder rebalance
520 swift-ring-builder container.builder rebalance
521 swift-ring-builder account.builder rebalance
522 } && popd >/dev/null
523
Dean Troyer64ab7742012-12-28 15:38:28 -0600524 # Create cache dir
525 sudo mkdir -p $SWIFT_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100526 sudo chown $STACK_USER $SWIFT_AUTH_CACHE_DIR
Dean Troyer64ab7742012-12-28 15:38:28 -0600527 rm -f $SWIFT_AUTH_CACHE_DIR/*
Attila Fazekasece6a332012-11-29 14:19:41 +0100528}
529
530function install_swift() {
531 git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500532 setup_develop $SWIFT_DIR
zhang-hared98a5d02013-06-21 18:18:02 +0800533 if is_apache_enabled_service swift; then
534 install_apache_wsgi
535 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100536}
537
538function install_swiftclient() {
539 git_clone $SWIFTCLIENT_REPO $SWIFTCLIENT_DIR $SWIFTCLIENT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500540 setup_develop $SWIFTCLIENT_DIR
Attila Fazekasece6a332012-11-29 14:19:41 +0100541}
542
Attila Fazekasece6a332012-11-29 14:19:41 +0100543# start_swift() - Start running processes, including screen
544function start_swift() {
545 # (re)start rsyslog
546 restart_service rsyslog
Chmouel Boudjnah8ecbb382013-03-12 12:15:17 +0100547 # (re)start memcached to make sure we have a clean memcache.
548 restart_service memcached
549
Attila Fazekasece6a332012-11-29 14:19:41 +0100550 # Start rsync
Vincent Untzc18b9652012-12-04 12:36:34 +0100551 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100552 sudo /etc/init.d/rsync restart || :
553 else
554 sudo systemctl start xinetd.service
555 fi
556
zhang-hared98a5d02013-06-21 18:18:02 +0800557 if is_apache_enabled_service swift; then
zhang-hared98a5d02013-06-21 18:18:02 +0800558 restart_apache_server
559 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest start
560 screen_it s-proxy "cd $SWIFT_DIR && sudo tail -f /var/log/$APACHE_NAME/proxy-server"
561 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
562 for type in object container account; do
563 screen_it s-${type} "cd $SWIFT_DIR && sudo tail -f /var/log/$APACHE_NAME/${type}-server-1"
564 done
565 fi
566 return 0
567 fi
568
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100569 # By default with only one replica we are launching the proxy,
570 # container, account and object server in screen in foreground and
571 # other services in background. If we have SWIFT_REPLICAS set to something
572 # greater than one we first spawn all the swift services then kill the proxy
573 # service so we can run it in foreground in screen. ``swift-init ...
574 # {stop|restart}`` exits with '1' if no servers are running, ignore it just
575 # in case
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100576 swift-init --run-dir=${SWIFT_DATA_DIR}/run all restart || true
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500577 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100578 todo="object container account"
579 fi
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500580 for type in proxy ${todo}; do
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100581 swift-init --run-dir=${SWIFT_DATA_DIR}/run ${type} stop || true
582 done
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500583 screen_it s-proxy "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONF_DIR}/proxy-server.conf -v"
584 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800585 for type in object container account; do
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500586 screen_it s-${type} "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-${type}-server ${SWIFT_CONF_DIR}/${type}-server/1.conf -v"
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100587 done
588 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100589}
590
591# stop_swift() - Stop running processes (non-screen)
592function stop_swift() {
zhang-hared98a5d02013-06-21 18:18:02 +0800593
594 if is_apache_enabled_service swift; then
595 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest stop && return 0
596 fi
597
Attila Fazekasece6a332012-11-29 14:19:41 +0100598 # screen normally killed by unstack.sh
Dean Troyer995eb922013-03-07 16:11:40 -0600599 if type -p swift-init >/dev/null; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100600 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
601 fi
Dean Troyer995eb922013-03-07 16:11:40 -0600602 # Dump the proxy server
603 sudo pkill -f swift-proxy-server
Attila Fazekasece6a332012-11-29 14:19:41 +0100604}
605
606# Restore xtrace
607$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400608
609# Local variables:
610# mode: shell-script
611# End: