blob: 2c87d21f6a798901497b461051ac15c4ef45f974 [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}
Attila Fazekasece6a332012-11-29 14:19:41 +010031
32# TODO: add logging to different location.
33
34# Set ``SWIFT_DATA_DIR`` to the location of swift drives and objects.
35# Default is the common DevStack data directory.
36SWIFT_DATA_DIR=${SWIFT_DATA_DIR:-${DATA_DIR}/swift}
37
Dean Troyer6ec72fa2013-03-13 11:44:53 -050038# Set ``SWIFT_CONF_DIR`` to the location of the configuration files.
Attila Fazekasece6a332012-11-29 14:19:41 +010039# Default is ``/etc/swift``.
Dean Troyer6ec72fa2013-03-13 11:44:53 -050040# TODO(dtroyer): remove SWIFT_CONFIG_DIR after cutting stable/grizzly
41SWIFT_CONF_DIR=${SWIFT_CONF_DIR:-${SWIFT_CONFIG_DIR:-/etc/swift}}
Attila Fazekasece6a332012-11-29 14:19:41 +010042
43# DevStack will create a loop-back disk formatted as XFS to store the
Kevin Lydad66c9652013-01-09 13:39:57 +000044# swift data. Set ``SWIFT_LOOPBACK_DISK_SIZE`` to the disk size in
45# kilobytes.
Attila Fazekasece6a332012-11-29 14:19:41 +010046# Default is 1 gigabyte.
47SWIFT_LOOPBACK_DISK_SIZE=${SWIFT_LOOPBACK_DISK_SIZE:-1000000}
48
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010049# Set ``SWIFT_EXTRAS_MIDDLEWARE`` to extras middlewares.
50# Default is ``staticweb, tempurl, bulk, formpost``
51SWIFT_EXTRAS_MIDDLEWARE=${SWIFT_EXTRAS_MIDDLEWARE:-tempurl formpost staticweb bulk}
52
Attila Fazekasece6a332012-11-29 14:19:41 +010053# The ring uses a configurable number of bits from a path’s MD5 hash as
54# a partition index that designates a device. The number of bits kept
55# from the hash is known as the partition power, and 2 to the partition
56# power indicates the partition count. Partitioning the full MD5 hash
57# ring allows other parts of the cluster to work in batches of items at
58# once which ends up either more efficient or at least less complex than
59# working with each item separately or the entire cluster all at once.
60# By default we define 9 for the partition count (which mean 512).
61SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9}
62
63# Set ``SWIFT_REPLICAS`` to configure how many replicas are to be
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +010064# configured for your Swift cluster. By default we are configuring
65# only one replica since this is way less CPU and memory intensive. If
66# you are planning to test swift replication you may want to set this
67# up to 3.
68SWIFT_REPLICAS=${SWIFT_REPLICAS:-1}
Attila Fazekasece6a332012-11-29 14:19:41 +010069SWIFT_REPLICAS_SEQ=$(seq ${SWIFT_REPLICAS})
70
71# Set ``OBJECT_PORT_BASE``, ``CONTAINER_PORT_BASE``, ``ACCOUNT_PORT_BASE``
72# Port bases used in port number calclution for the service "nodes"
73# The specified port number will be used, the additinal ports calculated by
74# base_port + node_num * 10
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +010075OBJECT_PORT_BASE=6013
Attila Fazekasece6a332012-11-29 14:19:41 +010076CONTAINER_PORT_BASE=6011
77ACCOUNT_PORT_BASE=6012
78
Dean Troyer6d04fd72012-12-21 11:03:37 -060079
Attila Fazekasece6a332012-11-29 14:19:41 +010080# Entry Points
81# ------------
82
83# cleanup_swift() - Remove residual data files
84function cleanup_swift() {
Dean Troyer6ec72fa2013-03-13 11:44:53 -050085 rm -f ${SWIFT_CONF_DIR}{*.builder,*.ring.gz,backups/*.builder,backups/*.ring.gz}
Attila Fazekasece6a332012-11-29 14:19:41 +010086 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
87 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
88 fi
89 if [[ -e ${SWIFT_DATA_DIR}/drives/images/swift.img ]]; then
90 rm ${SWIFT_DATA_DIR}/drives/images/swift.img
91 fi
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010092 rm -rf ${SWIFT_DATA_DIR}/run/
Attila Fazekasece6a332012-11-29 14:19:41 +010093}
94
95# configure_swift() - Set config files, create data dirs and loop image
96function configure_swift() {
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +010097 local swift_pipeline=" "
Attila Fazekasece6a332012-11-29 14:19:41 +010098 local node_number
99 local swift_node_config
100 local swift_log_dir
101
102 setup_develop $SWIFT_DIR
103
104 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100105 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100106
107 # First do a bit of setup by creating the directories and
108 # changing the permissions so we can run it as our user.
109
110 USER_GROUP=$(id -g)
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100111 sudo mkdir -p ${SWIFT_DATA_DIR}/{drives,cache,run,logs}
Attila Fazekasece6a332012-11-29 14:19:41 +0100112 sudo chown -R $USER:${USER_GROUP} ${SWIFT_DATA_DIR}
113
114 # Create a loopback disk and format it to XFS.
115 if [[ -e ${SWIFT_DATA_DIR}/drives/images/swift.img ]]; then
116 if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
117 sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
Chmouel Boudjnah43eb0b32013-01-12 20:10:34 +0000118 sudo rm -f ${SWIFT_DATA_DIR}/drives/images/swift.img
Attila Fazekasece6a332012-11-29 14:19:41 +0100119 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100120 fi
121
Chmouel Boudjnah43eb0b32013-01-12 20:10:34 +0000122 mkdir -p ${SWIFT_DATA_DIR}/drives/images
123 sudo touch ${SWIFT_DATA_DIR}/drives/images/swift.img
124 sudo chown $USER: ${SWIFT_DATA_DIR}/drives/images/swift.img
125
126 dd if=/dev/zero of=${SWIFT_DATA_DIR}/drives/images/swift.img \
127 bs=1024 count=0 seek=${SWIFT_LOOPBACK_DISK_SIZE}
128
Attila Fazekasece6a332012-11-29 14:19:41 +0100129 # Make a fresh XFS filesystem
130 mkfs.xfs -f -i size=1024 ${SWIFT_DATA_DIR}/drives/images/swift.img
131
132 # Mount the disk with mount options to make it as efficient as possible
133 mkdir -p ${SWIFT_DATA_DIR}/drives/sdb1
134 if ! egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
135 sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8 \
136 ${SWIFT_DATA_DIR}/drives/images/swift.img ${SWIFT_DATA_DIR}/drives/sdb1
137 fi
138
139 # Create a link to the above mount and
140 # create all of the directories needed to emulate a few different servers
141 for node_number in ${SWIFT_REPLICAS_SEQ}; do
142 sudo ln -sf ${SWIFT_DATA_DIR}/drives/sdb1/$node_number ${SWIFT_DATA_DIR}/$node_number;
143 drive=${SWIFT_DATA_DIR}/drives/sdb1/${node_number}
144 node=${SWIFT_DATA_DIR}/${node_number}/node
145 node_device=${node}/sdb1
146 [[ -d $node ]] && continue
147 [[ -d $drive ]] && continue
148 sudo install -o ${USER} -g $USER_GROUP -d $drive
149 sudo install -o ${USER} -g $USER_GROUP -d $node_device
150 sudo chown -R $USER: ${node}
151 done
152
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500153 sudo mkdir -p ${SWIFT_CONF_DIR}/{object,container,account}-server
154 sudo chown -R $USER: ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100155
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500156 if [[ "$SWIFT_CONF_DIR" != "/etc/swift" ]]; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100157 # Some swift tools are hard-coded to use ``/etc/swift`` and are apparently not going to be fixed.
158 # Create a symlink if the config dir is moved
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500159 sudo ln -sf ${SWIFT_CONF_DIR} /etc/swift
Attila Fazekasece6a332012-11-29 14:19:41 +0100160 fi
161
162 # Swift use rsync to synchronize between all the different
163 # partitions (which make more sense when you have a multi-node
164 # setup) we configure it with our version of rsync.
165 sed -e "
166 s/%GROUP%/${USER_GROUP}/;
167 s/%USER%/$USER/;
168 s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,;
169 " $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf
170 # rsyncd.conf just prepared for 4 nodes
Vincent Untzc18b9652012-12-04 12:36:34 +0100171 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100172 sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync
173 else
174 sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync
175 fi
176
177 if is_service_enabled swift3;then
178 swift_auth_server="s3token "
179 fi
180
181 # By default Swift will be installed with the tempauth middleware
182 # which has some default username and password if you have
183 # configured keystone it will checkout the directory.
184 if is_service_enabled key; then
185 swift_auth_server+="authtoken keystoneauth"
186 else
187 swift_auth_server=tempauth
188 fi
189
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500190 SWIFT_CONFIG_PROXY_SERVER=${SWIFT_CONF_DIR}/proxy-server.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100191 cp ${SWIFT_DIR}/etc/proxy-server.conf-sample ${SWIFT_CONFIG_PROXY_SERVER}
192
193 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user
194 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user ${USER}
195
196 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500197 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100198
199 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers
200 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1
201
202 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level
203 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level DEBUG
204
205 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port
206 iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT:-8080}
207
Chmouel Boudjnahbc3a3392013-02-23 04:00:51 +0100208 # By default Swift will be installed with the tempauth middleware
209 # which has some default username and password if you have
210 # configured keystone it will configure swift with it.
211 if is_service_enabled key;then
212 if is_service_enabled swift3;then
213 swift_pipeline=" s3token swift3 "
214 fi
215 swift_pipeline+=" authtoken keystoneauth "
216 else
217 if is_service_enabled swift3;then
218 swift_pipeline=" swift3 "
219 fi
220 swift_pipeline+=" tempauth "
221 fi
222 sed -i "/^pipeline/ { s/tempauth/${swift_pipeline} ${SWIFT_EXTRAS_MIDDLEWARE}/ ;}" ${SWIFT_CONFIG_PROXY_SERVER}
Attila Fazekasece6a332012-11-29 14:19:41 +0100223
224 iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server account_autocreate true
225
226 # Configure Keystone
227 sed -i '/^# \[filter:authtoken\]/,/^# \[filter:keystoneauth\]$/ s/^#[ \t]*//' ${SWIFT_CONFIG_PROXY_SERVER}
228 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_host $KEYSTONE_AUTH_HOST
229 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_port $KEYSTONE_AUTH_PORT
230 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
231 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
232 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
233 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_user swift
234 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_password $SERVICE_PASSWORD
Dean Troyer64ab7742012-12-28 15:38:28 -0600235 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken signing_dir $SWIFT_AUTH_CACHE_DIR
Attila Fazekasece6a332012-11-29 14:19:41 +0100236
237 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use
238 iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles
239 iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin"
240
241 if is_service_enabled swift3; then
242 cat <<EOF >>${SWIFT_CONFIG_PROXY_SERVER}
243# NOTE(chmou): s3token middleware is not updated yet to use only
244# username and password.
245[filter:s3token]
246paste.filter_factory = keystone.middleware.s3_token:filter_factory
247auth_port = ${KEYSTONE_AUTH_PORT}
248auth_host = ${KEYSTONE_AUTH_HOST}
249auth_protocol = ${KEYSTONE_AUTH_PROTOCOL}
250auth_token = ${SERVICE_TOKEN}
251admin_token = ${SERVICE_TOKEN}
252
253[filter:swift3]
254use = egg:swift3#swift3
255EOF
256 fi
257
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500258 cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONF_DIR}/swift.conf
259 iniset ${SWIFT_CONF_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH}
Attila Fazekasece6a332012-11-29 14:19:41 +0100260
261 # This function generates an object/account/proxy configuration
262 # emulating 4 nodes on different ports
263 function generate_swift_config() {
264 local swift_node_config=$1
265 local node_id=$2
266 local bind_port=$3
267
268 log_facility=$[ node_id - 1 ]
269 node_path=${SWIFT_DATA_DIR}/${node_number}
270
271 iniuncomment ${swift_node_config} DEFAULT user
272 iniset ${swift_node_config} DEFAULT user ${USER}
273
274 iniuncomment ${swift_node_config} DEFAULT bind_port
275 iniset ${swift_node_config} DEFAULT bind_port ${bind_port}
276
277 iniuncomment ${swift_node_config} DEFAULT swift_dir
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500278 iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONF_DIR}
Attila Fazekasece6a332012-11-29 14:19:41 +0100279
280 iniuncomment ${swift_node_config} DEFAULT devices
281 iniset ${swift_node_config} DEFAULT devices ${node_path}
282
283 iniuncomment ${swift_node_config} DEFAULT log_facility
284 iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility}
285
286 iniuncomment ${swift_node_config} DEFAULT mount_check
287 iniset ${swift_node_config} DEFAULT mount_check false
288
289 iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode
290 iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes
291 }
292
293 for node_number in ${SWIFT_REPLICAS_SEQ}; do
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500294 swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100295 cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config}
296 generate_swift_config ${swift_node_config} ${node_number} $[OBJECT_PORT_BASE + 10 * (node_number - 1)]
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000297 iniset ${swift_node_config} filter:recon recon_cache_path ${SWIFT_DATA_DIR}/cache
298 # Using a sed and not iniset/iniuncomment because we want to a global
299 # modification and make sure it works for new sections.
300 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100301
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500302 swift_node_config=${SWIFT_CONF_DIR}/container-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100303 cp ${SWIFT_DIR}/etc/container-server.conf-sample ${swift_node_config}
304 generate_swift_config ${swift_node_config} ${node_number} $[CONTAINER_PORT_BASE + 10 * (node_number - 1)]
Attila Fazekas83e10952012-11-30 23:28:07 +0100305 iniuncomment ${swift_node_config} app:container-server allow_versions
306 iniset ${swift_node_config} app:container-server allow_versions "true"
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000307 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}/account-server/${node_number}.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100310 cp ${SWIFT_DIR}/etc/account-server.conf-sample ${swift_node_config}
311 generate_swift_config ${swift_node_config} ${node_number} $[ACCOUNT_PORT_BASE + 10 * (node_number - 1)]
Chmouel Boudjnah8e5d2f02012-12-20 13:11:43 +0000312 sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config}
Attila Fazekasece6a332012-11-29 14:19:41 +0100313 done
314
315 swift_log_dir=${SWIFT_DATA_DIR}/logs
316 rm -rf ${swift_log_dir}
317 mkdir -p ${swift_log_dir}/hourly
318 sudo chown -R $USER:adm ${swift_log_dir}
319 sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \
320 tee /etc/rsyslog.d/10-swift.conf
Attila Fazekasece6a332012-11-29 14:19:41 +0100321}
322
323# configure_swiftclient() - Set config files, create data dirs, etc
324function configure_swiftclient() {
325 setup_develop $SWIFTCLIENT_DIR
326}
327
328# init_swift() - Initialize rings
329function init_swift() {
330 local node_number
331 # Make sure to kill all swift processes first
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100332 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
Attila Fazekasece6a332012-11-29 14:19:41 +0100333
334 # This is where we create three different rings for swift with
335 # different object servers binding on different ports.
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500336 pushd ${SWIFT_CONF_DIR} >/dev/null && {
Attila Fazekasece6a332012-11-29 14:19:41 +0100337
338 rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
339
340 swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
341 swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
342 swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
343
344 for node_number in ${SWIFT_REPLICAS_SEQ}; do
345 swift-ring-builder object.builder add z${node_number}-127.0.0.1:$[OBJECT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
346 swift-ring-builder container.builder add z${node_number}-127.0.0.1:$[CONTAINER_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
347 swift-ring-builder account.builder add z${node_number}-127.0.0.1:$[ACCOUNT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
348 done
349 swift-ring-builder object.builder rebalance
350 swift-ring-builder container.builder rebalance
351 swift-ring-builder account.builder rebalance
352 } && popd >/dev/null
353
Dean Troyer64ab7742012-12-28 15:38:28 -0600354 # Create cache dir
355 sudo mkdir -p $SWIFT_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100356 sudo chown $STACK_USER $SWIFT_AUTH_CACHE_DIR
Dean Troyer64ab7742012-12-28 15:38:28 -0600357 rm -f $SWIFT_AUTH_CACHE_DIR/*
Attila Fazekasece6a332012-11-29 14:19:41 +0100358}
359
360function install_swift() {
361 git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH
362}
363
364function install_swiftclient() {
365 git_clone $SWIFTCLIENT_REPO $SWIFTCLIENT_DIR $SWIFTCLIENT_BRANCH
366}
367
368
369# start_swift() - Start running processes, including screen
370function start_swift() {
371 # (re)start rsyslog
372 restart_service rsyslog
Chmouel Boudjnah8ecbb382013-03-12 12:15:17 +0100373 # (re)start memcached to make sure we have a clean memcache.
374 restart_service memcached
375
Attila Fazekasece6a332012-11-29 14:19:41 +0100376 # Start rsync
Vincent Untzc18b9652012-12-04 12:36:34 +0100377 if is_ubuntu; then
Attila Fazekasece6a332012-11-29 14:19:41 +0100378 sudo /etc/init.d/rsync restart || :
379 else
380 sudo systemctl start xinetd.service
381 fi
382
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100383 # By default with only one replica we are launching the proxy,
384 # container, account and object server in screen in foreground and
385 # other services in background. If we have SWIFT_REPLICAS set to something
386 # greater than one we first spawn all the swift services then kill the proxy
387 # service so we can run it in foreground in screen. ``swift-init ...
388 # {stop|restart}`` exits with '1' if no servers are running, ignore it just
389 # in case
Chmouel Boudjnahad8b2762013-01-10 15:40:01 +0100390 swift-init --run-dir=${SWIFT_DATA_DIR}/run all restart || true
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500391 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100392 todo="object container account"
393 fi
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500394 for type in proxy ${todo}; do
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100395 swift-init --run-dir=${SWIFT_DATA_DIR}/run ${type} stop || true
396 done
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500397 screen_it s-proxy "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONF_DIR}/proxy-server.conf -v"
398 if [[ ${SWIFT_REPLICAS} == 1 ]]; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100399 for type in object container account;do
Dean Troyer6ec72fa2013-03-13 11:44:53 -0500400 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 +0100401 done
402 fi
Attila Fazekasece6a332012-11-29 14:19:41 +0100403}
404
405# stop_swift() - Stop running processes (non-screen)
406function stop_swift() {
407 # screen normally killed by unstack.sh
Dean Troyer995eb922013-03-07 16:11:40 -0600408 if type -p swift-init >/dev/null; then
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100409 swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
410 fi
Dean Troyer995eb922013-03-07 16:11:40 -0600411 # Dump the proxy server
412 sudo pkill -f swift-proxy-server
Attila Fazekasece6a332012-11-29 14:19:41 +0100413}
414
415# Restore xtrace
416$XTRACE