blob: d50b554169756dbcb78ef76eae696351de5c7a36 [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
6# ``DEST``, ``SCREEN_NAME``, `SWIFT_HASH` must be defined
Attila Fazekas91b8d132013-01-06 22:40:09 +01007# ``STACK_USER`` must be defined
Attila Fazekasece6a332012-11-29 14:19:41 +01008# ``SWIFT_DATA_DIR`` or ``DATA_DIR`` must be defined
9# ``lib/keystone`` file
10# ``stack.sh`` calls the entry points in this order:
11#
12# install_swift
13# configure_swift
14# init_swift
15# start_swift
16# stop_swift
17# cleanup_swift
18
19# Save trace setting
20XTRACE=$(set +o | grep xtrace)
21set +o xtrace
22
23
24# Defaults
25# --------
26
Attila Fazekasece6a332012-11-29 14:19:41 +010027# Set up default directories
Attila Fazekasece6a332012-11-29 14:19:41 +010028SWIFT_DIR=$DEST/swift
29SWIFTCLIENT_DIR=$DEST/python-swiftclient
Dean Troyer64ab7742012-12-28 15:38:28 -060030SWIFT_AUTH_CACHE_DIR=${SWIFT_AUTH_CACHE_DIR:-/var/cache/swift}
Dean Troyerb7490da2013-03-18 16:07:56 -050031SWIFT3_DIR=$DEST/swift3
Attila Fazekasece6a332012-11-29 14:19:41 +010032
33# TODO: add logging to different location.
34
35# Set ``SWIFT_DATA_DIR`` to the location of swift drives and objects.
36# Default is the common DevStack data directory.
37SWIFT_DATA_DIR=${SWIFT_DATA_DIR:-${DATA_DIR}/swift}
38
Dean Troyer6ec72fa2013-03-13 11:44:53 -050039# Set ``SWIFT_CONF_DIR`` to the location of the configuration files.
Attila Fazekasece6a332012-11-29 14:19:41 +010040# Default is ``/etc/swift``.
Dean Troyer6ec72fa2013-03-13 11:44:53 -050041# TODO(dtroyer): remove SWIFT_CONFIG_DIR after cutting stable/grizzly
42SWIFT_CONF_DIR=${SWIFT_CONF_DIR:-${SWIFT_CONFIG_DIR:-/etc/swift}}
Attila Fazekasece6a332012-11-29 14:19:41 +010043
Dean Troyerb7490da2013-03-18 16:07:56 -050044if is_service_enabled s-proxy && is_service_enabled swift3; then
45 # If we are using swift3, we can default the s3 port to swift instead
46 # of nova-objectstore
47 S3_SERVICE_PORT=${S3_SERVICE_PORT:-8080}
48fi
49
Attila Fazekasece6a332012-11-29 14:19:41 +010050# DevStack will create a loop-back disk formatted as XFS to store the
Kevin Lydad66c9652013-01-09 13:39:57 +000051# swift data. Set ``SWIFT_LOOPBACK_DISK_SIZE`` to the disk size in
52# kilobytes.
Attila Fazekasece6a332012-11-29 14:19:41 +010053# Default is 1 gigabyte.
54SWIFT_LOOPBACK_DISK_SIZE=${SWIFT_LOOPBACK_DISK_SIZE:-1000000}
55
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010056# Set ``SWIFT_EXTRAS_MIDDLEWARE`` to extras middlewares.
57# Default is ``staticweb, tempurl, bulk, formpost``
58SWIFT_EXTRAS_MIDDLEWARE=${SWIFT_EXTRAS_MIDDLEWARE:-tempurl formpost staticweb bulk}
59
Attila Fazekasece6a332012-11-29 14:19:41 +010060# The ring uses a configurable number of bits from a path’s MD5 hash as
61# a partition index that designates a device. The number of bits kept
62# from the hash is known as the partition power, and 2 to the partition
63# power indicates the partition count. Partitioning the full MD5 hash
64# ring allows other parts of the cluster to work in batches of items at
65# once which ends up either more efficient or at least less complex than
66# working with each item separately or the entire cluster all at once.
67# By default we define 9 for the partition count (which mean 512).
68SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9}
69
70# Set ``SWIFT_REPLICAS`` to configure how many replicas are to be
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +010071# configured for your Swift cluster. By default we are configuring
72# only one replica since this is way less CPU and memory intensive. If
73# you are planning to test swift replication you may want to set this
74# up to 3.
75SWIFT_REPLICAS=${SWIFT_REPLICAS:-1}
Attila Fazekasece6a332012-11-29 14:19:41 +010076SWIFT_REPLICAS_SEQ=$(seq ${SWIFT_REPLICAS})
77
78# Set ``OBJECT_PORT_BASE``, ``CONTAINER_PORT_BASE``, ``ACCOUNT_PORT_BASE``
79# Port bases used in port number calclution for the service "nodes"
80# The specified port number will be used, the additinal ports calculated by
81# base_port + node_num * 10
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +010082OBJECT_PORT_BASE=6013
Attila Fazekasece6a332012-11-29 14:19:41 +010083CONTAINER_PORT_BASE=6011
84ACCOUNT_PORT_BASE=6012
85
Dean Troyer6d04fd72012-12-21 11:03:37 -060086
Attila Fazekasece6a332012-11-29 14:19:41 +010087# Entry Points
88# ------------
89
90# cleanup_swift() - Remove residual data files
91function cleanup_swift() {
Dean Troyer6ec72fa2013-03-13 11:44:53 -050092 rm -f ${SWIFT_CONF_DIR}{*.builder,*.ring.gz,backups/*.builder,backups/*.ring.gz}
Attila Fazekasece6a332012-11-29 14:19:41 +010093 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
94 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
95 fi
96 if [[ -e ${SWIFT_DATA_DIR}/drives/images/swift.img ]]; then
97 rm ${SWIFT_DATA_DIR}/drives/images/swift.img
98 fi
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010099 rm -rf ${SWIFT_DATA_DIR}/run/
Attila Fazekasece6a332012-11-29 14:19:41 +0100100}
101
102# configure_swift() - Set config files, create data dirs and loop image
103function configure_swift() {
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100104 local swift_pipeline=" "
Attila Fazekasece6a332012-11-29 14:19:41 +0100105 local node_number
106 local swift_node_config
107 local swift_log_dir
108
109 setup_develop $SWIFT_DIR
110
111 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100112 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100113
114 # First do a bit of setup by creating the directories and
115 # changing the permissions so we can run it as our user.
116
117 USER_GROUP=$(id -g)
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100118 sudo mkdir -p ${SWIFT_DATA_DIR}/{drives,cache,run,logs}
Attila Fazekasece6a332012-11-29 14:19:41 +0100119 sudo chown -R $USER:${USER_GROUP} ${SWIFT_DATA_DIR}
120
121 # Create a loopback disk and format it to XFS.
122 if [[ -e ${SWIFT_DATA_DIR}/drives/images/swift.img ]]; then
123 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
124 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
Chmouel Boudjnah43eb0b32013-01-12 20:10:34 +0000125 sudo rm -f ${SWIFT_DATA_DIR}/drives/images/swift.img
Attila Fazekasece6a332012-11-29 14:19:41 +0100126 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100127 fi
128
Chmouel Boudjnah43eb0b32013-01-12 20:10:34 +0000129 mkdir -p ${SWIFT_DATA_DIR}/drives/images
130 sudo touch ${SWIFT_DATA_DIR}/drives/images/swift.img
131 sudo chown $USER: ${SWIFT_DATA_DIR}/drives/images/swift.img
132
133 dd if=/dev/zero of=${SWIFT_DATA_DIR}/drives/images/swift.img \
134 bs=1024 count=0 seek=${SWIFT_LOOPBACK_DISK_SIZE}
135
Attila Fazekasece6a332012-11-29 14:19:41 +0100136 # Make a fresh XFS filesystem
137 mkfs.xfs -f -i size=1024 ${SWIFT_DATA_DIR}/drives/images/swift.img
138
139 # Mount the disk with mount options to make it as efficient as possible
140 mkdir -p ${SWIFT_DATA_DIR}/drives/sdb1
141 if ! egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
142 sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8 \
143 ${SWIFT_DATA_DIR}/drives/images/swift.img ${SWIFT_DATA_DIR}/drives/sdb1
144 fi
145
146 # Create a link to the above mount and
147 # create all of the directories needed to emulate a few different servers
148 for node_number in ${SWIFT_REPLICAS_SEQ}; do
149 sudo ln -sf ${SWIFT_DATA_DIR}/drives/sdb1/$node_number ${SWIFT_DATA_DIR}/$node_number;
150 drive=${SWIFT_DATA_DIR}/drives/sdb1/${node_number}
151 node=${SWIFT_DATA_DIR}/${node_number}/node
152 node_device=${node}/sdb1
153 [[ -d $node ]] && continue
154 [[ -d $drive ]] && continue
155 sudo install -o ${USER} -g $USER_GROUP -d $drive
156 sudo install -o ${USER} -g $USER_GROUP -d $node_device
157 sudo chown -R $USER: ${node}
158 done
159
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500160 sudo mkdir -p ${SWIFT_CONF_DIR}/{object,container,account}-server
161 sudo chown -R $USER: ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100162
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500163 if [[ "$SWIFT_CONF_DIR" != "/etc/swift" ]]; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100164 # Some swift tools are hard-coded to use ``/etc/swift`` and are apparently not going to be fixed.
165 # Create a symlink if the config dir is moved
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500166 sudo ln -sf ${SWIFT_CONF_DIR} /etc/swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100167 fi
168
169 # Swift use rsync to synchronize between all the different
170 # partitions (which make more sense when you have a multi-node
171 # setup) we configure it with our version of rsync.
172 sed -e "
173 s/%GROUP%/${USER_GROUP}/;
174 s/%USER%/$USER/;
175 s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,;
176 " $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf
177 # rsyncd.conf just prepared for 4 nodes
Vincent Untzc18b9652012-12-04 12:36:34 +0100178 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100179 sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync
180 else
181 sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync
182 fi
183
184 if is_service_enabled swift3;then
185 swift_auth_server="s3token "
186 fi
187
188 # By default Swift will be installed with the tempauth middleware
189 # which has some default username and password if you have
190 # configured keystone it will checkout the directory.
191 if is_service_enabled key; then
192 swift_auth_server+="authtoken keystoneauth"
193 else
194 swift_auth_server=tempauth
195 fi
196
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500197 SWIFT_CONFIG_PROXY_SERVER=${SWIFT_CONF_DIR}/proxy-server.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100198 cp ${SWIFT_DIR}/etc/proxy-server.conf-sample ${SWIFT_CONFIG_PROXY_SERVER}
199
200 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user
201 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user ${USER}
202
203 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500204 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100205
206 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers
207 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1
208
209 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level
210 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level DEBUG
211
212 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port
213 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT:-8080}
214
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100215 # By default Swift will be installed with the tempauth middleware
216 # which has some default username and password if you have
217 # configured keystone it will configure swift with it.
218 if is_service_enabled key;then
219 if is_service_enabled swift3;then
220 swift_pipeline=" s3token swift3 "
221 fi
222 swift_pipeline+=" authtoken keystoneauth "
223 else
224 if is_service_enabled swift3;then
225 swift_pipeline=" swift3 "
226 fi
227 swift_pipeline+=" tempauth "
228 fi
229 sed -i "/^pipeline/ { s/tempauth/${swift_pipeline} ${SWIFT_EXTRAS_MIDDLEWARE}/ ;}" ${SWIFT_CONFIG_PROXY_SERVER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100230
231 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server account_autocreate true
232
233 # Configure Keystone
234 sed -i '/^# \[filter:authtoken\]/,/^# \[filter:keystoneauth\]$/ s/^#[ \t]*//' ${SWIFT_CONFIG_PROXY_SERVER}
235 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_host $KEYSTONE_AUTH_HOST
236 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_port $KEYSTONE_AUTH_PORT
237 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
238 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
239 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
240 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_user swift
241 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_password $SERVICE_PASSWORD
Dean Troyer64ab7742012-12-28 15:38:28 -0600242 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken signing_dir $SWIFT_AUTH_CACHE_DIR
Attila Fazekasece6a332012-11-29 14:19:41 +0100243
244 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use
245 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles
246 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin"
247
248 if is_service_enabled swift3; then
249 cat <<EOF >>${SWIFT_CONFIG_PROXY_SERVER}
250# NOTE(chmou): s3token middleware is not updated yet to use only
251# username and password.
252[filter:s3token]
253paste.filter_factory = keystone.middleware.s3_token:filter_factory
254auth_port = ${KEYSTONE_AUTH_PORT}
255auth_host = ${KEYSTONE_AUTH_HOST}
256auth_protocol = ${KEYSTONE_AUTH_PROTOCOL}
257auth_token = ${SERVICE_TOKEN}
258admin_token = ${SERVICE_TOKEN}
259
260[filter:swift3]
261use = egg:swift3#swift3
262EOF
263 fi
264
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500265 cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONF_DIR}/swift.conf
266 iniset ${SWIFT_CONF_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH}
Attila Fazekasece6a332012-11-29 14:19:41 +0100267
268 # This function generates an object/account/proxy configuration
269 # emulating 4 nodes on different ports
270 function generate_swift_config() {
271 local swift_node_config=$1
272 local node_id=$2
273 local bind_port=$3
274
275 log_facility=$[ node_id - 1 ]
276 node_path=${SWIFT_DATA_DIR}/${node_number}
277
278 iniuncomment ${swift_node_config} DEFAULT user
279 iniset ${swift_node_config} DEFAULT user ${USER}
280
281 iniuncomment ${swift_node_config} DEFAULT bind_port
282 iniset ${swift_node_config} DEFAULT bind_port ${bind_port}
283
284 iniuncomment ${swift_node_config} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500285 iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100286
287 iniuncomment ${swift_node_config} DEFAULT devices
288 iniset ${swift_node_config} DEFAULT devices ${node_path}
289
290 iniuncomment ${swift_node_config} DEFAULT log_facility
291 iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility}
292
293 iniuncomment ${swift_node_config} DEFAULT mount_check
294 iniset ${swift_node_config} DEFAULT mount_check false
295
296 iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode
297 iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes
298 }
299
300 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500301 swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100302 cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config}
303 generate_swift_config ${swift_node_config} ${node_number} $[OBJECT_PORT_BASE + 10 * (node_number - 1)]
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000304 iniset ${swift_node_config} filter:recon recon_cache_path ${SWIFT_DATA_DIR}/cache
305 # Using a sed and not iniset/iniuncomment because we want to a global
306 # modification and make sure it works for new sections.
307 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100308
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500309 swift_node_config=${SWIFT_CONF_DIR}/container-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100310 cp ${SWIFT_DIR}/etc/container-server.conf-sample ${swift_node_config}
311 generate_swift_config ${swift_node_config} ${node_number} $[CONTAINER_PORT_BASE + 10 * (node_number - 1)]
Attila Fazekas83e10952012-11-30 23:28:07 +0100312 iniuncomment ${swift_node_config} app:container-server allow_versions
313 iniset ${swift_node_config} app:container-server allow_versions "true"
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000314 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100315
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500316 swift_node_config=${SWIFT_CONF_DIR}/account-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100317 cp ${SWIFT_DIR}/etc/account-server.conf-sample ${swift_node_config}
318 generate_swift_config ${swift_node_config} ${node_number} $[ACCOUNT_PORT_BASE + 10 * (node_number - 1)]
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000319 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100320 done
321
322 swift_log_dir=${SWIFT_DATA_DIR}/logs
323 rm -rf ${swift_log_dir}
324 mkdir -p ${swift_log_dir}/hourly
325 sudo chown -R $USER:adm ${swift_log_dir}
326 sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \
327 tee /etc/rsyslog.d/10-swift.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100328}
329
330# configure_swiftclient() - Set config files, create data dirs, etc
331function configure_swiftclient() {
332 setup_develop $SWIFTCLIENT_DIR
333}
334
335# init_swift() - Initialize rings
336function init_swift() {
337 local node_number
338 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100339 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100340
341 # This is where we create three different rings for swift with
342 # different object servers binding on different ports.
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500343 pushd ${SWIFT_CONF_DIR} >/dev/null && {
Attila Fazekasece6a332012-11-29 14:19:41 +0100344
345 rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
346
347 swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
348 swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
349 swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
350
351 for node_number in ${SWIFT_REPLICAS_SEQ}; do
352 swift-ring-builder object.builder add z${node_number}-127.0.0.1:$[OBJECT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
353 swift-ring-builder container.builder add z${node_number}-127.0.0.1:$[CONTAINER_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
354 swift-ring-builder account.builder add z${node_number}-127.0.0.1:$[ACCOUNT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
355 done
356 swift-ring-builder object.builder rebalance
357 swift-ring-builder container.builder rebalance
358 swift-ring-builder account.builder rebalance
359 } && popd >/dev/null
360
Dean Troyer64ab7742012-12-28 15:38:28 -0600361 # Create cache dir
362 sudo mkdir -p $SWIFT_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100363 sudo chown $STACK_USER $SWIFT_AUTH_CACHE_DIR
Dean Troyer64ab7742012-12-28 15:38:28 -0600364 rm -f $SWIFT_AUTH_CACHE_DIR/*
Attila Fazekasece6a332012-11-29 14:19:41 +0100365}
366
367function install_swift() {
368 git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH
369}
370
371function install_swiftclient() {
372 git_clone $SWIFTCLIENT_REPO $SWIFTCLIENT_DIR $SWIFTCLIENT_BRANCH
373}
374
375
376# start_swift() - Start running processes, including screen
377function start_swift() {
378 # (re)start rsyslog
379 restart_service rsyslog
Chmouel Boudjnah8ecbb382013-03-12 12:15:17 +0100380 # (re)start memcached to make sure we have a clean memcache.
381 restart_service memcached
382
Attila Fazekasece6a332012-11-29 14:19:41 +0100383 # Start rsync
Vincent Untzc18b9652012-12-04 12:36:34 +0100384 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100385 sudo /etc/init.d/rsync restart || :
386 else
387 sudo systemctl start xinetd.service
388 fi
389
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100390 # By default with only one replica we are launching the proxy,
391 # container, account and object server in screen in foreground and
392 # other services in background. If we have SWIFT_REPLICAS set to something
393 # greater than one we first spawn all the swift services then kill the proxy
394 # service so we can run it in foreground in screen. ``swift-init ...
395 # {stop|restart}`` exits with '1' if no servers are running, ignore it just
396 # in case
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100397 swift-init --run-dir=${SWIFT_DATA_DIR}/run all restart || true
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500398 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100399 todo="object container account"
400 fi
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500401 for type in proxy ${todo}; do
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100402 swift-init --run-dir=${SWIFT_DATA_DIR}/run ${type} stop || true
403 done
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500404 screen_it s-proxy "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONF_DIR}/proxy-server.conf -v"
405 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100406 for type in object container account;do
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500407 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 +0100408 done
409 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100410}
411
412# stop_swift() - Stop running processes (non-screen)
413function stop_swift() {
414 # screen normally killed by unstack.sh
Dean Troyer995eb922013-03-07 16:11:40 -0600415 if type -p swift-init >/dev/null; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100416 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
417 fi
Dean Troyer995eb922013-03-07 16:11:40 -0600418 # Dump the proxy server
419 sudo pkill -f swift-proxy-server
Attila Fazekasece6a332012-11-29 14:19:41 +0100420}
421
422# Restore xtrace
423$XTRACE