blob: ae8ef746f0997c5a4ea167782ad10c61c0ca68f6 [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.
58SWIFT_LOOPBACK_DISK_SIZE=${SWIFT_LOOPBACK_DISK_SIZE:-1000000}
59
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010060# Set ``SWIFT_EXTRAS_MIDDLEWARE`` to extras middlewares.
Chmouel Boudjnah1fba1aa2013-08-02 00:40:05 +020061# Default is ``staticweb, tempurl, formpost``
62SWIFT_EXTRAS_MIDDLEWARE=${SWIFT_EXTRAS_MIDDLEWARE:-tempurl formpost staticweb}
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010063
Attila Fazekasece6a332012-11-29 14:19:41 +010064# The ring uses a configurable number of bits from a path’s MD5 hash as
65# a partition index that designates a device. The number of bits kept
66# from the hash is known as the partition power, and 2 to the partition
67# power indicates the partition count. Partitioning the full MD5 hash
68# ring allows other parts of the cluster to work in batches of items at
69# once which ends up either more efficient or at least less complex than
70# working with each item separately or the entire cluster all at once.
71# By default we define 9 for the partition count (which mean 512).
72SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9}
73
74# Set ``SWIFT_REPLICAS`` to configure how many replicas are to be
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +010075# configured for your Swift cluster. By default we are configuring
76# only one replica since this is way less CPU and memory intensive. If
77# you are planning to test swift replication you may want to set this
78# up to 3.
79SWIFT_REPLICAS=${SWIFT_REPLICAS:-1}
Attila Fazekasece6a332012-11-29 14:19:41 +010080SWIFT_REPLICAS_SEQ=$(seq ${SWIFT_REPLICAS})
81
82# Set ``OBJECT_PORT_BASE``, ``CONTAINER_PORT_BASE``, ``ACCOUNT_PORT_BASE``
83# Port bases used in port number calclution for the service "nodes"
84# The specified port number will be used, the additinal ports calculated by
85# base_port + node_num * 10
Dean Troyer1151d6f2013-03-29 14:06:52 -050086OBJECT_PORT_BASE=${OBJECT_PORT_BASE:-6013}
87CONTAINER_PORT_BASE=${CONTAINER_PORT_BASE:-6011}
88ACCOUNT_PORT_BASE=${ACCOUNT_PORT_BASE:-6012}
Attila Fazekasece6a332012-11-29 14:19:41 +010089
Dean Troyer6d04fd72012-12-21 11:03:37 -060090
Dean Troyercc6b4432013-04-08 15:38:03 -050091# Functions
92# ---------
Attila Fazekasece6a332012-11-29 14:19:41 +010093
94# cleanup_swift() - Remove residual data files
95function cleanup_swift() {
Dean Troyer6ec72fa2013-03-13 11:44:53 -050096 rm -f ${SWIFT_CONF_DIR}{*.builder,*.ring.gz,backups/*.builder,backups/*.ring.gz}
Attila Fazekasece6a332012-11-29 14:19:41 +010097 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
98 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
99 fi
100 if [[ -e ${SWIFT_DATA_DIR}/drives/images/swift.img ]]; then
101 rm ${SWIFT_DATA_DIR}/drives/images/swift.img
102 fi
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100103 rm -rf ${SWIFT_DATA_DIR}/run/
zhang-hared98a5d02013-06-21 18:18:02 +0800104 if is_apache_enabled_service swift; then
105 _cleanup_swift_apache_wsgi
106 fi
107}
108
109# _cleanup_swift_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
110function _cleanup_swift_apache_wsgi() {
111 sudo rm -f $SWIFT_APACHE_WSGI_DIR/*.wsgi
112 ! is_fedora && sudo a2dissite proxy-server
113 for node_number in ${SWIFT_REPLICAS_SEQ}; do
114 for type in object container account; do
115 site_name=${type}-server-${node_number}
116 ! is_fedora && sudo a2dissite ${site_name}
117 sudo rm -f /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site_name}
118 done
119 done
120}
121
122# _config_swift_apache_wsgi() - Set WSGI config files of Swift
123function _config_swift_apache_wsgi() {
124 sudo mkdir -p ${SWIFT_APACHE_WSGI_DIR}
125 local apache_vhost_dir=/etc/${APACHE_NAME}/$APACHE_CONF_DIR
126 local proxy_port=${SWIFT_DEFAULT_BIND_PORT:-8080}
127
128 # copy proxy vhost and wsgi file
129 sudo cp ${SWIFT_DIR}/examples/apache2/proxy-server.template ${apache_vhost_dir}/proxy-server
130 sudo sed -e "
131 /^#/d;/^$/d;
132 s/%PORT%/$proxy_port/g;
133 s/%SERVICENAME%/proxy-server/g;
134 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000135 s/%USER%/${STACK_USER}/g;
zhang-hared98a5d02013-06-21 18:18:02 +0800136 " -i ${apache_vhost_dir}/proxy-server
137
138 sudo cp ${SWIFT_DIR}/examples/wsgi/proxy-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
139 sudo sed -e "
140 /^#/d;/^$/d;
141 s/%SERVICECONF%/proxy-server.conf/g;
142 " -i ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
143 ! is_fedora && sudo a2ensite proxy-server
144
145 # copy apache vhost file and set name and port
146 for node_number in ${SWIFT_REPLICAS_SEQ}; do
147 object_port=$[OBJECT_PORT_BASE + 10 * ($node_number - 1)]
148 container_port=$[CONTAINER_PORT_BASE + 10 * ($node_number - 1)]
149 account_port=$[ACCOUNT_PORT_BASE + 10 * ($node_number - 1)]
150
151 sudo cp ${SWIFT_DIR}/examples/apache2/object-server.template ${apache_vhost_dir}/object-server-${node_number}
152 sudo sed -e "
153 s/%PORT%/$object_port/g;
154 s/%SERVICENAME%/object-server-${node_number}/g;
155 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000156 s/%USER%/${STACK_USER}/g;
zhang-hared98a5d02013-06-21 18:18:02 +0800157 " -i ${apache_vhost_dir}/object-server-${node_number}
158 ! is_fedora && sudo a2ensite object-server-${node_number}
159
160 sudo cp ${SWIFT_DIR}/examples/wsgi/object-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
161 sudo sed -e "
162 /^#/d;/^$/d;
163 s/%SERVICECONF%/object-server\/${node_number}.conf/g;
164 " -i ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
165
166 sudo cp ${SWIFT_DIR}/examples/apache2/container-server.template ${apache_vhost_dir}/container-server-${node_number}
167 sudo sed -e "
168 /^#/d;/^$/d;
169 s/%PORT%/$container_port/g;
170 s/%SERVICENAME%/container-server-${node_number}/g;
171 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000172 s/%USER%/${STACK_USER}/g;
zhang-hared98a5d02013-06-21 18:18:02 +0800173 " -i ${apache_vhost_dir}/container-server-${node_number}
174 ! is_fedora && sudo a2ensite container-server-${node_number}
175
176 sudo cp ${SWIFT_DIR}/examples/wsgi/container-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
177 sudo sed -e "
178 /^#/d;/^$/d;
179 s/%SERVICECONF%/container-server\/${node_number}.conf/g;
180 " -i ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
181
182 sudo cp ${SWIFT_DIR}/examples/apache2/account-server.template ${apache_vhost_dir}/account-server-${node_number}
183 sudo sed -e "
184 /^#/d;/^$/d;
185 s/%PORT%/$account_port/g;
186 s/%SERVICENAME%/account-server-${node_number}/g;
187 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000188 s/%USER%/${STACK_USER}/g;
zhang-hared98a5d02013-06-21 18:18:02 +0800189 " -i ${apache_vhost_dir}/account-server-${node_number}
190 ! is_fedora && sudo a2ensite account-server-${node_number}
191
192 sudo cp ${SWIFT_DIR}/examples/wsgi/account-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
193 sudo sed -e "
194 /^#/d;/^$/d;
195 s/%SERVICECONF%/account-server\/${node_number}.conf/g;
196 " -i ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
197
198 done
199
200 # run apache server as stack user
201 change_apache_user_group ${STACK_USER}
202
203 # WSGI isn't enabled by default, enable it
204 ! is_fedora && sudo a2enmod wsgi
Attila Fazekasece6a332012-11-29 14:19:41 +0100205}
206
207# configure_swift() - Set config files, create data dirs and loop image
208function configure_swift() {
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100209 local swift_pipeline=" "
Attila Fazekasece6a332012-11-29 14:19:41 +0100210 local node_number
211 local swift_node_config
212 local swift_log_dir
213
Attila Fazekasece6a332012-11-29 14:19:41 +0100214 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100215 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100216
Dean Troyer1c6c1122013-03-27 17:40:53 -0500217 sudo mkdir -p ${SWIFT_CONF_DIR}/{object,container,account}-server
218 sudo chown -R $USER: ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100219
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500220 if [[ "$SWIFT_CONF_DIR" != "/etc/swift" ]]; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100221 # Some swift tools are hard-coded to use ``/etc/swift`` and are apparently not going to be fixed.
222 # Create a symlink if the config dir is moved
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500223 sudo ln -sf ${SWIFT_CONF_DIR} /etc/swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100224 fi
225
226 # Swift use rsync to synchronize between all the different
227 # partitions (which make more sense when you have a multi-node
228 # setup) we configure it with our version of rsync.
229 sed -e "
230 s/%GROUP%/${USER_GROUP}/;
231 s/%USER%/$USER/;
232 s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,;
233 " $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf
234 # rsyncd.conf just prepared for 4 nodes
Vincent Untzc18b9652012-12-04 12:36:34 +0100235 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100236 sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync
237 else
238 sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync
239 fi
240
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500241 SWIFT_CONFIG_PROXY_SERVER=${SWIFT_CONF_DIR}/proxy-server.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100242 cp ${SWIFT_DIR}/etc/proxy-server.conf-sample ${SWIFT_CONFIG_PROXY_SERVER}
243
244 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user
245 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user ${USER}
246
247 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500248 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100249
250 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers
251 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1
252
253 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level
254 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level DEBUG
255
256 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port
257 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT:-8080}
258
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000259 # By default Swift will be installed with keystone and tempauth middleware
260 # and add the swift3 middleware if its configured for it. The token for
261 # tempauth would be prefixed with the reseller_prefix setting TEMPAUTH_ the
262 # token for keystoneauth would have the standard reseller_prefix AUTH_
263 if is_service_enabled swift3;then
264 swift_pipeline=" swift3 s3token "
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100265 fi
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000266 swift_pipeline+=" authtoken keystoneauth tempauth "
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100267 sed -i "/^pipeline/ { s/tempauth/${swift_pipeline} ${SWIFT_EXTRAS_MIDDLEWARE}/ ;}" ${SWIFT_CONFIG_PROXY_SERVER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100268
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000269 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth account_autocreate
Attila Fazekasece6a332012-11-29 14:19:41 +0100270 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server account_autocreate true
271
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000272 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix
273 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix "TEMPAUTH"
274
Attila Fazekasece6a332012-11-29 14:19:41 +0100275 # Configure Keystone
276 sed -i '/^# \[filter:authtoken\]/,/^# \[filter:keystoneauth\]$/ s/^#[ \t]*//' ${SWIFT_CONFIG_PROXY_SERVER}
277 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_host $KEYSTONE_AUTH_HOST
278 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_port $KEYSTONE_AUTH_PORT
279 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
280 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
281 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
282 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_user swift
283 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_password $SERVICE_PASSWORD
Dean Troyer64ab7742012-12-28 15:38:28 -0600284 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken signing_dir $SWIFT_AUTH_CACHE_DIR
Attila Fazekasece6a332012-11-29 14:19:41 +0100285
286 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use
287 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles
288 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin"
289
290 if is_service_enabled swift3; then
291 cat <<EOF >>${SWIFT_CONFIG_PROXY_SERVER}
292# NOTE(chmou): s3token middleware is not updated yet to use only
293# username and password.
294[filter:s3token]
295paste.filter_factory = keystone.middleware.s3_token:filter_factory
296auth_port = ${KEYSTONE_AUTH_PORT}
297auth_host = ${KEYSTONE_AUTH_HOST}
298auth_protocol = ${KEYSTONE_AUTH_PROTOCOL}
299auth_token = ${SERVICE_TOKEN}
300admin_token = ${SERVICE_TOKEN}
301
302[filter:swift3]
303use = egg:swift3#swift3
304EOF
305 fi
306
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500307 cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONF_DIR}/swift.conf
308 iniset ${SWIFT_CONF_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH}
Attila Fazekasece6a332012-11-29 14:19:41 +0100309
310 # This function generates an object/account/proxy configuration
311 # emulating 4 nodes on different ports
312 function generate_swift_config() {
313 local swift_node_config=$1
314 local node_id=$2
315 local bind_port=$3
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000316 local server_type=$4
Attila Fazekasece6a332012-11-29 14:19:41 +0100317
318 log_facility=$[ node_id - 1 ]
319 node_path=${SWIFT_DATA_DIR}/${node_number}
320
321 iniuncomment ${swift_node_config} DEFAULT user
322 iniset ${swift_node_config} DEFAULT user ${USER}
323
324 iniuncomment ${swift_node_config} DEFAULT bind_port
325 iniset ${swift_node_config} DEFAULT bind_port ${bind_port}
326
327 iniuncomment ${swift_node_config} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500328 iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100329
330 iniuncomment ${swift_node_config} DEFAULT devices
331 iniset ${swift_node_config} DEFAULT devices ${node_path}
332
333 iniuncomment ${swift_node_config} DEFAULT log_facility
334 iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility}
335
Chmouel Boudjnah82c09962013-07-16 07:16:07 +0000336 iniuncomment ${swift_node_config} DEFAULT disable_fallocate
337 iniset ${swift_node_config} DEFAULT disable_fallocate true
338
Attila Fazekasece6a332012-11-29 14:19:41 +0100339 iniuncomment ${swift_node_config} DEFAULT mount_check
340 iniset ${swift_node_config} DEFAULT mount_check false
341
342 iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode
343 iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes
344 }
345
346 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500347 swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100348 cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000349 generate_swift_config ${swift_node_config} ${node_number} $[OBJECT_PORT_BASE + 10 * (node_number - 1)] object
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000350 iniset ${swift_node_config} filter:recon recon_cache_path ${SWIFT_DATA_DIR}/cache
351 # Using a sed and not iniset/iniuncomment because we want to a global
352 # modification and make sure it works for new sections.
353 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100354
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500355 swift_node_config=${SWIFT_CONF_DIR}/container-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100356 cp ${SWIFT_DIR}/etc/container-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000357 generate_swift_config ${swift_node_config} ${node_number} $[CONTAINER_PORT_BASE + 10 * (node_number - 1)] container
Attila Fazekas83e10952012-11-30 23:28:07 +0100358 iniuncomment ${swift_node_config} app:container-server allow_versions
359 iniset ${swift_node_config} app:container-server allow_versions "true"
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000360 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100361
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500362 swift_node_config=${SWIFT_CONF_DIR}/account-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100363 cp ${SWIFT_DIR}/etc/account-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000364 generate_swift_config ${swift_node_config} ${node_number} $[ACCOUNT_PORT_BASE + 10 * (node_number - 1)] account
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000365 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100366 done
367
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000368 # Set new accounts in tempauth to match keystone tenant/user (to make testing easier)
369 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest1 "testing .admin"
370 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest2_swiftusertest2 "testing2 .admin"
371 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest3 "testing3 .admin"
372
373 testfile=${SWIFT_CONF_DIR}/test.conf
374 cp ${SWIFT_DIR}/test/sample.conf ${testfile}
375
376 # Set accounts for functional tests
377 iniset ${testfile} func_test account swifttenanttest1
378 iniset ${testfile} func_test username swiftusertest1
379 iniset ${testfile} func_test username3 swiftusertest3
380 iniset ${testfile} func_test account2 swifttenanttest2
381 iniset ${testfile} func_test username2 swiftusertest2
382
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000383 if is_service_enabled key;then
384 iniuncomment ${testfile} func_test auth_version
385 iniset ${testfile} func_test auth_host ${KEYSTONE_SERVICE_HOST}
386 iniset ${testfile} func_test auth_port ${KEYSTONE_AUTH_PORT}
387 iniset ${testfile} func_test auth_prefix /v2.0/
388 fi
389
Attila Fazekasece6a332012-11-29 14:19:41 +0100390 swift_log_dir=${SWIFT_DATA_DIR}/logs
391 rm -rf ${swift_log_dir}
392 mkdir -p ${swift_log_dir}/hourly
393 sudo chown -R $USER:adm ${swift_log_dir}
394 sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \
395 tee /etc/rsyslog.d/10-swift.conf
zhang-hared98a5d02013-06-21 18:18:02 +0800396 if is_apache_enabled_service swift; then
397 _config_swift_apache_wsgi
398 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100399}
400
Dean Troyer1c6c1122013-03-27 17:40:53 -0500401# create_swift_disk - Create Swift backing disk
402function create_swift_disk() {
403 local node_number
404
405 # First do a bit of setup by creating the directories and
406 # changing the permissions so we can run it as our user.
407
408 USER_GROUP=$(id -g)
409 sudo mkdir -p ${SWIFT_DATA_DIR}/{drives,cache,run,logs}
410 sudo chown -R $USER:${USER_GROUP} ${SWIFT_DATA_DIR}
411
412 # Create a loopback disk and format it to XFS.
413 if [[ -e ${SWIFT_DATA_DIR}/drives/images/swift.img ]]; then
414 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
415 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
416 sudo rm -f ${SWIFT_DATA_DIR}/drives/images/swift.img
417 fi
418 fi
419
420 mkdir -p ${SWIFT_DATA_DIR}/drives/images
421 sudo touch ${SWIFT_DATA_DIR}/drives/images/swift.img
422 sudo chown $USER: ${SWIFT_DATA_DIR}/drives/images/swift.img
423
424 dd if=/dev/zero of=${SWIFT_DATA_DIR}/drives/images/swift.img \
425 bs=1024 count=0 seek=${SWIFT_LOOPBACK_DISK_SIZE}
426
427 # Make a fresh XFS filesystem
428 mkfs.xfs -f -i size=1024 ${SWIFT_DATA_DIR}/drives/images/swift.img
429
430 # Mount the disk with mount options to make it as efficient as possible
431 mkdir -p ${SWIFT_DATA_DIR}/drives/sdb1
432 if ! egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
433 sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8 \
434 ${SWIFT_DATA_DIR}/drives/images/swift.img ${SWIFT_DATA_DIR}/drives/sdb1
435 fi
436
437 # Create a link to the above mount and
438 # create all of the directories needed to emulate a few different servers
439 for node_number in ${SWIFT_REPLICAS_SEQ}; do
440 sudo ln -sf ${SWIFT_DATA_DIR}/drives/sdb1/$node_number ${SWIFT_DATA_DIR}/$node_number;
441 drive=${SWIFT_DATA_DIR}/drives/sdb1/${node_number}
442 node=${SWIFT_DATA_DIR}/${node_number}/node
443 node_device=${node}/sdb1
444 [[ -d $node ]] && continue
445 [[ -d $drive ]] && continue
446 sudo install -o ${USER} -g $USER_GROUP -d $drive
447 sudo install -o ${USER} -g $USER_GROUP -d $node_device
448 sudo chown -R $USER: ${node}
449 done
450}
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200451# create_swift_accounts() - Set up standard swift accounts and extra
452# one for tests we do this by attaching all words in the account name
453# since we want to make it compatible with tempauth which use
454# underscores for separators.
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000455
456# Tenant User Roles
457# ------------------------------------------------------------------
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200458# service swift service
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000459# swifttenanttest1 swiftusertest1 admin
460# swifttenanttest1 swiftusertest3 anotherrole
461# swifttenanttest2 swiftusertest2 admin
462
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000463function create_swift_accounts() {
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200464 KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql}
465
466 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
467 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
468
469 SWIFT_USER=$(keystone user-create --name=swift --pass="$SERVICE_PASSWORD" \
470 --tenant_id $SERVICE_TENANT --email=swift@example.com | grep " id " | get_field 2)
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200471 keystone user-role-add --tenant-id $SERVICE_TENANT --user-id $SWIFT_USER --role-id $ADMIN_ROLE
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200472
473 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
474 SWIFT_SERVICE=$(keystone service-create --name=swift --type="object-store" \
475 --description="Swift Service" | grep " id " | get_field 2)
476 keystone endpoint-create \
477 --region RegionOne \
478 --service_id $SWIFT_SERVICE \
479 --publicurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \
480 --adminurl "http://$SERVICE_HOST:8080" \
481 --internalurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s"
482 fi
483
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000484 SWIFT_TENANT_TEST1=$(keystone tenant-create --name=swifttenanttest1 | grep " id " | get_field 2)
485 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 +0200486 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 +0000487
488 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 +0200489 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 +0000490
491 SWIFT_TENANT_TEST2=$(keystone tenant-create --name=swifttenanttest2 | grep " id " | get_field 2)
492 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 +0200493 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 +0000494}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500495
Attila Fazekasece6a332012-11-29 14:19:41 +0100496# init_swift() - Initialize rings
497function init_swift() {
498 local node_number
499 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100500 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100501
Dean Troyer1c6c1122013-03-27 17:40:53 -0500502 # Forcibly re-create the backing filesystem
503 create_swift_disk
504
Attila Fazekasece6a332012-11-29 14:19:41 +0100505 # This is where we create three different rings for swift with
506 # different object servers binding on different ports.
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500507 pushd ${SWIFT_CONF_DIR} >/dev/null && {
Attila Fazekasece6a332012-11-29 14:19:41 +0100508
509 rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
510
511 swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
512 swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
513 swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
514
515 for node_number in ${SWIFT_REPLICAS_SEQ}; do
516 swift-ring-builder object.builder add z${node_number}-127.0.0.1:$[OBJECT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
517 swift-ring-builder container.builder add z${node_number}-127.0.0.1:$[CONTAINER_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
518 swift-ring-builder account.builder add z${node_number}-127.0.0.1:$[ACCOUNT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
519 done
520 swift-ring-builder object.builder rebalance
521 swift-ring-builder container.builder rebalance
522 swift-ring-builder account.builder rebalance
523 } && popd >/dev/null
524
Dean Troyer64ab7742012-12-28 15:38:28 -0600525 # Create cache dir
526 sudo mkdir -p $SWIFT_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100527 sudo chown $STACK_USER $SWIFT_AUTH_CACHE_DIR
Dean Troyer64ab7742012-12-28 15:38:28 -0600528 rm -f $SWIFT_AUTH_CACHE_DIR/*
Attila Fazekasece6a332012-11-29 14:19:41 +0100529}
530
531function install_swift() {
532 git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500533 setup_develop $SWIFT_DIR
zhang-hared98a5d02013-06-21 18:18:02 +0800534 if is_apache_enabled_service swift; then
535 install_apache_wsgi
536 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100537}
538
539function install_swiftclient() {
540 git_clone $SWIFTCLIENT_REPO $SWIFTCLIENT_DIR $SWIFTCLIENT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500541 setup_develop $SWIFTCLIENT_DIR
Attila Fazekasece6a332012-11-29 14:19:41 +0100542}
543
Attila Fazekasece6a332012-11-29 14:19:41 +0100544# start_swift() - Start running processes, including screen
545function start_swift() {
546 # (re)start rsyslog
547 restart_service rsyslog
Chmouel Boudjnah8ecbb382013-03-12 12:15:17 +0100548 # (re)start memcached to make sure we have a clean memcache.
549 restart_service memcached
550
Attila Fazekasece6a332012-11-29 14:19:41 +0100551 # Start rsync
Vincent Untzc18b9652012-12-04 12:36:34 +0100552 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100553 sudo /etc/init.d/rsync restart || :
554 else
555 sudo systemctl start xinetd.service
556 fi
557
zhang-hared98a5d02013-06-21 18:18:02 +0800558 if is_apache_enabled_service swift; then
559 # Make sure the apache lock dir is owned by $STACK_USER
560 # for running apache server to avoid failure of restarting
561 # apache server due to permission problem.
562 sudo chown -R $STACK_USER /var/run/lock/$APACHE_NAME
563 restart_apache_server
564 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest start
565 screen_it s-proxy "cd $SWIFT_DIR && sudo tail -f /var/log/$APACHE_NAME/proxy-server"
566 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
567 for type in object container account; do
568 screen_it s-${type} "cd $SWIFT_DIR && sudo tail -f /var/log/$APACHE_NAME/${type}-server-1"
569 done
570 fi
571 return 0
572 fi
573
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100574 # By default with only one replica we are launching the proxy,
575 # container, account and object server in screen in foreground and
576 # other services in background. If we have SWIFT_REPLICAS set to something
577 # greater than one we first spawn all the swift services then kill the proxy
578 # service so we can run it in foreground in screen. ``swift-init ...
579 # {stop|restart}`` exits with '1' if no servers are running, ignore it just
580 # in case
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100581 swift-init --run-dir=${SWIFT_DATA_DIR}/run all restart || true
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500582 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100583 todo="object container account"
584 fi
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500585 for type in proxy ${todo}; do
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100586 swift-init --run-dir=${SWIFT_DATA_DIR}/run ${type} stop || true
587 done
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500588 screen_it s-proxy "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONF_DIR}/proxy-server.conf -v"
589 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
zhang-hared98a5d02013-06-21 18:18:02 +0800590 for type in object container account; do
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500591 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 +0100592 done
593 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100594}
595
596# stop_swift() - Stop running processes (non-screen)
597function stop_swift() {
zhang-hared98a5d02013-06-21 18:18:02 +0800598
599 if is_apache_enabled_service swift; then
600 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest stop && return 0
601 fi
602
Attila Fazekasece6a332012-11-29 14:19:41 +0100603 # screen normally killed by unstack.sh
Dean Troyer995eb922013-03-07 16:11:40 -0600604 if type -p swift-init >/dev/null; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100605 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
606 fi
Dean Troyer995eb922013-03-07 16:11:40 -0600607 # Dump the proxy server
608 sudo pkill -f swift-proxy-server
Attila Fazekasece6a332012-11-29 14:19:41 +0100609}
610
611# Restore xtrace
612$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400613
614# Local variables:
615# mode: shell-script
616# End: