Browse code

Merge "Refactor swift installation"

Jenkins authored on 2012/12/01 07:04:46
Showing 3 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,364 @@
0
+# lib/swift
1
+# Functions to control the configuration and operation of the swift service
2
+
3
+# Dependencies:
4
+# ``functions`` file
5
+# ``DEST``, ``SCREEN_NAME``, `SWIFT_HASH` must be defined
6
+# ``SWIFT_DATA_DIR`` or ``DATA_DIR`` must be defined
7
+# ``lib/keystone`` file
8
+# ``stack.sh`` calls the entry points in this order:
9
+#
10
+# install_swift
11
+# configure_swift
12
+# init_swift
13
+# start_swift
14
+# stop_swift
15
+# cleanup_swift
16
+
17
+# Save trace setting
18
+XTRACE=$(set +o | grep xtrace)
19
+set +o xtrace
20
+
21
+
22
+# Defaults
23
+# --------
24
+
25
+# <define global variables here that belong to this project>
26
+
27
+# Set up default directories
28
+
29
+SWIFT_DIR=$DEST/swift
30
+SWIFTCLIENT_DIR=$DEST/python-swiftclient
31
+
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.
36
+SWIFT_DATA_DIR=${SWIFT_DATA_DIR:-${DATA_DIR}/swift}
37
+
38
+# Set ``SWIFT_CONFIG_DIR`` to the location of the configuration files.
39
+# Default is ``/etc/swift``.
40
+SWIFT_CONFIG_DIR=${SWIFT_CONFIG_DIR:-/etc/swift}
41
+
42
+# DevStack will create a loop-back disk formatted as XFS to store the
43
+# swift data. Set ``SWIFT_LOOPBACK_DISK_SIZE`` to the disk size in bytes.
44
+# Default is 1 gigabyte.
45
+SWIFT_LOOPBACK_DISK_SIZE=${SWIFT_LOOPBACK_DISK_SIZE:-1000000}
46
+
47
+# The ring uses a configurable number of bits from a path’s MD5 hash as
48
+# a partition index that designates a device. The number of bits kept
49
+# from the hash is known as the partition power, and 2 to the partition
50
+# power indicates the partition count. Partitioning the full MD5 hash
51
+# ring allows other parts of the cluster to work in batches of items at
52
+# once which ends up either more efficient or at least less complex than
53
+# working with each item separately or the entire cluster all at once.
54
+# By default we define 9 for the partition count (which mean 512).
55
+SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9}
56
+
57
+# Set ``SWIFT_REPLICAS`` to configure how many replicas are to be
58
+# configured for your Swift cluster.  By default the three replicas would need a
59
+# bit of IO and Memory on a VM you may want to lower that to 1 if you want to do
60
+# only some quick testing.
61
+SWIFT_REPLICAS=${SWIFT_REPLICAS:-3}
62
+SWIFT_REPLICAS_SEQ=$(seq ${SWIFT_REPLICAS})
63
+
64
+# Set ``OBJECT_PORT_BASE``, ``CONTAINER_PORT_BASE``, ``ACCOUNT_PORT_BASE``
65
+# Port bases used in port number calclution for the service "nodes"
66
+# The specified port number will be used, the additinal ports calculated by
67
+# base_port + node_num * 10
68
+OBJECT_PORT_BASE=6010
69
+CONTAINER_PORT_BASE=6011
70
+ACCOUNT_PORT_BASE=6012
71
+
72
+# Entry Points
73
+# ------------
74
+
75
+# cleanup_swift() - Remove residual data files
76
+function cleanup_swift() {
77
+   rm -f ${SWIFT_CONFIG_DIR}{*.builder,*.ring.gz,backups/*.builder,backups/*.ring.gz}
78
+   if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
79
+      sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
80
+   fi
81
+   if [[ -e ${SWIFT_DATA_DIR}/drives/images/swift.img ]]; then
82
+      rm ${SWIFT_DATA_DIR}/drives/images/swift.img
83
+   fi
84
+}
85
+
86
+# configure_swift() - Set config files, create data dirs and loop image
87
+function configure_swift() {
88
+    local swift_auth_server
89
+    local node_number
90
+    local swift_node_config
91
+    local swift_log_dir
92
+
93
+    setup_develop $SWIFT_DIR
94
+
95
+    # Make sure to kill all swift processes first
96
+    swift-init all stop || true
97
+
98
+    # First do a bit of setup by creating the directories and
99
+    # changing the permissions so we can run it as our user.
100
+
101
+    USER_GROUP=$(id -g)
102
+    sudo mkdir -p ${SWIFT_DATA_DIR}/drives
103
+    sudo chown -R $USER:${USER_GROUP} ${SWIFT_DATA_DIR}
104
+
105
+    # Create a loopback disk and format it to XFS.
106
+    if [[ -e ${SWIFT_DATA_DIR}/drives/images/swift.img ]]; then
107
+        if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
108
+            sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
109
+        fi
110
+    else
111
+        mkdir -p  ${SWIFT_DATA_DIR}/drives/images
112
+        sudo touch  ${SWIFT_DATA_DIR}/drives/images/swift.img
113
+        sudo chown $USER: ${SWIFT_DATA_DIR}/drives/images/swift.img
114
+
115
+        dd if=/dev/zero of=${SWIFT_DATA_DIR}/drives/images/swift.img \
116
+            bs=1024 count=0 seek=${SWIFT_LOOPBACK_DISK_SIZE}
117
+    fi
118
+
119
+    # Make a fresh XFS filesystem
120
+    mkfs.xfs -f -i size=1024  ${SWIFT_DATA_DIR}/drives/images/swift.img
121
+
122
+    # Mount the disk with mount options to make it as efficient as possible
123
+    mkdir -p ${SWIFT_DATA_DIR}/drives/sdb1
124
+    if ! egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
125
+        sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8  \
126
+            ${SWIFT_DATA_DIR}/drives/images/swift.img ${SWIFT_DATA_DIR}/drives/sdb1
127
+    fi
128
+
129
+    # Create a link to the above mount and
130
+    # create all of the directories needed to emulate a few different servers
131
+    for node_number in ${SWIFT_REPLICAS_SEQ}; do
132
+        sudo ln -sf ${SWIFT_DATA_DIR}/drives/sdb1/$node_number ${SWIFT_DATA_DIR}/$node_number;
133
+        drive=${SWIFT_DATA_DIR}/drives/sdb1/${node_number}
134
+        node=${SWIFT_DATA_DIR}/${node_number}/node
135
+        node_device=${node}/sdb1
136
+        [[ -d $node ]] && continue
137
+        [[ -d $drive ]] && continue
138
+        sudo install -o ${USER} -g $USER_GROUP -d $drive
139
+        sudo install -o ${USER} -g $USER_GROUP -d $node_device
140
+        sudo chown -R $USER: ${node}
141
+    done
142
+
143
+   sudo mkdir -p ${SWIFT_CONFIG_DIR}/{object,container,account}-server /var/run/swift
144
+   sudo chown -R $USER: ${SWIFT_CONFIG_DIR} /var/run/swift
145
+
146
+    if [[ "$SWIFT_CONFIG_DIR" != "/etc/swift" ]]; then
147
+        # Some swift tools are hard-coded to use ``/etc/swift`` and are apparently not going to be fixed.
148
+        # Create a symlink if the config dir is moved
149
+        sudo ln -sf ${SWIFT_CONFIG_DIR} /etc/swift
150
+    fi
151
+
152
+    # Swift use rsync to synchronize between all the different
153
+    # partitions (which make more sense when you have a multi-node
154
+    # setup) we configure it with our version of rsync.
155
+    sed -e "
156
+        s/%GROUP%/${USER_GROUP}/;
157
+        s/%USER%/$USER/;
158
+        s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,;
159
+    " $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf
160
+    # rsyncd.conf just prepared for 4 nodes
161
+    if [[ "$os_PACKAGE" = "deb" ]]; then
162
+        sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync
163
+    else
164
+        sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync
165
+    fi
166
+
167
+    if is_service_enabled swift3;then
168
+        swift_auth_server="s3token "
169
+    fi
170
+
171
+    # By default Swift will be installed with the tempauth middleware
172
+    # which has some default username and password if you have
173
+    # configured keystone it will checkout the directory.
174
+    if is_service_enabled key; then
175
+        swift_auth_server+="authtoken keystoneauth"
176
+    else
177
+        swift_auth_server=tempauth
178
+    fi
179
+
180
+    SWIFT_CONFIG_PROXY_SERVER=${SWIFT_CONFIG_DIR}/proxy-server.conf
181
+    cp ${SWIFT_DIR}/etc/proxy-server.conf-sample ${SWIFT_CONFIG_PROXY_SERVER}
182
+
183
+    iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user
184
+    iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user ${USER}
185
+
186
+    iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir
187
+    iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir ${SWIFT_CONFIG_DIR}
188
+
189
+    iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers
190
+    iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1
191
+
192
+    iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level
193
+    iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level DEBUG
194
+
195
+    iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port
196
+    iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT:-8080}
197
+
198
+    # Only enable Swift3 if we have it enabled in ENABLED_SERVICES
199
+    is_service_enabled swift3 && swift3=swift3 || swift3=""
200
+
201
+    iniset ${SWIFT_CONFIG_PROXY_SERVER} pipeline:main pipeline "catch_errors healthcheck cache ratelimit ${swift3} ${swift_auth_server} proxy-logging proxy-server"
202
+
203
+    iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server account_autocreate true
204
+
205
+    # Configure Keystone
206
+    sed -i '/^# \[filter:authtoken\]/,/^# \[filter:keystoneauth\]$/ s/^#[ \t]*//' ${SWIFT_CONFIG_PROXY_SERVER}
207
+    iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_host $KEYSTONE_AUTH_HOST
208
+    iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_port $KEYSTONE_AUTH_PORT
209
+    iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
210
+    iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
211
+    iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
212
+    iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_user swift
213
+    iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_password $SERVICE_PASSWORD
214
+
215
+    iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use
216
+    iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles
217
+    iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin"
218
+
219
+    if is_service_enabled swift3; then
220
+        cat <<EOF >>${SWIFT_CONFIG_PROXY_SERVER}
221
+# NOTE(chmou): s3token middleware is not updated yet to use only
222
+# username and password.
223
+[filter:s3token]
224
+paste.filter_factory = keystone.middleware.s3_token:filter_factory
225
+auth_port = ${KEYSTONE_AUTH_PORT}
226
+auth_host = ${KEYSTONE_AUTH_HOST}
227
+auth_protocol = ${KEYSTONE_AUTH_PROTOCOL}
228
+auth_token = ${SERVICE_TOKEN}
229
+admin_token = ${SERVICE_TOKEN}
230
+
231
+[filter:swift3]
232
+use = egg:swift3#swift3
233
+EOF
234
+    fi
235
+
236
+    cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONFIG_DIR}/swift.conf
237
+    iniset ${SWIFT_CONFIG_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH}
238
+
239
+    # This function generates an object/account/proxy configuration
240
+    # emulating 4 nodes on different ports
241
+    function generate_swift_config() {
242
+        local swift_node_config=$1
243
+        local node_id=$2
244
+        local bind_port=$3
245
+
246
+        log_facility=$[ node_id - 1 ]
247
+        node_path=${SWIFT_DATA_DIR}/${node_number}
248
+
249
+        iniuncomment ${swift_node_config} DEFAULT user
250
+        iniset ${swift_node_config} DEFAULT user ${USER}
251
+
252
+        iniuncomment ${swift_node_config} DEFAULT bind_port
253
+        iniset ${swift_node_config} DEFAULT bind_port ${bind_port}
254
+
255
+        iniuncomment ${swift_node_config} DEFAULT swift_dir
256
+        iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONFIG_DIR}
257
+
258
+        iniuncomment ${swift_node_config} DEFAULT devices
259
+        iniset ${swift_node_config} DEFAULT devices ${node_path}
260
+
261
+        iniuncomment ${swift_node_config} DEFAULT log_facility
262
+        iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility}
263
+
264
+        iniuncomment ${swift_node_config} DEFAULT mount_check
265
+        iniset ${swift_node_config} DEFAULT mount_check false
266
+
267
+        iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode
268
+        iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes
269
+    }
270
+
271
+    for node_number in ${SWIFT_REPLICAS_SEQ}; do
272
+        swift_node_config=${SWIFT_CONFIG_DIR}/object-server/${node_number}.conf
273
+        cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config}
274
+        generate_swift_config ${swift_node_config} ${node_number} $[OBJECT_PORT_BASE + 10 * (node_number - 1)]
275
+
276
+        swift_node_config=${SWIFT_CONFIG_DIR}/container-server/${node_number}.conf
277
+        cp ${SWIFT_DIR}/etc/container-server.conf-sample ${swift_node_config}
278
+        generate_swift_config ${swift_node_config} ${node_number} $[CONTAINER_PORT_BASE + 10 * (node_number - 1)]
279
+
280
+        swift_node_config=${SWIFT_CONFIG_DIR}/account-server/${node_number}.conf
281
+        cp ${SWIFT_DIR}/etc/account-server.conf-sample ${swift_node_config}
282
+        generate_swift_config ${swift_node_config} ${node_number} $[ACCOUNT_PORT_BASE + 10 * (node_number - 1)]
283
+    done
284
+
285
+    swift_log_dir=${SWIFT_DATA_DIR}/logs
286
+    rm -rf ${swift_log_dir}
287
+    mkdir -p ${swift_log_dir}/hourly
288
+    sudo chown -R $USER:adm ${swift_log_dir}
289
+    sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \
290
+        tee /etc/rsyslog.d/10-swift.conf
291
+
292
+}
293
+
294
+# configure_swiftclient() - Set config files, create data dirs, etc
295
+function configure_swiftclient() {
296
+    setup_develop $SWIFTCLIENT_DIR
297
+}
298
+
299
+# init_swift() - Initialize rings
300
+function init_swift() {
301
+    local node_number
302
+    # Make sure to kill all swift processes first
303
+    swift-init all stop || true
304
+
305
+    # This is where we create three different rings for swift with
306
+    # different object servers binding on different ports.
307
+    pushd ${SWIFT_CONFIG_DIR} >/dev/null && {
308
+
309
+        rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
310
+
311
+        swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
312
+        swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
313
+        swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
314
+
315
+        for node_number in ${SWIFT_REPLICAS_SEQ}; do
316
+            swift-ring-builder object.builder add z${node_number}-127.0.0.1:$[OBJECT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
317
+            swift-ring-builder container.builder add z${node_number}-127.0.0.1:$[CONTAINER_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
318
+            swift-ring-builder account.builder add z${node_number}-127.0.0.1:$[ACCOUNT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1
319
+        done
320
+        swift-ring-builder object.builder rebalance
321
+        swift-ring-builder container.builder rebalance
322
+        swift-ring-builder account.builder rebalance
323
+    } && popd >/dev/null
324
+
325
+}
326
+
327
+function install_swift() {
328
+    git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH
329
+}
330
+
331
+function install_swiftclient() {
332
+    git_clone $SWIFTCLIENT_REPO $SWIFTCLIENT_DIR $SWIFTCLIENT_BRANCH
333
+}
334
+
335
+
336
+# start_swift() - Start running processes, including screen
337
+function start_swift() {
338
+    # (re)start rsyslog
339
+    restart_service rsyslog
340
+    # Start rsync
341
+    if [[ "$os_PACKAGE" = "deb" ]]; then
342
+        sudo /etc/init.d/rsync restart || :
343
+    else
344
+        sudo systemctl start xinetd.service
345
+    fi
346
+
347
+   # First spawn all the swift services then kill the
348
+   # proxy service so we can run it in foreground in screen.
349
+   # ``swift-init ... {stop|restart}`` exits with '1' if no servers are running,
350
+   # ignore it just in case
351
+   swift-init all restart || true
352
+   swift-init proxy stop || true
353
+   screen_it swift "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONFIG_DIR}/proxy-server.conf -v"
354
+}
355
+
356
+# stop_swift() - Stop running processes (non-screen)
357
+function stop_swift() {
358
+    # screen normally killed by unstack.sh
359
+    swift-init all stop || true
360
+}
361
+
362
+# Restore xtrace
363
+$XTRACE
... ...
@@ -105,7 +105,7 @@ disable_negated_services
105 105
 
106 106
 # Warn users who aren't on an explicitly supported distro, but allow them to
107 107
 # override check and attempt installation with ``FORCE=yes ./stack``
108
-if [[ ! ${DISTRO} =~ (oneiric|precise|quantal|raring|f16|f17) ]]; then
108
+if [[ ! ${DISTRO} =~ (oneiric|precise|quantal|raring|f16|f17|f18) ]]; then
109 109
     echo "WARNING: this script has not been tested on $DISTRO"
110 110
     if [[ "$FORCE" != "yes" ]]; then
111 111
         echo "If you wish to run this script anyway run with FORCE=yes"
... ...
@@ -310,6 +310,7 @@ source $TOP_DIR/lib/keystone
310 310
 source $TOP_DIR/lib/glance
311 311
 source $TOP_DIR/lib/nova
312 312
 source $TOP_DIR/lib/cinder
313
+source $TOP_DIR/lib/swift
313 314
 source $TOP_DIR/lib/ceilometer
314 315
 source $TOP_DIR/lib/heat
315 316
 source $TOP_DIR/lib/quantum
... ...
@@ -319,9 +320,7 @@ source $TOP_DIR/lib/tempest
319 319
 HORIZON_DIR=$DEST/horizon
320 320
 OPENSTACKCLIENT_DIR=$DEST/python-openstackclient
321 321
 NOVNC_DIR=$DEST/noVNC
322
-SWIFT_DIR=$DEST/swift
323 322
 SWIFT3_DIR=$DEST/swift3
324
-SWIFTCLIENT_DIR=$DEST/python-swiftclient
325 323
 QUANTUM_DIR=$DEST/quantum
326 324
 QUANTUM_CLIENT_DIR=$DEST/python-quantumclient
327 325
 
... ...
@@ -503,41 +502,6 @@ if is_service_enabled rabbit; then
503 503
     read_password RABBIT_PASSWORD "ENTER A PASSWORD TO USE FOR RABBIT."
504 504
 fi
505 505
 
506
-
507
-# Swift
508
-# -----
509
-
510
-# TODO: add logging to different location.
511
-
512
-# Set ``SWIFT_DATA_DIR`` to the location of swift drives and objects.
513
-# Default is the common DevStack data directory.
514
-SWIFT_DATA_DIR=${SWIFT_DATA_DIR:-${DATA_DIR}/swift}
515
-
516
-# Set ``SWIFT_CONFIG_DIR`` to the location of the configuration files.
517
-# Default is ``/etc/swift``.
518
-SWIFT_CONFIG_DIR=${SWIFT_CONFIG_DIR:-/etc/swift}
519
-
520
-# DevStack will create a loop-back disk formatted as XFS to store the
521
-# swift data. Set ``SWIFT_LOOPBACK_DISK_SIZE`` to the disk size in bytes.
522
-# Default is 1 gigabyte.
523
-SWIFT_LOOPBACK_DISK_SIZE=${SWIFT_LOOPBACK_DISK_SIZE:-1000000}
524
-
525
-# The ring uses a configurable number of bits from a path’s MD5 hash as
526
-# a partition index that designates a device. The number of bits kept
527
-# from the hash is known as the partition power, and 2 to the partition
528
-# power indicates the partition count. Partitioning the full MD5 hash
529
-# ring allows other parts of the cluster to work in batches of items at
530
-# once which ends up either more efficient or at least less complex than
531
-# working with each item separately or the entire cluster all at once.
532
-# By default we define 9 for the partition count (which mean 512).
533
-SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9}
534
-
535
-# Set ``SWIFT_REPLICAS`` to configure how many replicas are to be
536
-# configured for your Swift cluster.  By default the three replicas would need a
537
-# bit of IO and Memory on a VM you may want to lower that to 1 if you want to do
538
-# only some quick testing.
539
-SWIFT_REPLICAS=${SWIFT_REPLICAS:-3}
540
-
541 506
 if is_service_enabled swift; then
542 507
     # If we are using swift3, we can default the s3 port to swift instead
543 508
     # of nova-objectstore
... ...
@@ -793,7 +757,6 @@ echo_summary "Installing OpenStack project source"
793 793
 install_keystoneclient
794 794
 install_glanceclient
795 795
 install_novaclient
796
-
797 796
 # Check out the client libs that are used most
798 797
 git_clone $OPENSTACKCLIENT_REPO $OPENSTACKCLIENT_DIR $OPENSTACKCLIENT_BRANCH
799 798
 
... ...
@@ -802,16 +765,16 @@ if is_service_enabled key g-api n-api swift; then
802 802
     # unified auth system (manages accounts/tokens)
803 803
     install_keystone
804 804
 fi
805
+
805 806
 if is_service_enabled swift; then
806
-    # storage service
807
-    git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH
808
-    # storage service client and and Library
809
-    git_clone $SWIFTCLIENT_REPO $SWIFTCLIENT_DIR $SWIFTCLIENT_BRANCH
807
+    install_swiftclient
808
+    install_swift
810 809
     if is_service_enabled swift3; then
811 810
         # swift3 middleware to provide S3 emulation to Swift
812 811
         git_clone $SWIFT3_REPO $SWIFT3_DIR $SWIFT3_BRANCH
813 812
     fi
814 813
 fi
814
+
815 815
 if is_service_enabled g-api n-api; then
816 816
     # image catalog service
817 817
     install_glance
... ...
@@ -867,11 +830,11 @@ if is_service_enabled key g-api n-api swift; then
867 867
     configure_keystone
868 868
 fi
869 869
 if is_service_enabled swift; then
870
-    setup_develop $SWIFT_DIR
871
-    setup_develop $SWIFTCLIENT_DIR
872
-fi
873
-if is_service_enabled swift3; then
874
-    setup_develop $SWIFT3_DIR
870
+    configure_swift
871
+    configure_swiftclient
872
+    if is_service_enabled swift3; then
873
+        setup_develop $SWIFT3_DIR
874
+    fi
875 875
 fi
876 876
 if is_service_enabled g-api n-api; then
877 877
     configure_glance
... ...
@@ -1439,253 +1402,7 @@ fi
1439 1439
 
1440 1440
 if is_service_enabled swift; then
1441 1441
     echo_summary "Configuring Swift"
1442
-
1443
-    # Make sure to kill all swift processes first
1444
-    swift-init all stop || true
1445
-
1446
-    # First do a bit of setup by creating the directories and
1447
-    # changing the permissions so we can run it as our user.
1448
-
1449
-    USER_GROUP=$(id -g)
1450
-    sudo mkdir -p ${SWIFT_DATA_DIR}/drives
1451
-    sudo chown -R $USER:${USER_GROUP} ${SWIFT_DATA_DIR}
1452
-
1453
-    # Create a loopback disk and format it to XFS.
1454
-    if [[ -e ${SWIFT_DATA_DIR}/drives/images/swift.img ]]; then
1455
-        if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
1456
-            sudo umount ${SWIFT_DATA_DIR}/drives/sdb1
1457
-        fi
1458
-    else
1459
-        mkdir -p  ${SWIFT_DATA_DIR}/drives/images
1460
-        sudo touch  ${SWIFT_DATA_DIR}/drives/images/swift.img
1461
-        sudo chown $USER: ${SWIFT_DATA_DIR}/drives/images/swift.img
1462
-
1463
-        dd if=/dev/zero of=${SWIFT_DATA_DIR}/drives/images/swift.img \
1464
-            bs=1024 count=0 seek=${SWIFT_LOOPBACK_DISK_SIZE}
1465
-    fi
1466
-
1467
-    # Make a fresh XFS filesystem
1468
-    mkfs.xfs -f -i size=1024  ${SWIFT_DATA_DIR}/drives/images/swift.img
1469
-
1470
-    # Mount the disk with mount options to make it as efficient as possible
1471
-    mkdir -p ${SWIFT_DATA_DIR}/drives/sdb1
1472
-    if ! egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then
1473
-        sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8  \
1474
-            ${SWIFT_DATA_DIR}/drives/images/swift.img ${SWIFT_DATA_DIR}/drives/sdb1
1475
-    fi
1476
-
1477
-    # Create a link to the above mount
1478
-    for x in $(seq ${SWIFT_REPLICAS}); do
1479
-        sudo ln -sf ${SWIFT_DATA_DIR}/drives/sdb1/$x ${SWIFT_DATA_DIR}/$x; done
1480
-
1481
-    # Create all of the directories needed to emulate a few different servers
1482
-    for x in $(seq ${SWIFT_REPLICAS}); do
1483
-            drive=${SWIFT_DATA_DIR}/drives/sdb1/${x}
1484
-            node=${SWIFT_DATA_DIR}/${x}/node
1485
-            node_device=${node}/sdb1
1486
-            [[ -d $node ]] && continue
1487
-            [[ -d $drive ]] && continue
1488
-            sudo install -o ${USER} -g $USER_GROUP -d $drive
1489
-            sudo install -o ${USER} -g $USER_GROUP -d $node_device
1490
-            sudo chown -R $USER: ${node}
1491
-    done
1492
-
1493
-   sudo mkdir -p ${SWIFT_CONFIG_DIR}/{object,container,account}-server /var/run/swift
1494
-   sudo chown -R $USER: ${SWIFT_CONFIG_DIR} /var/run/swift
1495
-
1496
-    if [[ "$SWIFT_CONFIG_DIR" != "/etc/swift" ]]; then
1497
-        # Some swift tools are hard-coded to use ``/etc/swift`` and are apparently not going to be fixed.
1498
-        # Create a symlink if the config dir is moved
1499
-        sudo ln -sf ${SWIFT_CONFIG_DIR} /etc/swift
1500
-    fi
1501
-
1502
-    # Swift use rsync to synchronize between all the different
1503
-    # partitions (which make more sense when you have a multi-node
1504
-    # setup) we configure it with our version of rsync.
1505
-    sed -e "
1506
-        s/%GROUP%/${USER_GROUP}/;
1507
-        s/%USER%/$USER/;
1508
-        s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,;
1509
-    " $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf
1510
-    if [[ "$os_PACKAGE" = "deb" ]]; then
1511
-        sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync
1512
-    else
1513
-        sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync
1514
-    fi
1515
-
1516
-    if is_service_enabled swift3;then
1517
-        swift_auth_server="s3token "
1518
-    fi
1519
-
1520
-    # By default Swift will be installed with the tempauth middleware
1521
-    # which has some default username and password if you have
1522
-    # configured keystone it will checkout the directory.
1523
-    if is_service_enabled key; then
1524
-        swift_auth_server+="authtoken keystoneauth"
1525
-    else
1526
-        swift_auth_server=tempauth
1527
-    fi
1528
-
1529
-    SWIFT_CONFIG_PROXY_SERVER=${SWIFT_CONFIG_DIR}/proxy-server.conf
1530
-    cp ${SWIFT_DIR}/etc/proxy-server.conf-sample ${SWIFT_CONFIG_PROXY_SERVER}
1531
-
1532
-    iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user
1533
-    iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user ${USER}
1534
-
1535
-    iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir
1536
-    iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir ${SWIFT_CONFIG_DIR}
1537
-
1538
-    iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers
1539
-    iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1
1540
-
1541
-    iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level
1542
-    iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level DEBUG
1543
-
1544
-    iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port
1545
-    iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT:-8080}
1546
-
1547
-    # Only enable Swift3 if we have it enabled in ENABLED_SERVICES
1548
-    is_service_enabled swift3 && swift3=swift3 || swift3=""
1549
-
1550
-    iniset ${SWIFT_CONFIG_PROXY_SERVER} pipeline:main pipeline "catch_errors healthcheck cache ratelimit ${swift3} ${swift_auth_server} proxy-logging proxy-server"
1551
-
1552
-    iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server account_autocreate true
1553
-
1554
-    # Configure Keystone
1555
-    sed -i '/^# \[filter:authtoken\]/,/^# \[filter:keystoneauth\]$/ s/^#[ \t]*//' ${SWIFT_CONFIG_PROXY_SERVER}
1556
-    iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_host $KEYSTONE_AUTH_HOST
1557
-    iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_port $KEYSTONE_AUTH_PORT
1558
-    iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
1559
-    iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
1560
-    iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME
1561
-    iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_user swift
1562
-    iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_password $SERVICE_PASSWORD
1563
-
1564
-    iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use
1565
-    iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles
1566
-    iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin"
1567
-
1568
-    if is_service_enabled swift3; then
1569
-        cat <<EOF >>${SWIFT_CONFIG_PROXY_SERVER}
1570
-# NOTE(chmou): s3token middleware is not updated yet to use only
1571
-# username and password.
1572
-[filter:s3token]
1573
-paste.filter_factory = keystone.middleware.s3_token:filter_factory
1574
-auth_port = ${KEYSTONE_AUTH_PORT}
1575
-auth_host = ${KEYSTONE_AUTH_HOST}
1576
-auth_protocol = ${KEYSTONE_AUTH_PROTOCOL}
1577
-auth_token = ${SERVICE_TOKEN}
1578
-admin_token = ${SERVICE_TOKEN}
1579
-
1580
-[filter:swift3]
1581
-use = egg:swift3#swift3
1582
-EOF
1583
-    fi
1584
-
1585
-    cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONFIG_DIR}/swift.conf
1586
-    iniset ${SWIFT_CONFIG_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH}
1587
-
1588
-    # This function generates an object/account/proxy configuration
1589
-    # emulating 4 nodes on different ports
1590
-    function generate_swift_configuration() {
1591
-        local server_type=$1
1592
-        local bind_port=$2
1593
-        local log_facility=$3
1594
-        local node_number
1595
-        local swift_node_config
1596
-
1597
-        for node_number in $(seq ${SWIFT_REPLICAS}); do
1598
-            node_path=${SWIFT_DATA_DIR}/${node_number}
1599
-            swift_node_config=${SWIFT_CONFIG_DIR}/${server_type}-server/${node_number}.conf
1600
-
1601
-            cp ${SWIFT_DIR}/etc/${server_type}-server.conf-sample ${swift_node_config}
1602
-
1603
-            iniuncomment ${swift_node_config} DEFAULT user
1604
-            iniset ${swift_node_config} DEFAULT user ${USER}
1605
-
1606
-            iniuncomment ${swift_node_config} DEFAULT bind_port
1607
-            iniset ${swift_node_config} DEFAULT bind_port ${bind_port}
1608
-
1609
-            iniuncomment ${swift_node_config} DEFAULT swift_dir
1610
-            iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONFIG_DIR}
1611
-
1612
-            iniuncomment ${swift_node_config} DEFAULT devices
1613
-            iniset ${swift_node_config} DEFAULT devices ${node_path}
1614
-
1615
-            iniuncomment ${swift_node_config} DEFAULT log_facility
1616
-            iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility}
1617
-
1618
-            iniuncomment ${swift_node_config} DEFAULT mount_check
1619
-            iniset ${swift_node_config} DEFAULT mount_check false
1620
-
1621
-            iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode
1622
-            iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes
1623
-
1624
-            bind_port=$(( ${bind_port} + 10 ))
1625
-            log_facility=$(( ${log_facility} + 1 ))
1626
-        done
1627
-    }
1628
-    generate_swift_configuration object 6010 2
1629
-    generate_swift_configuration container 6011 2
1630
-    generate_swift_configuration account 6012 2
1631
-
1632
-    # Specific configuration for swift for rsyslog. See
1633
-    # ``/etc/rsyslog.d/10-swift.conf`` for more info.
1634
-    swift_log_dir=${SWIFT_DATA_DIR}/logs
1635
-    rm -rf ${swift_log_dir}
1636
-    mkdir -p ${swift_log_dir}/hourly
1637
-    sudo chown -R $USER:adm ${swift_log_dir}
1638
-    sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \
1639
-        tee /etc/rsyslog.d/10-swift.conf
1640
-    restart_service rsyslog
1641
-
1642
-    # This is where we create three different rings for swift with
1643
-    # different object servers binding on different ports.
1644
-    pushd ${SWIFT_CONFIG_DIR} >/dev/null && {
1645
-
1646
-        rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz
1647
-
1648
-        port_number=6010
1649
-        swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
1650
-        for x in $(seq ${SWIFT_REPLICAS}); do
1651
-            swift-ring-builder object.builder add z${x}-127.0.0.1:${port_number}/sdb1 1
1652
-            port_number=$[port_number + 10]
1653
-        done
1654
-        swift-ring-builder object.builder rebalance
1655
-
1656
-        port_number=6011
1657
-        swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
1658
-        for x in $(seq ${SWIFT_REPLICAS}); do
1659
-            swift-ring-builder container.builder add z${x}-127.0.0.1:${port_number}/sdb1 1
1660
-            port_number=$[port_number + 10]
1661
-        done
1662
-        swift-ring-builder container.builder rebalance
1663
-
1664
-        port_number=6012
1665
-        swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1
1666
-        for x in $(seq ${SWIFT_REPLICAS}); do
1667
-            swift-ring-builder account.builder add z${x}-127.0.0.1:${port_number}/sdb1 1
1668
-            port_number=$[port_number + 10]
1669
-        done
1670
-        swift-ring-builder account.builder rebalance
1671
-
1672
-    } && popd >/dev/null
1673
-
1674
-   # Start rsync
1675
-    if [[ "$os_PACKAGE" = "deb" ]]; then
1676
-        sudo /etc/init.d/rsync restart || :
1677
-    else
1678
-        sudo systemctl start xinetd.service
1679
-    fi
1680
-
1681
-   # First spawn all the swift services then kill the
1682
-   # proxy service so we can run it in foreground in screen.
1683
-   # ``swift-init ... {stop|restart}`` exits with '1' if no servers are running,
1684
-   # ignore it just in case
1685
-   swift-init all restart || true
1686
-   swift-init proxy stop || true
1687
-
1688
-   unset s swift_hash swift_auth_server
1442
+    init_swift
1689 1443
 fi
1690 1444
 
1691 1445
 
... ...
@@ -1802,6 +1519,12 @@ fi
1802 1802
 
1803 1803
 # Only run the services specified in ``ENABLED_SERVICES``
1804 1804
 
1805
+# Launch Swift Services
1806
+if is_service_enabled swift; then
1807
+    echo_summary "Starting Swift"
1808
+    start_swift
1809
+fi
1810
+
1805 1811
 # Launch the Glance services
1806 1812
 if is_service_enabled g-api g-reg; then
1807 1813
     echo_summary "Starting Glance"
... ...
@@ -1905,8 +1628,6 @@ if is_service_enabled ceilometer; then
1905 1905
     start_ceilometer
1906 1906
 fi
1907 1907
 
1908
-screen_it swift "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONFIG_DIR}/proxy-server.conf -v"
1909
-
1910 1908
 # Starting the nova-objectstore only if swift3 service is not enabled.
1911 1909
 # Swift will act as s3 objectstore.
1912 1910
 is_service_enabled swift3 || \
... ...
@@ -27,6 +27,7 @@ DATA_DIR=${DATA_DIR:-${DEST}/data}
27 27
 # Get project function libraries
28 28
 source $TOP_DIR/lib/cinder
29 29
 source $TOP_DIR/lib/horizon
30
+source $TOP_DIR/lib/swift
30 31
 
31 32
 # Determine what system we are running on.  This provides ``os_VENDOR``,
32 33
 # ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME``
... ...
@@ -47,7 +48,7 @@ fi
47 47
 
48 48
 # Swift runs daemons
49 49
 if is_service_enabled swift; then
50
-    swift-init all stop 2>/dev/null || true
50
+    stop_swift
51 51
 fi
52 52
 
53 53
 # Apache has the WSGI processes