blob: 28ca8a80dfbe82e345698778ea59310d593c3e24 [file] [log] [blame]
Attila Fazekasece6a332012-11-29 14:19:41 +01001# lib/swift
Dean Troyer6d04fd72012-12-21 11:03:37 -06002# Functions to control the configuration and operation of the **Swift** service
Attila Fazekasece6a332012-11-29 14:19:41 +01003
4# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01005#
6# - ``functions`` file
7# - ``apache`` file
8# - ``DEST``, ``SCREEN_NAME``, `SWIFT_HASH` must be defined
9# - ``STACK_USER`` must be defined
10# - ``SWIFT_DATA_DIR`` or ``DATA_DIR`` must be defined
11# - ``lib/keystone`` file
12#
Attila Fazekasece6a332012-11-29 14:19:41 +010013# ``stack.sh`` calls the entry points in this order:
14#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010015# - install_swift
16# - _config_swift_apache_wsgi
17# - configure_swift
18# - init_swift
19# - start_swift
20# - stop_swift
21# - cleanup_swift
22# - _cleanup_swift_apache_wsgi
Attila Fazekasece6a332012-11-29 14:19:41 +010023
24# Save trace setting
25XTRACE=$(set +o | grep xtrace)
26set +o xtrace
27
28
29# Defaults
30# --------
31
Attila Fazekasece6a332012-11-29 14:19:41 +010032# Set up default directories
Attila Fazekasece6a332012-11-29 14:19:41 +010033SWIFT_DIR=$DEST/swift
34SWIFTCLIENT_DIR=$DEST/python-swiftclient
Dean Troyer64ab7742012-12-28 15:38:28 -060035SWIFT_AUTH_CACHE_DIR=${SWIFT_AUTH_CACHE_DIR:-/var/cache/swift}
zhang-hared98a5d02013-06-21 18:18:02 +080036SWIFT_APACHE_WSGI_DIR=${SWIFT_APACHE_WSGI_DIR:-/var/www/swift}
Dean Troyerb7490da2013-03-18 16:07:56 -050037SWIFT3_DIR=$DEST/swift3
Attila Fazekasece6a332012-11-29 14:19:41 +010038
39# TODO: add logging to different location.
40
41# Set ``SWIFT_DATA_DIR`` to the location of swift drives and objects.
42# Default is the common DevStack data directory.
43SWIFT_DATA_DIR=${SWIFT_DATA_DIR:-${DATA_DIR}/swift}
Attila Fazekase6024412013-09-15 18:38:48 +020044SWIFT_DISK_IMAGE=${SWIFT_DATA_DIR}/drives/images/swift.img
Attila Fazekasece6a332012-11-29 14:19:41 +010045
Dean Troyer6ec72fa2013-03-13 11:44:53 -050046# Set ``SWIFT_CONF_DIR`` to the location of the configuration files.
Attila Fazekasece6a332012-11-29 14:19:41 +010047# Default is ``/etc/swift``.
Dean Troyer6ec72fa2013-03-13 11:44:53 -050048# TODO(dtroyer): remove SWIFT_CONFIG_DIR after cutting stable/grizzly
49SWIFT_CONF_DIR=${SWIFT_CONF_DIR:-${SWIFT_CONFIG_DIR:-/etc/swift}}
Attila Fazekasece6a332012-11-29 14:19:41 +010050
Dean Troyerb7490da2013-03-18 16:07:56 -050051if is_service_enabled s-proxy && is_service_enabled swift3; then
52 # If we are using swift3, we can default the s3 port to swift instead
53 # of nova-objectstore
54 S3_SERVICE_PORT=${S3_SERVICE_PORT:-8080}
55fi
56
Attila Fazekasece6a332012-11-29 14:19:41 +010057# DevStack will create a loop-back disk formatted as XFS to store the
Kevin Lydad66c9652013-01-09 13:39:57 +000058# swift data. Set ``SWIFT_LOOPBACK_DISK_SIZE`` to the disk size in
59# kilobytes.
Attila Fazekasece6a332012-11-29 14:19:41 +010060# Default is 1 gigabyte.
Attila Fazekase6024412013-09-15 18:38:48 +020061SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=1G
Joe Gordon66c54242013-11-12 16:24:14 -080062# if tempest enabled the default size is 6 Gigabyte.
Attila Fazekas3418c1c2013-09-16 18:35:49 +020063if is_service_enabled tempest; then
Joe Gordon66c54242013-11-12 16:24:14 -080064 SWIFT_LOOPBACK_DISK_SIZE_DEFAULT=${SWIFT_LOOPBACK_DISK_SIZE:-6G}
Attila Fazekas3418c1c2013-09-16 18:35:49 +020065fi
66
67SWIFT_LOOPBACK_DISK_SIZE=${SWIFT_LOOPBACK_DISK_SIZE:-$SWIFT_LOOPBACK_DISK_SIZE_DEFAULT}
Attila Fazekasece6a332012-11-29 14:19:41 +010068
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010069# Set ``SWIFT_EXTRAS_MIDDLEWARE`` to extras middlewares.
Chmouel Boudjnah1fba1aa2013-08-02 00:40:05 +020070# Default is ``staticweb, tempurl, formpost``
71SWIFT_EXTRAS_MIDDLEWARE=${SWIFT_EXTRAS_MIDDLEWARE:-tempurl formpost staticweb}
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010072
Cyril Roelandtd9883402013-09-27 15:16:51 +000073# Set ``SWIFT_EXTRAS_MIDDLEWARE_LAST`` to extras middlewares that need to be at
74# the end of the pipeline.
75SWIFT_EXTRAS_MIDDLEWARE_LAST=${SWIFT_EXTRAS_MIDDLEWARE_LAST}
76
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +020077# Set ``SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH`` to extras middlewares that need to be at
78# the beginning of the pipeline, before authentication middlewares.
79SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH=${SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH:-crossdomain}
80
Attila Fazekasece6a332012-11-29 14:19:41 +010081# The ring uses a configurable number of bits from a path’s MD5 hash as
82# a partition index that designates a device. The number of bits kept
83# from the hash is known as the partition power, and 2 to the partition
84# power indicates the partition count. Partitioning the full MD5 hash
85# ring allows other parts of the cluster to work in batches of items at
86# once which ends up either more efficient or at least less complex than
87# working with each item separately or the entire cluster all at once.
88# By default we define 9 for the partition count (which mean 512).
89SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9}
90
91# Set ``SWIFT_REPLICAS`` to configure how many replicas are to be
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +010092# configured for your Swift cluster. By default we are configuring
93# only one replica since this is way less CPU and memory intensive. If
94# you are planning to test swift replication you may want to set this
95# up to 3.
96SWIFT_REPLICAS=${SWIFT_REPLICAS:-1}
Attila Fazekasece6a332012-11-29 14:19:41 +010097SWIFT_REPLICAS_SEQ=$(seq ${SWIFT_REPLICAS})
98
Peter Portantecee4b3b2013-11-20 14:33:16 -050099# Set ``SWIFT_LOG_TOKEN_LENGTH`` to configure how many characters of an auth
100# token should be placed in the logs. When keystone is used with PKI tokens,
101# the token values can be huge, seemingly larger the 2K, at the least. We
102# restrict it here to a default of 12 characters, which should be enough to
103# trace through the logs when looking for its use.
104SWIFT_LOG_TOKEN_LENGTH=${SWIFT_LOG_TOKEN_LENGTH:-12}
105
Attila Fazekasece6a332012-11-29 14:19:41 +0100106# Set ``OBJECT_PORT_BASE``, ``CONTAINER_PORT_BASE``, ``ACCOUNT_PORT_BASE``
107# Port bases used in port number calclution for the service "nodes"
108# The specified port number will be used, the additinal ports calculated by
109# base_port + node_num * 10
Dean Troyer1151d6f2013-03-29 14:06:52 -0500110OBJECT_PORT_BASE=${OBJECT_PORT_BASE:-6013}
111CONTAINER_PORT_BASE=${CONTAINER_PORT_BASE:-6011}
112ACCOUNT_PORT_BASE=${ACCOUNT_PORT_BASE:-6012}
Attila Fazekasece6a332012-11-29 14:19:41 +0100113
Dean Troyer4237f592014-01-29 16:22:11 -0600114# Tell Tempest this project is present
115TEMPEST_SERVICES+=,swift
116
Dean Troyer6d04fd72012-12-21 11:03:37 -0600117
Dean Troyercc6b4432013-04-08 15:38:03 -0500118# Functions
119# ---------
Attila Fazekasece6a332012-11-29 14:19:41 +0100120
121# cleanup_swift() - Remove residual data files
122function cleanup_swift() {
Sean Dague101b4242013-10-22 08:47:11 -0400123 rm -f ${SWIFT_CONF_DIR}{*.builder,*.ring.gz,backups/*.builder,backups/*.ring.gz}
124 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
125 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
126 fi
127 if [[ -e ${SWIFT_DISK_IMAGE} ]]; then
128 rm ${SWIFT_DISK_IMAGE}
129 fi
130 rm -rf ${SWIFT_DATA_DIR}/run/
131 if is_apache_enabled_service swift; then
132 _cleanup_swift_apache_wsgi
133 fi
zhang-hared98a5d02013-06-21 18:18:02 +0800134}
135
136# _cleanup_swift_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
137function _cleanup_swift_apache_wsgi() {
138 sudo rm -f $SWIFT_APACHE_WSGI_DIR/*.wsgi
Jamie Lennox54707012013-09-17 12:07:48 +1000139 disable_apache_site proxy-server
zhang-hared98a5d02013-06-21 18:18:02 +0800140 for node_number in ${SWIFT_REPLICAS_SEQ}; do
141 for type in object container account; do
142 site_name=${type}-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000143 disable_apache_site ${site_name}
zhang-hared98a5d02013-06-21 18:18:02 +0800144 sudo rm -f /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site_name}
145 done
146 done
147}
148
149# _config_swift_apache_wsgi() - Set WSGI config files of Swift
150function _config_swift_apache_wsgi() {
151 sudo mkdir -p ${SWIFT_APACHE_WSGI_DIR}
152 local apache_vhost_dir=/etc/${APACHE_NAME}/$APACHE_CONF_DIR
153 local proxy_port=${SWIFT_DEFAULT_BIND_PORT:-8080}
154
155 # copy proxy vhost and wsgi file
156 sudo cp ${SWIFT_DIR}/examples/apache2/proxy-server.template ${apache_vhost_dir}/proxy-server
157 sudo sed -e "
158 /^#/d;/^$/d;
159 s/%PORT%/$proxy_port/g;
160 s/%SERVICENAME%/proxy-server/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}/proxy-server
Jamie Lennox54707012013-09-17 12:07:48 +1000164 enable_apache_site proxy-server
zhang-hared98a5d02013-06-21 18:18:02 +0800165
166 sudo cp ${SWIFT_DIR}/examples/wsgi/proxy-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
167 sudo sed -e "
168 /^#/d;/^$/d;
169 s/%SERVICECONF%/proxy-server.conf/g;
170 " -i ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi
zhang-hared98a5d02013-06-21 18:18:02 +0800171
172 # copy apache vhost file and set name and port
173 for node_number in ${SWIFT_REPLICAS_SEQ}; do
174 object_port=$[OBJECT_PORT_BASE + 10 * ($node_number - 1)]
175 container_port=$[CONTAINER_PORT_BASE + 10 * ($node_number - 1)]
176 account_port=$[ACCOUNT_PORT_BASE + 10 * ($node_number - 1)]
177
178 sudo cp ${SWIFT_DIR}/examples/apache2/object-server.template ${apache_vhost_dir}/object-server-${node_number}
179 sudo sed -e "
180 s/%PORT%/$object_port/g;
181 s/%SERVICENAME%/object-server-${node_number}/g;
182 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000183 s/%USER%/${STACK_USER}/g;
zhang-hared98a5d02013-06-21 18:18:02 +0800184 " -i ${apache_vhost_dir}/object-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000185 enable_apache_site object-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800186
187 sudo cp ${SWIFT_DIR}/examples/wsgi/object-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
188 sudo sed -e "
189 /^#/d;/^$/d;
190 s/%SERVICECONF%/object-server\/${node_number}.conf/g;
191 " -i ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi
192
193 sudo cp ${SWIFT_DIR}/examples/apache2/container-server.template ${apache_vhost_dir}/container-server-${node_number}
194 sudo sed -e "
195 /^#/d;/^$/d;
196 s/%PORT%/$container_port/g;
197 s/%SERVICENAME%/container-server-${node_number}/g;
198 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000199 s/%USER%/${STACK_USER}/g;
zhang-hared98a5d02013-06-21 18:18:02 +0800200 " -i ${apache_vhost_dir}/container-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000201 enable_apache_site container-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800202
203 sudo cp ${SWIFT_DIR}/examples/wsgi/container-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
204 sudo sed -e "
205 /^#/d;/^$/d;
206 s/%SERVICECONF%/container-server\/${node_number}.conf/g;
207 " -i ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi
208
209 sudo cp ${SWIFT_DIR}/examples/apache2/account-server.template ${apache_vhost_dir}/account-server-${node_number}
210 sudo sed -e "
Sean Dague101b4242013-10-22 08:47:11 -0400211 /^#/d;/^$/d;
zhang-hared98a5d02013-06-21 18:18:02 +0800212 s/%PORT%/$account_port/g;
213 s/%SERVICENAME%/account-server-${node_number}/g;
214 s/%APACHE_NAME%/${APACHE_NAME}/g;
Jamie Lennoxd5824602013-09-17 11:44:37 +1000215 s/%USER%/${STACK_USER}/g;
zhang-hared98a5d02013-06-21 18:18:02 +0800216 " -i ${apache_vhost_dir}/account-server-${node_number}
Jamie Lennox54707012013-09-17 12:07:48 +1000217 enable_apache_site account-server-${node_number}
zhang-hared98a5d02013-06-21 18:18:02 +0800218
219 sudo cp ${SWIFT_DIR}/examples/wsgi/account-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
220 sudo sed -e "
Sean Dague101b4242013-10-22 08:47:11 -0400221 /^#/d;/^$/d;
zhang-hared98a5d02013-06-21 18:18:02 +0800222 s/%SERVICECONF%/account-server\/${node_number}.conf/g;
223 " -i ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi
zhang-hared98a5d02013-06-21 18:18:02 +0800224 done
Attila Fazekasece6a332012-11-29 14:19:41 +0100225}
226
227# configure_swift() - Set config files, create data dirs and loop image
228function configure_swift() {
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200229 local swift_pipeline="${SWIFT_EXTRAS_MIDDLEWARE_NO_AUTH}"
Attila Fazekasece6a332012-11-29 14:19:41 +0100230 local node_number
231 local swift_node_config
232 local swift_log_dir
233
Attila Fazekasece6a332012-11-29 14:19:41 +0100234 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100235 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100236
Dean Troyer1c6c1122013-03-27 17:40:53 -0500237 sudo mkdir -p ${SWIFT_CONF_DIR}/{object,container,account}-server
Stephan Renatuse578eff2013-11-19 13:31:04 +0100238 sudo chown -R ${STACK_USER}: ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100239
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500240 if [[ "$SWIFT_CONF_DIR" != "/etc/swift" ]]; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100241 # Some swift tools are hard-coded to use ``/etc/swift`` and are apparently not going to be fixed.
242 # Create a symlink if the config dir is moved
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500243 sudo ln -sf ${SWIFT_CONF_DIR} /etc/swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100244 fi
245
246 # Swift use rsync to synchronize between all the different
247 # partitions (which make more sense when you have a multi-node
248 # setup) we configure it with our version of rsync.
249 sed -e "
250 s/%GROUP%/${USER_GROUP}/;
Stephan Renatuse578eff2013-11-19 13:31:04 +0100251 s/%USER%/${STACK_USER}/;
Attila Fazekasece6a332012-11-29 14:19:41 +0100252 s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,;
253 " $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf
254 # rsyncd.conf just prepared for 4 nodes
Vincent Untzc18b9652012-12-04 12:36:34 +0100255 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100256 sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync
257 else
258 sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync
259 fi
260
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500261 SWIFT_CONFIG_PROXY_SERVER=${SWIFT_CONF_DIR}/proxy-server.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100262 cp ${SWIFT_DIR}/etc/proxy-server.conf-sample ${SWIFT_CONFIG_PROXY_SERVER}
263
Chmouel Boudjnahf2c1a712014-01-29 21:38:14 +0000264 cp ${SWIFT_DIR}/etc/container-sync-realms.conf-sample ${SWIFT_CONF_DIR}/container-sync-realms.conf
265
Attila Fazekasece6a332012-11-29 14:19:41 +0100266 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user
Stephan Renatuse578eff2013-11-19 13:31:04 +0100267 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user ${STACK_USER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100268
269 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500270 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100271
272 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers
273 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1
274
275 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level
276 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level DEBUG
277
278 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port
279 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT:-8080}
280
Joe Gordond254da52013-11-19 21:06:29 -0800281 # Devstack is commonly run in a small slow environment, so bump the
282 # timeouts up.
283 # node_timeout is how long between read operations a node takes to
284 # respond to the proxy server
285 # conn_timeout is all about how long it takes a connect() system call to
286 # return
287 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server node_timeout 120
288 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server conn_timeout 20
289
Cyril Roelandtd9883402013-09-27 15:16:51 +0000290 # Configure Ceilometer
291 if is_service_enabled ceilometer; then
292 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:ceilometer use "egg:ceilometer#swift"
293 SWIFT_EXTRAS_MIDDLEWARE_LAST="${SWIFT_EXTRAS_MIDDLEWARE_LAST} ceilometer"
294 fi
295
Peter Portantecee4b3b2013-11-20 14:33:16 -0500296 # Restrict the length of auth tokens in the swift proxy-server logs.
297 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:proxy-logging reveal_sensitive_prefix ${SWIFT_LOG_TOKEN_LENGTH}
298
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000299 # By default Swift will be installed with keystone and tempauth middleware
300 # and add the swift3 middleware if its configured for it. The token for
Adam Spierscb961592013-10-05 12:11:07 +0100301 # tempauth would be prefixed with the reseller_prefix setting `TEMPAUTH_` the
302 # token for keystoneauth would have the standard reseller_prefix `AUTH_`
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000303 if is_service_enabled swift3;then
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200304 swift_pipeline+=" swift3 s3token "
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100305 fi
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000306 swift_pipeline+=" authtoken keystoneauth tempauth "
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100307 sed -i "/^pipeline/ { s/tempauth/${swift_pipeline} ${SWIFT_EXTRAS_MIDDLEWARE}/ ;}" ${SWIFT_CONFIG_PROXY_SERVER}
Cyril Roelandtd9883402013-09-27 15:16:51 +0000308 sed -i "/^pipeline/ { s/proxy-server/${SWIFT_EXTRAS_MIDDLEWARE_LAST} proxy-server/ ; }" ${SWIFT_CONFIG_PROXY_SERVER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100309
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000310 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth account_autocreate
Attila Fazekasece6a332012-11-29 14:19:41 +0100311 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server account_autocreate true
312
Chmouel Boudjnah5cac3782013-07-17 15:13:44 +0000313 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix
314 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth reseller_prefix "TEMPAUTH"
315
Joe H. Rahme1ce2ffd2013-10-22 15:19:09 +0200316 # Configure Crossdomain
317 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:crossdomain use "egg:swift#crossdomain"
318
Attila Fazekasece6a332012-11-29 14:19:41 +0100319 # Configure Keystone
320 sed -i '/^# \[filter:authtoken\]/,/^# \[filter:keystoneauth\]$/ s/^#[ \t]*//' ${SWIFT_CONFIG_PROXY_SERVER}
321 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_host $KEYSTONE_AUTH_HOST
322 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_port $KEYSTONE_AUTH_PORT
323 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000324 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken cafile $KEYSTONE_SSL_CA
Attila Fazekasece6a332012-11-29 14:19:41 +0100325 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
326 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
327 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_user swift
328 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_password $SERVICE_PASSWORD
Dean Troyer64ab7742012-12-28 15:38:28 -0600329 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken signing_dir $SWIFT_AUTH_CACHE_DIR
Peter Portante8afc8932013-11-20 17:34:39 -0500330 # This causes the authtoken middleware to use the same python logging
331 # adapter provided by the swift proxy-server, so that request transaction
332 # IDs will included in all of its log messages.
333 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken log_name swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100334
335 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use
336 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles
337 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin"
338
339 if is_service_enabled swift3; then
340 cat <<EOF >>${SWIFT_CONFIG_PROXY_SERVER}
341# NOTE(chmou): s3token middleware is not updated yet to use only
342# username and password.
343[filter:s3token]
344paste.filter_factory = keystone.middleware.s3_token:filter_factory
345auth_port = ${KEYSTONE_AUTH_PORT}
346auth_host = ${KEYSTONE_AUTH_HOST}
347auth_protocol = ${KEYSTONE_AUTH_PROTOCOL}
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000348cafile = ${KEYSTONE_SSL_CA}
Attila Fazekasece6a332012-11-29 14:19:41 +0100349auth_token = ${SERVICE_TOKEN}
350admin_token = ${SERVICE_TOKEN}
351
352[filter:swift3]
353use = egg:swift3#swift3
354EOF
355 fi
356
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500357 cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONF_DIR}/swift.conf
358 iniset ${SWIFT_CONF_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH}
Attila Fazekasece6a332012-11-29 14:19:41 +0100359
Peter Portantecee4b3b2013-11-20 14:33:16 -0500360 # This function generates an object/container/account configuration
Attila Fazekasece6a332012-11-29 14:19:41 +0100361 # emulating 4 nodes on different ports
362 function generate_swift_config() {
363 local swift_node_config=$1
364 local node_id=$2
365 local bind_port=$3
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000366 local server_type=$4
Attila Fazekasece6a332012-11-29 14:19:41 +0100367
368 log_facility=$[ node_id - 1 ]
369 node_path=${SWIFT_DATA_DIR}/${node_number}
370
371 iniuncomment ${swift_node_config} DEFAULT user
Stephan Renatuse578eff2013-11-19 13:31:04 +0100372 iniset ${swift_node_config} DEFAULT user ${STACK_USER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100373
374 iniuncomment ${swift_node_config} DEFAULT bind_port
375 iniset ${swift_node_config} DEFAULT bind_port ${bind_port}
376
377 iniuncomment ${swift_node_config} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500378 iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100379
380 iniuncomment ${swift_node_config} DEFAULT devices
381 iniset ${swift_node_config} DEFAULT devices ${node_path}
382
383 iniuncomment ${swift_node_config} DEFAULT log_facility
384 iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility}
385
Chmouel Boudjnah63d9f3e2013-12-21 01:19:09 -0800386 iniuncomment ${swift_node_config} DEFAULT workers
387 iniset ${swift_node_config} DEFAULT workers 1
Chmouel Boudjnah86d9aed2013-12-10 12:24:16 +0000388
Chmouel Boudjnah82c09962013-07-16 07:16:07 +0000389 iniuncomment ${swift_node_config} DEFAULT disable_fallocate
390 iniset ${swift_node_config} DEFAULT disable_fallocate true
391
Attila Fazekasece6a332012-11-29 14:19:41 +0100392 iniuncomment ${swift_node_config} DEFAULT mount_check
393 iniset ${swift_node_config} DEFAULT mount_check false
394
395 iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode
396 iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes
397 }
398
399 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500400 swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100401 cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000402 generate_swift_config ${swift_node_config} ${node_number} $[OBJECT_PORT_BASE + 10 * (node_number - 1)] object
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000403 iniset ${swift_node_config} filter:recon recon_cache_path ${SWIFT_DATA_DIR}/cache
404 # Using a sed and not iniset/iniuncomment because we want to a global
405 # modification and make sure it works for new sections.
406 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100407
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500408 swift_node_config=${SWIFT_CONF_DIR}/container-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100409 cp ${SWIFT_DIR}/etc/container-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000410 generate_swift_config ${swift_node_config} ${node_number} $[CONTAINER_PORT_BASE + 10 * (node_number - 1)] container
Attila Fazekas83e10952012-11-30 23:28:07 +0100411 iniuncomment ${swift_node_config} app:container-server allow_versions
412 iniset ${swift_node_config} app:container-server allow_versions "true"
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000413 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100414
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500415 swift_node_config=${SWIFT_CONF_DIR}/account-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100416 cp ${SWIFT_DIR}/etc/account-server.conf-sample ${swift_node_config}
Chmouel Boudjnah35633f02013-07-16 07:35:13 +0000417 generate_swift_config ${swift_node_config} ${node_number} $[ACCOUNT_PORT_BASE + 10 * (node_number - 1)] account
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000418 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100419 done
420
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000421 # Set new accounts in tempauth to match keystone tenant/user (to make testing easier)
422 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest1 "testing .admin"
423 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest2_swiftusertest2 "testing2 .admin"
424 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:tempauth user_swifttenanttest1_swiftusertest3 "testing3 .admin"
425
426 testfile=${SWIFT_CONF_DIR}/test.conf
427 cp ${SWIFT_DIR}/test/sample.conf ${testfile}
428
429 # Set accounts for functional tests
430 iniset ${testfile} func_test account swifttenanttest1
431 iniset ${testfile} func_test username swiftusertest1
432 iniset ${testfile} func_test username3 swiftusertest3
433 iniset ${testfile} func_test account2 swifttenanttest2
434 iniset ${testfile} func_test username2 swiftusertest2
435
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000436 if is_service_enabled key;then
437 iniuncomment ${testfile} func_test auth_version
438 iniset ${testfile} func_test auth_host ${KEYSTONE_SERVICE_HOST}
439 iniset ${testfile} func_test auth_port ${KEYSTONE_AUTH_PORT}
440 iniset ${testfile} func_test auth_prefix /v2.0/
441 fi
442
Attila Fazekasece6a332012-11-29 14:19:41 +0100443 swift_log_dir=${SWIFT_DATA_DIR}/logs
444 rm -rf ${swift_log_dir}
445 mkdir -p ${swift_log_dir}/hourly
Stephan Renatuse578eff2013-11-19 13:31:04 +0100446 sudo chown -R ${STACK_USER}:adm ${swift_log_dir}
Attila Fazekasece6a332012-11-29 14:19:41 +0100447 sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \
448 tee /etc/rsyslog.d/10-swift.conf
zhang-hared98a5d02013-06-21 18:18:02 +0800449 if is_apache_enabled_service swift; then
450 _config_swift_apache_wsgi
451 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100452}
453
Dean Troyer1c6c1122013-03-27 17:40:53 -0500454# create_swift_disk - Create Swift backing disk
455function create_swift_disk() {
456 local node_number
457
458 # First do a bit of setup by creating the directories and
459 # changing the permissions so we can run it as our user.
460
Stephan Renatuse578eff2013-11-19 13:31:04 +0100461 USER_GROUP=$(id -g ${STACK_USER})
Dean Troyer1c6c1122013-03-27 17:40:53 -0500462 sudo mkdir -p ${SWIFT_DATA_DIR}/{drives,cache,run,logs}
Stephan Renatuse578eff2013-11-19 13:31:04 +0100463 sudo chown -R ${STACK_USER}:${USER_GROUP} ${SWIFT_DATA_DIR}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500464
465 # Create a loopback disk and format it to XFS.
Attila Fazekase6024412013-09-15 18:38:48 +0200466 if [[ -e ${SWIFT_DISK_IMAGE} ]]; then
Dean Troyer1c6c1122013-03-27 17:40:53 -0500467 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
468 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
Attila Fazekase6024412013-09-15 18:38:48 +0200469 sudo rm -f ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500470 fi
471 fi
472
473 mkdir -p ${SWIFT_DATA_DIR}/drives/images
Attila Fazekase6024412013-09-15 18:38:48 +0200474 sudo touch ${SWIFT_DISK_IMAGE}
Stephan Renatuse578eff2013-11-19 13:31:04 +0100475 sudo chown ${STACK_USER}: ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500476
Attila Fazekase6024412013-09-15 18:38:48 +0200477 truncate -s ${SWIFT_LOOPBACK_DISK_SIZE} ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500478
479 # Make a fresh XFS filesystem
Attila Fazekase6024412013-09-15 18:38:48 +0200480 mkfs.xfs -f -i size=1024 ${SWIFT_DISK_IMAGE}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500481
482 # Mount the disk with mount options to make it as efficient as possible
483 mkdir -p ${SWIFT_DATA_DIR}/drives/sdb1
484 if ! egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
485 sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8 \
Attila Fazekase6024412013-09-15 18:38:48 +0200486 ${SWIFT_DISK_IMAGE} ${SWIFT_DATA_DIR}/drives/sdb1
Dean Troyer1c6c1122013-03-27 17:40:53 -0500487 fi
488
489 # Create a link to the above mount and
490 # create all of the directories needed to emulate a few different servers
491 for node_number in ${SWIFT_REPLICAS_SEQ}; do
492 sudo ln -sf ${SWIFT_DATA_DIR}/drives/sdb1/$node_number ${SWIFT_DATA_DIR}/$node_number;
493 drive=${SWIFT_DATA_DIR}/drives/sdb1/${node_number}
494 node=${SWIFT_DATA_DIR}/${node_number}/node
495 node_device=${node}/sdb1
496 [[ -d $node ]] && continue
497 [[ -d $drive ]] && continue
Stephan Renatuse578eff2013-11-19 13:31:04 +0100498 sudo install -o ${STACK_USER} -g $USER_GROUP -d $drive
499 sudo install -o ${STACK_USER} -g $USER_GROUP -d $node_device
500 sudo chown -R ${STACK_USER}: ${node}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500501 done
502}
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200503# create_swift_accounts() - Set up standard swift accounts and extra
504# one for tests we do this by attaching all words in the account name
505# since we want to make it compatible with tempauth which use
506# underscores for separators.
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000507
508# Tenant User Roles
509# ------------------------------------------------------------------
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200510# service swift service
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000511# swifttenanttest1 swiftusertest1 admin
512# swifttenanttest1 swiftusertest3 anotherrole
513# swifttenanttest2 swiftusertest2 admin
514
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000515function create_swift_accounts() {
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200516 KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql}
517
518 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
519 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
520
521 SWIFT_USER=$(keystone user-create --name=swift --pass="$SERVICE_PASSWORD" \
Dirk Mueller25049cd2014-01-09 13:53:52 +0100522 --tenant-id $SERVICE_TENANT --email=swift@example.com | grep " id " | get_field 2)
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200523 keystone user-role-add --tenant-id $SERVICE_TENANT --user-id $SWIFT_USER --role-id $ADMIN_ROLE
Chmouel Boudjnahba313052013-07-10 21:03:43 +0200524
525 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
526 SWIFT_SERVICE=$(keystone service-create --name=swift --type="object-store" \
527 --description="Swift Service" | grep " id " | get_field 2)
528 keystone endpoint-create \
529 --region RegionOne \
530 --service_id $SWIFT_SERVICE \
531 --publicurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \
532 --adminurl "http://$SERVICE_HOST:8080" \
533 --internalurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s"
534 fi
535
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000536 SWIFT_TENANT_TEST1=$(keystone tenant-create --name=swifttenanttest1 | grep " id " | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500537 die_if_not_set $LINENO SWIFT_TENANT_TEST1 "Failure creating SWIFT_TENANT_TEST1"
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000538 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 -0500539 die_if_not_set $LINENO SWIFT_USER_TEST1 "Failure creating SWIFT_USER_TEST1"
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200540 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 +0000541
542 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 -0500543 die_if_not_set $LINENO SWIFT_USER_TEST3 "Failure creating SWIFT_USER_TEST3"
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200544 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 +0000545
546 SWIFT_TENANT_TEST2=$(keystone tenant-create --name=swifttenanttest2 | grep " id " | get_field 2)
DennyZhang23178a92013-10-22 17:07:32 -0500547 die_if_not_set $LINENO SWIFT_TENANT_TEST2 "Failure creating SWIFT_TENANT_TEST2"
Chmouel Boudjnah0ce91a52013-07-05 11:59:24 +0000548 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 -0500549 die_if_not_set $LINENO SWIFT_USER_TEST2 "Failure creating SWIFT_USER_TEST2"
Jorge Valderrama Romerof39ee962013-09-02 17:18:40 +0200550 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 +0000551}
Dean Troyer1c6c1122013-03-27 17:40:53 -0500552
Attila Fazekasece6a332012-11-29 14:19:41 +0100553# init_swift() - Initialize rings
554function init_swift() {
555 local node_number
556 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100557 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100558
Dean Troyer1c6c1122013-03-27 17:40:53 -0500559 # Forcibly re-create the backing filesystem
560 create_swift_disk
561
Attila Fazekasece6a332012-11-29 14:19:41 +0100562 # This is where we create three different rings for swift with
563 # different object servers binding on different ports.
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500564 pushd ${SWIFT_CONF_DIR} >/dev/null && {
Attila Fazekasece6a332012-11-29 14:19:41 +0100565
566 rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
567
568 swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
569 swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
570 swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
571
572 for node_number in ${SWIFT_REPLICAS_SEQ}; do
573 swift-ring-builder object.builder add z${node_number}-127.0.0.1:$[OBJECT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
574 swift-ring-builder container.builder add z${node_number}-127.0.0.1:$[CONTAINER_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
575 swift-ring-builder account.builder add z${node_number}-127.0.0.1:$[ACCOUNT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
576 done
577 swift-ring-builder object.builder rebalance
578 swift-ring-builder container.builder rebalance
579 swift-ring-builder account.builder rebalance
580 } && popd >/dev/null
581
Dean Troyer64ab7742012-12-28 15:38:28 -0600582 # Create cache dir
583 sudo mkdir -p $SWIFT_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100584 sudo chown $STACK_USER $SWIFT_AUTH_CACHE_DIR
Dean Troyer64ab7742012-12-28 15:38:28 -0600585 rm -f $SWIFT_AUTH_CACHE_DIR/*
Attila Fazekasece6a332012-11-29 14:19:41 +0100586}
587
588function install_swift() {
589 git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500590 setup_develop $SWIFT_DIR
zhang-hared98a5d02013-06-21 18:18:02 +0800591 if is_apache_enabled_service swift; then
592 install_apache_wsgi
593 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100594}
595
596function install_swiftclient() {
597 git_clone $SWIFTCLIENT_REPO $SWIFTCLIENT_DIR $SWIFTCLIENT_BRANCH
Dean Troyer253a1a32013-04-01 18:23:22 -0500598 setup_develop $SWIFTCLIENT_DIR
Attila Fazekasece6a332012-11-29 14:19:41 +0100599}
600
Attila Fazekasece6a332012-11-29 14:19:41 +0100601# start_swift() - Start running processes, including screen
602function start_swift() {
603 # (re)start rsyslog
604 restart_service rsyslog
Chmouel Boudjnah8ecbb382013-03-12 12:15:17 +0100605 # (re)start memcached to make sure we have a clean memcache.
606 restart_service memcached
607
Attila Fazekasece6a332012-11-29 14:19:41 +0100608 # Start rsync
Vincent Untzc18b9652012-12-04 12:36:34 +0100609 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100610 sudo /etc/init.d/rsync restart || :
611 else
612 sudo systemctl start xinetd.service
613 fi
614
zhang-hared98a5d02013-06-21 18:18:02 +0800615 if is_apache_enabled_service swift; then
zhang-hared98a5d02013-06-21 18:18:02 +0800616 restart_apache_server
617 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest start
618 screen_it s-proxy "cd $SWIFT_DIR && sudo tail -f /var/log/$APACHE_NAME/proxy-server"
619 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
620 for type in object container account; do
621 screen_it s-${type} "cd $SWIFT_DIR && sudo tail -f /var/log/$APACHE_NAME/${type}-server-1"
622 done
623 fi
624 return 0
625 fi
626
Sean Dague101b4242013-10-22 08:47:11 -0400627 # By default with only one replica we are launching the proxy,
628 # container, account and object server in screen in foreground and
629 # other services in background. If we have SWIFT_REPLICAS set to something
630 # greater than one we first spawn all the swift services then kill the proxy
631 # service so we can run it in foreground in screen. ``swift-init ...
632 # {stop|restart}`` exits with '1' if no servers are running, ignore it just
633 # in case
634 swift-init --run-dir=${SWIFT_DATA_DIR}/run all restart || true
635 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100636 todo="object container account"
Sean Dague101b4242013-10-22 08:47:11 -0400637 fi
638 for type in proxy ${todo}; do
639 swift-init --run-dir=${SWIFT_DATA_DIR}/run ${type} stop || true
640 done
641 screen_it s-proxy "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONF_DIR}/proxy-server.conf -v"
642 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
643 for type in object container account; do
644 screen_it s-${type} "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-${type}-server ${SWIFT_CONF_DIR}/${type}-server/1.conf -v"
645 done
646 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100647}
648
649# stop_swift() - Stop running processes (non-screen)
650function stop_swift() {
zhang-hared98a5d02013-06-21 18:18:02 +0800651
652 if is_apache_enabled_service swift; then
653 swift-init --run-dir=${SWIFT_DATA_DIR}/run rest stop && return 0
654 fi
655
Attila Fazekasece6a332012-11-29 14:19:41 +0100656 # screen normally killed by unstack.sh
Dean Troyer995eb922013-03-07 16:11:40 -0600657 if type -p swift-init >/dev/null; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100658 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
659 fi
Chmouel Boudjnahf36a9b22014-02-03 23:44:47 +0100660 # Dump all of the servers
661 pkill -f swift-
Attila Fazekasece6a332012-11-29 14:19:41 +0100662}
663
664# Restore xtrace
665$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400666
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100667# Tell emacs to use shell-script-mode
668## Local variables:
669## mode: shell-script
670## End: