Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 1 | # lib/swift |
Dean Troyer | 6d04fd7 | 2012-12-21 11:03:37 -0600 | [diff] [blame] | 2 | # Functions to control the configuration and operation of the **Swift** service |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 3 | |
| 4 | # Dependencies: |
| 5 | # ``functions`` file |
| 6 | # ``DEST``, ``SCREEN_NAME``, `SWIFT_HASH` must be defined |
Attila Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 7 | # ``STACK_USER`` must be defined |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 8 | # ``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 |
| 20 | XTRACE=$(set +o | grep xtrace) |
| 21 | set +o xtrace |
| 22 | |
| 23 | |
| 24 | # Defaults |
| 25 | # -------- |
| 26 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 27 | # Set up default directories |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 28 | SWIFT_DIR=$DEST/swift |
| 29 | SWIFTCLIENT_DIR=$DEST/python-swiftclient |
Dean Troyer | 64ab774 | 2012-12-28 15:38:28 -0600 | [diff] [blame] | 30 | SWIFT_AUTH_CACHE_DIR=${SWIFT_AUTH_CACHE_DIR:-/var/cache/swift} |
Dean Troyer | b7490da | 2013-03-18 16:07:56 -0500 | [diff] [blame] | 31 | SWIFT3_DIR=$DEST/swift3 |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 32 | |
| 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. |
| 37 | SWIFT_DATA_DIR=${SWIFT_DATA_DIR:-${DATA_DIR}/swift} |
| 38 | |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 39 | # Set ``SWIFT_CONF_DIR`` to the location of the configuration files. |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 40 | # Default is ``/etc/swift``. |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 41 | # TODO(dtroyer): remove SWIFT_CONFIG_DIR after cutting stable/grizzly |
| 42 | SWIFT_CONF_DIR=${SWIFT_CONF_DIR:-${SWIFT_CONFIG_DIR:-/etc/swift}} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 43 | |
Dean Troyer | b7490da | 2013-03-18 16:07:56 -0500 | [diff] [blame] | 44 | if 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} |
| 48 | fi |
| 49 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 50 | # DevStack will create a loop-back disk formatted as XFS to store the |
Kevin Lyda | d66c965 | 2013-01-09 13:39:57 +0000 | [diff] [blame] | 51 | # swift data. Set ``SWIFT_LOOPBACK_DISK_SIZE`` to the disk size in |
| 52 | # kilobytes. |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 53 | # Default is 1 gigabyte. |
| 54 | SWIFT_LOOPBACK_DISK_SIZE=${SWIFT_LOOPBACK_DISK_SIZE:-1000000} |
| 55 | |
Chmouel Boudjnah | bc3a339 | 2013-02-23 04:00:51 +0100 | [diff] [blame] | 56 | # Set ``SWIFT_EXTRAS_MIDDLEWARE`` to extras middlewares. |
| 57 | # Default is ``staticweb, tempurl, bulk, formpost`` |
| 58 | SWIFT_EXTRAS_MIDDLEWARE=${SWIFT_EXTRAS_MIDDLEWARE:-tempurl formpost staticweb bulk} |
| 59 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 60 | # 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). |
| 68 | SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9} |
| 69 | |
| 70 | # Set ``SWIFT_REPLICAS`` to configure how many replicas are to be |
Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 71 | # 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. |
| 75 | SWIFT_REPLICAS=${SWIFT_REPLICAS:-1} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 76 | SWIFT_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 |
Dean Troyer | 1151d6f | 2013-03-29 14:06:52 -0500 | [diff] [blame^] | 82 | OBJECT_PORT_BASE=${OBJECT_PORT_BASE:-6013} |
| 83 | CONTAINER_PORT_BASE=${CONTAINER_PORT_BASE:-6011} |
| 84 | ACCOUNT_PORT_BASE=${ACCOUNT_PORT_BASE:-6012} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 85 | |
Dean Troyer | 6d04fd7 | 2012-12-21 11:03:37 -0600 | [diff] [blame] | 86 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 87 | # Entry Points |
| 88 | # ------------ |
| 89 | |
| 90 | # cleanup_swift() - Remove residual data files |
| 91 | function cleanup_swift() { |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 92 | rm -f ${SWIFT_CONF_DIR}{*.builder,*.ring.gz,backups/*.builder,backups/*.ring.gz} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 93 | 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 Boudjnah | bc3a339 | 2013-02-23 04:00:51 +0100 | [diff] [blame] | 99 | rm -rf ${SWIFT_DATA_DIR}/run/ |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | # configure_swift() - Set config files, create data dirs and loop image |
| 103 | function configure_swift() { |
Chmouel Boudjnah | bc3a339 | 2013-02-23 04:00:51 +0100 | [diff] [blame] | 104 | local swift_pipeline=" " |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 105 | 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 Boudjnah | ad8b276 | 2013-01-10 15:40:01 +0100 | [diff] [blame] | 112 | swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 113 | |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 114 | sudo mkdir -p ${SWIFT_CONF_DIR}/{object,container,account}-server |
| 115 | sudo chown -R $USER: ${SWIFT_CONF_DIR} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 116 | |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 117 | if [[ "$SWIFT_CONF_DIR" != "/etc/swift" ]]; then |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 118 | # Some swift tools are hard-coded to use ``/etc/swift`` and are apparently not going to be fixed. |
| 119 | # Create a symlink if the config dir is moved |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 120 | sudo ln -sf ${SWIFT_CONF_DIR} /etc/swift |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 121 | fi |
| 122 | |
| 123 | # Swift use rsync to synchronize between all the different |
| 124 | # partitions (which make more sense when you have a multi-node |
| 125 | # setup) we configure it with our version of rsync. |
| 126 | sed -e " |
| 127 | s/%GROUP%/${USER_GROUP}/; |
| 128 | s/%USER%/$USER/; |
| 129 | s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,; |
| 130 | " $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf |
| 131 | # rsyncd.conf just prepared for 4 nodes |
Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 132 | if is_ubuntu; then |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 133 | sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync |
| 134 | else |
| 135 | sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync |
| 136 | fi |
| 137 | |
| 138 | if is_service_enabled swift3;then |
| 139 | swift_auth_server="s3token " |
| 140 | fi |
| 141 | |
| 142 | # By default Swift will be installed with the tempauth middleware |
| 143 | # which has some default username and password if you have |
| 144 | # configured keystone it will checkout the directory. |
| 145 | if is_service_enabled key; then |
| 146 | swift_auth_server+="authtoken keystoneauth" |
| 147 | else |
| 148 | swift_auth_server=tempauth |
| 149 | fi |
| 150 | |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 151 | SWIFT_CONFIG_PROXY_SERVER=${SWIFT_CONF_DIR}/proxy-server.conf |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 152 | cp ${SWIFT_DIR}/etc/proxy-server.conf-sample ${SWIFT_CONFIG_PROXY_SERVER} |
| 153 | |
| 154 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user |
| 155 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT user ${USER} |
| 156 | |
| 157 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 158 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT swift_dir ${SWIFT_CONF_DIR} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 159 | |
| 160 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers |
| 161 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT workers 1 |
| 162 | |
| 163 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level |
| 164 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT log_level DEBUG |
| 165 | |
| 166 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port |
| 167 | iniset ${SWIFT_CONFIG_PROXY_SERVER} DEFAULT bind_port ${SWIFT_DEFAULT_BIND_PORT:-8080} |
| 168 | |
Chmouel Boudjnah | bc3a339 | 2013-02-23 04:00:51 +0100 | [diff] [blame] | 169 | # By default Swift will be installed with the tempauth middleware |
| 170 | # which has some default username and password if you have |
| 171 | # configured keystone it will configure swift with it. |
| 172 | if is_service_enabled key;then |
| 173 | if is_service_enabled swift3;then |
| 174 | swift_pipeline=" s3token swift3 " |
| 175 | fi |
| 176 | swift_pipeline+=" authtoken keystoneauth " |
| 177 | else |
| 178 | if is_service_enabled swift3;then |
| 179 | swift_pipeline=" swift3 " |
| 180 | fi |
| 181 | swift_pipeline+=" tempauth " |
| 182 | fi |
| 183 | sed -i "/^pipeline/ { s/tempauth/${swift_pipeline} ${SWIFT_EXTRAS_MIDDLEWARE}/ ;}" ${SWIFT_CONFIG_PROXY_SERVER} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 184 | |
| 185 | iniset ${SWIFT_CONFIG_PROXY_SERVER} app:proxy-server account_autocreate true |
| 186 | |
| 187 | # Configure Keystone |
| 188 | sed -i '/^# \[filter:authtoken\]/,/^# \[filter:keystoneauth\]$/ s/^#[ \t]*//' ${SWIFT_CONFIG_PROXY_SERVER} |
| 189 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_host $KEYSTONE_AUTH_HOST |
| 190 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_port $KEYSTONE_AUTH_PORT |
| 191 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL |
| 192 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/ |
| 193 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_tenant_name $SERVICE_TENANT_NAME |
| 194 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_user swift |
| 195 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken admin_password $SERVICE_PASSWORD |
Dean Troyer | 64ab774 | 2012-12-28 15:38:28 -0600 | [diff] [blame] | 196 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:authtoken signing_dir $SWIFT_AUTH_CACHE_DIR |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 197 | |
| 198 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth use |
| 199 | iniuncomment ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles |
| 200 | iniset ${SWIFT_CONFIG_PROXY_SERVER} filter:keystoneauth operator_roles "Member, admin" |
| 201 | |
| 202 | if is_service_enabled swift3; then |
| 203 | cat <<EOF >>${SWIFT_CONFIG_PROXY_SERVER} |
| 204 | # NOTE(chmou): s3token middleware is not updated yet to use only |
| 205 | # username and password. |
| 206 | [filter:s3token] |
| 207 | paste.filter_factory = keystone.middleware.s3_token:filter_factory |
| 208 | auth_port = ${KEYSTONE_AUTH_PORT} |
| 209 | auth_host = ${KEYSTONE_AUTH_HOST} |
| 210 | auth_protocol = ${KEYSTONE_AUTH_PROTOCOL} |
| 211 | auth_token = ${SERVICE_TOKEN} |
| 212 | admin_token = ${SERVICE_TOKEN} |
| 213 | |
| 214 | [filter:swift3] |
| 215 | use = egg:swift3#swift3 |
| 216 | EOF |
| 217 | fi |
| 218 | |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 219 | cp ${SWIFT_DIR}/etc/swift.conf-sample ${SWIFT_CONF_DIR}/swift.conf |
| 220 | iniset ${SWIFT_CONF_DIR}/swift.conf swift-hash swift_hash_path_suffix ${SWIFT_HASH} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 221 | |
| 222 | # This function generates an object/account/proxy configuration |
| 223 | # emulating 4 nodes on different ports |
| 224 | function generate_swift_config() { |
| 225 | local swift_node_config=$1 |
| 226 | local node_id=$2 |
| 227 | local bind_port=$3 |
| 228 | |
| 229 | log_facility=$[ node_id - 1 ] |
| 230 | node_path=${SWIFT_DATA_DIR}/${node_number} |
| 231 | |
| 232 | iniuncomment ${swift_node_config} DEFAULT user |
| 233 | iniset ${swift_node_config} DEFAULT user ${USER} |
| 234 | |
| 235 | iniuncomment ${swift_node_config} DEFAULT bind_port |
| 236 | iniset ${swift_node_config} DEFAULT bind_port ${bind_port} |
| 237 | |
| 238 | iniuncomment ${swift_node_config} DEFAULT swift_dir |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 239 | iniset ${swift_node_config} DEFAULT swift_dir ${SWIFT_CONF_DIR} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 240 | |
| 241 | iniuncomment ${swift_node_config} DEFAULT devices |
| 242 | iniset ${swift_node_config} DEFAULT devices ${node_path} |
| 243 | |
| 244 | iniuncomment ${swift_node_config} DEFAULT log_facility |
| 245 | iniset ${swift_node_config} DEFAULT log_facility LOG_LOCAL${log_facility} |
| 246 | |
| 247 | iniuncomment ${swift_node_config} DEFAULT mount_check |
| 248 | iniset ${swift_node_config} DEFAULT mount_check false |
| 249 | |
| 250 | iniuncomment ${swift_node_config} ${server_type}-replicator vm_test_mode |
| 251 | iniset ${swift_node_config} ${server_type}-replicator vm_test_mode yes |
| 252 | } |
| 253 | |
| 254 | for node_number in ${SWIFT_REPLICAS_SEQ}; do |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 255 | swift_node_config=${SWIFT_CONF_DIR}/object-server/${node_number}.conf |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 256 | cp ${SWIFT_DIR}/etc/object-server.conf-sample ${swift_node_config} |
| 257 | generate_swift_config ${swift_node_config} ${node_number} $[OBJECT_PORT_BASE + 10 * (node_number - 1)] |
Chmouel Boudjnah | 8e5d2f0 | 2012-12-20 13:11:43 +0000 | [diff] [blame] | 258 | iniset ${swift_node_config} filter:recon recon_cache_path ${SWIFT_DATA_DIR}/cache |
| 259 | # Using a sed and not iniset/iniuncomment because we want to a global |
| 260 | # modification and make sure it works for new sections. |
| 261 | sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 262 | |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 263 | swift_node_config=${SWIFT_CONF_DIR}/container-server/${node_number}.conf |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 264 | cp ${SWIFT_DIR}/etc/container-server.conf-sample ${swift_node_config} |
| 265 | generate_swift_config ${swift_node_config} ${node_number} $[CONTAINER_PORT_BASE + 10 * (node_number - 1)] |
Attila Fazekas | 83e1095 | 2012-11-30 23:28:07 +0100 | [diff] [blame] | 266 | iniuncomment ${swift_node_config} app:container-server allow_versions |
| 267 | iniset ${swift_node_config} app:container-server allow_versions "true" |
Chmouel Boudjnah | 8e5d2f0 | 2012-12-20 13:11:43 +0000 | [diff] [blame] | 268 | sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 269 | |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 270 | swift_node_config=${SWIFT_CONF_DIR}/account-server/${node_number}.conf |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 271 | cp ${SWIFT_DIR}/etc/account-server.conf-sample ${swift_node_config} |
| 272 | generate_swift_config ${swift_node_config} ${node_number} $[ACCOUNT_PORT_BASE + 10 * (node_number - 1)] |
Chmouel Boudjnah | 8e5d2f0 | 2012-12-20 13:11:43 +0000 | [diff] [blame] | 273 | sed -i -e "s,#[ ]*recon_cache_path .*,recon_cache_path = ${SWIFT_DATA_DIR}/cache," ${swift_node_config} |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 274 | done |
| 275 | |
| 276 | swift_log_dir=${SWIFT_DATA_DIR}/logs |
| 277 | rm -rf ${swift_log_dir} |
| 278 | mkdir -p ${swift_log_dir}/hourly |
| 279 | sudo chown -R $USER:adm ${swift_log_dir} |
| 280 | sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \ |
| 281 | tee /etc/rsyslog.d/10-swift.conf |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | # configure_swiftclient() - Set config files, create data dirs, etc |
| 285 | function configure_swiftclient() { |
| 286 | setup_develop $SWIFTCLIENT_DIR |
| 287 | } |
| 288 | |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 289 | # create_swift_disk - Create Swift backing disk |
| 290 | function create_swift_disk() { |
| 291 | local node_number |
| 292 | |
| 293 | # First do a bit of setup by creating the directories and |
| 294 | # changing the permissions so we can run it as our user. |
| 295 | |
| 296 | USER_GROUP=$(id -g) |
| 297 | sudo mkdir -p ${SWIFT_DATA_DIR}/{drives,cache,run,logs} |
| 298 | sudo chown -R $USER:${USER_GROUP} ${SWIFT_DATA_DIR} |
| 299 | |
| 300 | # Create a loopback disk and format it to XFS. |
| 301 | if [[ -e ${SWIFT_DATA_DIR}/drives/images/swift.img ]]; then |
| 302 | if egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then |
| 303 | sudo umount ${SWIFT_DATA_DIR}/drives/sdb1 |
| 304 | sudo rm -f ${SWIFT_DATA_DIR}/drives/images/swift.img |
| 305 | fi |
| 306 | fi |
| 307 | |
| 308 | mkdir -p ${SWIFT_DATA_DIR}/drives/images |
| 309 | sudo touch ${SWIFT_DATA_DIR}/drives/images/swift.img |
| 310 | sudo chown $USER: ${SWIFT_DATA_DIR}/drives/images/swift.img |
| 311 | |
| 312 | dd if=/dev/zero of=${SWIFT_DATA_DIR}/drives/images/swift.img \ |
| 313 | bs=1024 count=0 seek=${SWIFT_LOOPBACK_DISK_SIZE} |
| 314 | |
| 315 | # Make a fresh XFS filesystem |
| 316 | mkfs.xfs -f -i size=1024 ${SWIFT_DATA_DIR}/drives/images/swift.img |
| 317 | |
| 318 | # Mount the disk with mount options to make it as efficient as possible |
| 319 | mkdir -p ${SWIFT_DATA_DIR}/drives/sdb1 |
| 320 | if ! egrep -q ${SWIFT_DATA_DIR}/drives/sdb1 /proc/mounts; then |
| 321 | sudo mount -t xfs -o loop,noatime,nodiratime,nobarrier,logbufs=8 \ |
| 322 | ${SWIFT_DATA_DIR}/drives/images/swift.img ${SWIFT_DATA_DIR}/drives/sdb1 |
| 323 | fi |
| 324 | |
| 325 | # Create a link to the above mount and |
| 326 | # create all of the directories needed to emulate a few different servers |
| 327 | for node_number in ${SWIFT_REPLICAS_SEQ}; do |
| 328 | sudo ln -sf ${SWIFT_DATA_DIR}/drives/sdb1/$node_number ${SWIFT_DATA_DIR}/$node_number; |
| 329 | drive=${SWIFT_DATA_DIR}/drives/sdb1/${node_number} |
| 330 | node=${SWIFT_DATA_DIR}/${node_number}/node |
| 331 | node_device=${node}/sdb1 |
| 332 | [[ -d $node ]] && continue |
| 333 | [[ -d $drive ]] && continue |
| 334 | sudo install -o ${USER} -g $USER_GROUP -d $drive |
| 335 | sudo install -o ${USER} -g $USER_GROUP -d $node_device |
| 336 | sudo chown -R $USER: ${node} |
| 337 | done |
| 338 | } |
| 339 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 340 | # init_swift() - Initialize rings |
| 341 | function init_swift() { |
| 342 | local node_number |
| 343 | # Make sure to kill all swift processes first |
Chmouel Boudjnah | ad8b276 | 2013-01-10 15:40:01 +0100 | [diff] [blame] | 344 | swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 345 | |
Dean Troyer | 1c6c112 | 2013-03-27 17:40:53 -0500 | [diff] [blame] | 346 | # Forcibly re-create the backing filesystem |
| 347 | create_swift_disk |
| 348 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 349 | # This is where we create three different rings for swift with |
| 350 | # different object servers binding on different ports. |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 351 | pushd ${SWIFT_CONF_DIR} >/dev/null && { |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 352 | |
| 353 | rm -f *.builder *.ring.gz backups/*.builder backups/*.ring.gz |
| 354 | |
| 355 | swift-ring-builder object.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1 |
| 356 | swift-ring-builder container.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1 |
| 357 | swift-ring-builder account.builder create ${SWIFT_PARTITION_POWER_SIZE} ${SWIFT_REPLICAS} 1 |
| 358 | |
| 359 | for node_number in ${SWIFT_REPLICAS_SEQ}; do |
| 360 | swift-ring-builder object.builder add z${node_number}-127.0.0.1:$[OBJECT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1 |
| 361 | swift-ring-builder container.builder add z${node_number}-127.0.0.1:$[CONTAINER_PORT_BASE + 10 * (node_number - 1)]/sdb1 1 |
| 362 | swift-ring-builder account.builder add z${node_number}-127.0.0.1:$[ACCOUNT_PORT_BASE + 10 * (node_number - 1)]/sdb1 1 |
| 363 | done |
| 364 | swift-ring-builder object.builder rebalance |
| 365 | swift-ring-builder container.builder rebalance |
| 366 | swift-ring-builder account.builder rebalance |
| 367 | } && popd >/dev/null |
| 368 | |
Dean Troyer | 64ab774 | 2012-12-28 15:38:28 -0600 | [diff] [blame] | 369 | # Create cache dir |
| 370 | sudo mkdir -p $SWIFT_AUTH_CACHE_DIR |
Attila Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 371 | sudo chown $STACK_USER $SWIFT_AUTH_CACHE_DIR |
Dean Troyer | 64ab774 | 2012-12-28 15:38:28 -0600 | [diff] [blame] | 372 | rm -f $SWIFT_AUTH_CACHE_DIR/* |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | function install_swift() { |
| 376 | git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH |
| 377 | } |
| 378 | |
| 379 | function install_swiftclient() { |
| 380 | git_clone $SWIFTCLIENT_REPO $SWIFTCLIENT_DIR $SWIFTCLIENT_BRANCH |
| 381 | } |
| 382 | |
| 383 | |
| 384 | # start_swift() - Start running processes, including screen |
| 385 | function start_swift() { |
| 386 | # (re)start rsyslog |
| 387 | restart_service rsyslog |
Chmouel Boudjnah | 8ecbb38 | 2013-03-12 12:15:17 +0100 | [diff] [blame] | 388 | # (re)start memcached to make sure we have a clean memcache. |
| 389 | restart_service memcached |
| 390 | |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 391 | # Start rsync |
Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 392 | if is_ubuntu; then |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 393 | sudo /etc/init.d/rsync restart || : |
| 394 | else |
| 395 | sudo systemctl start xinetd.service |
| 396 | fi |
| 397 | |
Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 398 | # By default with only one replica we are launching the proxy, |
| 399 | # container, account and object server in screen in foreground and |
| 400 | # other services in background. If we have SWIFT_REPLICAS set to something |
| 401 | # greater than one we first spawn all the swift services then kill the proxy |
| 402 | # service so we can run it in foreground in screen. ``swift-init ... |
| 403 | # {stop|restart}`` exits with '1' if no servers are running, ignore it just |
| 404 | # in case |
Chmouel Boudjnah | ad8b276 | 2013-01-10 15:40:01 +0100 | [diff] [blame] | 405 | swift-init --run-dir=${SWIFT_DATA_DIR}/run all restart || true |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 406 | if [[ ${SWIFT_REPLICAS} == 1 ]]; then |
Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 407 | todo="object container account" |
| 408 | fi |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 409 | for type in proxy ${todo}; do |
Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 410 | swift-init --run-dir=${SWIFT_DATA_DIR}/run ${type} stop || true |
| 411 | done |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 412 | screen_it s-proxy "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONF_DIR}/proxy-server.conf -v" |
| 413 | if [[ ${SWIFT_REPLICAS} == 1 ]]; then |
Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 414 | for type in object container account;do |
Dean Troyer | 6ec72fa | 2013-03-13 11:44:53 -0500 | [diff] [blame] | 415 | screen_it s-${type} "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-${type}-server ${SWIFT_CONF_DIR}/${type}-server/1.conf -v" |
Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 416 | done |
| 417 | fi |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | # stop_swift() - Stop running processes (non-screen) |
| 421 | function stop_swift() { |
| 422 | # screen normally killed by unstack.sh |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 423 | if type -p swift-init >/dev/null; then |
Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 424 | swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true |
| 425 | fi |
Dean Troyer | 995eb92 | 2013-03-07 16:11:40 -0600 | [diff] [blame] | 426 | # Dump the proxy server |
| 427 | sudo pkill -f swift-proxy-server |
Attila Fazekas | ece6a33 | 2012-11-29 14:19:41 +0100 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | # Restore xtrace |
| 431 | $XTRACE |