setup-object-storage.sh 13.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#!/bin/sh

##
## Setup a OpenStack object storage node.
##

set -x

# Gotta know the rules!
if [ $EUID -ne 0 ] ; then
    echo "This script must be run as root" 1>&2
    exit 1
fi

# Grab our libs
. "`dirname $0`/setup-lib.sh"

if [ "$HOSTNAME" != "$OBJECTHOST" ]; then
    exit 0;
fi

if [ -f $OURDIR/setup-object-host-done ]; then
    exit 0
fi

26 27
logtstart "object-storage"

28 29 30
if [ -f $SETTINGS ]; then
    . $SETTINGS
fi
31 32 33
if [ -f $LOCALSETTINGS ]; then
    . $LOCALSETTINGS
fi
34

35
maybe_install_packages xfsprogs rsync
36

37 38 39 40 41
#
# First try to make LVM volumes; fall back to loop device in /storage.  We use
# /storage for swift later, so we make the dir either way.
#

42
mkdir -p /storage
43 44 45
if [ -z "$LVM" ] ; then
    LVM=1
    VGNAME="openstack-volumes"
46
    MKEXTRAFS_ARGS="-l -v ${VGNAME} -m util -z 1024"
47
    # On Cloudlab ARM machines, there is no second disk nor extra disk space
48
    # Well, now there's a new partition layout; try it.
49
    if [ "$ARCH" = "aarch64" ]; then
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
	maybe_install_packages gdisk
	sgdisk -i 1 /dev/sda
	if [ $? -eq 0 ] ; then
	    sgdisk -N 2 /dev/sda
	    if [ $? -eq 0 ] ; then
		partprobe
		# Add the second partition specifically
		MKEXTRAFS_ARGS="${MKEXTRAFS_ARGS} -s 2"
	    else
		MKEXTRAFS_ARGS=""
		LVM=0
	    fi
	else
	    MKEXTRAFS_ARGS=""
	    LVM=0
	fi
66 67 68 69 70 71 72 73 74 75 76 77
    fi

    /usr/local/etc/emulab/mkextrafs.pl ${MKEXTRAFS_ARGS}
    if [ $? -ne 0 ]; then
	/usr/local/etc/emulab/mkextrafs.pl ${MKEXTRAFS_ARGS} -f
	if [ $? -ne 0 ]; then
	    /usr/local/etc/emulab/mkextrafs.pl -f /storage
	    LVM=0
	fi
    fi
fi

78
LDEVS=""
79 80 81 82
if [ $LVM -eq 0 ] ; then
    dd if=/dev/zero of=/storage/swiftv1 bs=32768 count=131072
    LDEV=`losetup -f`
    losetup $LDEV /storage/swiftv1
83 84 85 86 87
    LDEVS="${LDEV}"
    dd if=/dev/zero of=/storage/swiftv1-2 bs=32768 count=131072
    LDEV=`losetup -f`
    losetup $LDEV /storage/swiftv1-2
    LDEVS="${LDEVS} ${LDEV}"
88 89 90
else
    lvcreate -n swiftv1 -L 4G $VGNAME
    LDEV=/dev/${VGNAME}/swiftv1
91 92 93 94
    LDEVS="${LDEV}"
    lvcreate -n swiftv1-2 -L 4G $VGNAME
    LDEV=/dev/${VGNAME}/swiftv1-2
    LDEVS="${LDEVS} ${LDEV}"
95
fi
96 97

mkdir -p /storage/mnt/swift
98 99 100 101 102
for ldev in $LDEVS ; do
    base=`basename $ldev`
    mkfs.xfs $ldev
    cat <<EOF >> /etc/fstab
$ldev /storage/mnt/swift/$base xfs noatime,nodiratime,nobarrier,logbufs=8 0 2
103
EOF
104 105 106
    mkdir -p /storage/mnt/swift/$base
    mount /storage/mnt/swift/$base
done
107 108 109 110 111 112

cat <<EOF >> /etc/rsyncd.conf
uid = swift
gid = swift
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
113
address = $MGMTIP
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137

[account]
max connections = 8
path = /storage/mnt/swift
read only = false
lock file = /var/lock/account.lock

[container]
max connections = 8
path = /storage/mnt/swift
read only = false
lock file = /var/lock/container.lock

[object]
max connections = 8
path = /storage/mnt/swift
read only = false
lock file = /var/lock/object.lock
EOF

cat <<EOF >> /etc/default/rsync
RSYNC_ENABLE=true
EOF

138 139 140
service_enable rsync
service_restart rsync
service_start rsync
141

142 143
mkdir -p /var/log/swift
chown -R syslog.adm /var/log/swift
144

145
maybe_install_packages swift swift-account swift-container swift-object
146

David Johnson's avatar
David Johnson committed
147
wget -O /etc/swift/account-server.conf \
148
    "https://git.openstack.org/cgit/openstack/swift/plain/etc/account-server.conf-sample?h=stable/${OSCODENAME}"
149 150 151 152 153
if [ ! $? -eq 0 ]; then
    # Try the EOL version...
    wget -O /etc/swift/account-server.conf \
	"https://git.openstack.org/cgit/openstack/swift/plain/etc/account-server.conf-sample?h=${OSCODENAME}-eol"
fi
154

David Johnson's avatar
David Johnson committed
155
wget -O /etc/swift/container-server.conf \
156
    "https://git.openstack.org/cgit/openstack/swift/plain/etc/container-server.conf-sample?h=stable/${OSCODENAME}"
157 158 159 160 161
if [ ! $? -eq 0 ]; then
    # Try the EOL version...
    wget -O /etc/swift/container-server.conf \
	"https://git.openstack.org/cgit/openstack/swift/plain/etc/container-server.conf-sample?h=${OSCODENAME}-eol"
fi
162

David Johnson's avatar
David Johnson committed
163
wget -O /etc/swift/object-server.conf \
164
    "https://git.openstack.org/cgit/openstack/swift/plain/etc/object-server.conf-sample?h=stable/${OSCODENAME}"
165 166 167 168 169
if [ ! $? -eq 0 ]; then
    # Try the EOL version...
    wget -O /etc/swift/object-server.conf \
	"https://git.openstack.org/cgit/openstack/swift/plain/etc/object-server.conf-sample?h=${OSCODENAME}-eol"
fi
170

171
if [ $OSVERSION -ge $OSKILO ]; then
172 173
    wget -O /etc/swift/container-reconciler.conf \
	"https://git.openstack.org/cgit/openstack/swift/plain/etc/container-reconciler.conf-sample?h=stable/${OSCODENAME}"
174 175 176 177 178
    if [ ! $? -eq 0 ]; then
        # Try the EOL version...
	wget -O /etc/swift/container-reconciler.conf \
	    "https://git.openstack.org/cgit/openstack/swift/plain/etc/container-reconciler.conf-sample?h=${OSCODENAME}-eol"
    fi
179 180
    wget -O /etc/swift/object-expirer.conf \
	"https://git.openstack.org/cgit/openstack/swift/plain/etc/object-expirer.conf-sample?h=stable/${OSCODENAME}"
181 182 183 184 185
    if [ ! $? -eq 0 ]; then
        # Try the EOL version...
	wget -O /etc/swift/object-expirer.conf \
	    "https://git.openstack.org/cgit/openstack/swift/plain/etc/object-expirer.conf-sample?h=${OSCODENAME}-eol"
    fi
186
fi
187

188 189 190 191 192 193 194 195
crudini --set /etc/swift/account-server.conf DEFAULT bind_ip $MGMTIP
crudini --set /etc/swift/account-server.conf DEFAULT bind_port 6002
crudini --set /etc/swift/account-server.conf DEFAULT user swift
crudini --set /etc/swift/account-server.conf DEFAULT swift_dir /etc/swift
crudini --set /etc/swift/account-server.conf DEFAULT devices /storage/mnt/swift
if [ $OSVERSION -ge $OSLIBERTY ]; then
    crudini --set /etc/swift/account-server.conf DEFAULT mount_check true
fi
196

197 198 199 200 201 202
crudini --set /etc/swift/account-server.conf pipeline:main \
    pipeline 'healthcheck recon account-server'
crudini --set /etc/swift/account-server.conf filter:recon \
    use 'egg:swift#recon'
crudini --set /etc/swift/account-server.conf filter:recon \
    recon_cache_path /var/cache/swift
203

204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
crudini --set /etc/swift/account-server.conf DEFAULT log_facility LOG_LOCAL1
crudini --set /etc/swift/account-server.conf DEFAULT log_level INFO
crudini --set /etc/swift/account-server.conf DEFAULT log_name swift-account
crudini --set /etc/swift/account-server.conf app:account-server log_facility LOG_LOCAL1
crudini --set /etc/swift/account-server.conf app:account-server log_level INFO
crudini --set /etc/swift/account-server.conf app:account-server log_name swift-account
crudini --set /etc/swift/account-server.conf account-replicator log_facility LOG_LOCAL1
crudini --set /etc/swift/account-server.conf account-replicator log_level INFO
crudini --set /etc/swift/account-server.conf account-replicator log_name swift-account-replicator
crudini --set /etc/swift/account-server.conf account-auditor log_facility LOG_LOCAL1
crudini --set /etc/swift/account-server.conf account-auditor log_level INFO
crudini --set /etc/swift/account-server.conf account-auditor log_name swift-account-auditor
crudini --set /etc/swift/account-server.conf account-reaper log_facility LOG_LOCAL1
crudini --set /etc/swift/account-server.conf account-reaper log_level INFO
crudini --set /etc/swift/account-server.conf account-reaper log_name swift-account-reaper

echo 'if $programname == "swift-account" then { action(type="omfile" file="/var/log/swift/swift-account.log") }' >> /etc/rsyslog.d/99-swift.conf

222 223 224 225 226 227 228 229
crudini --set /etc/swift/container-server.conf DEFAULT bind_ip $MGMTIP
crudini --set /etc/swift/container-server.conf DEFAULT bind_port 6001
crudini --set /etc/swift/container-server.conf DEFAULT user swift
crudini --set /etc/swift/container-server.conf DEFAULT swift_dir /etc/swift
crudini --set /etc/swift/container-server.conf DEFAULT devices /storage/mnt/swift
if [ $OSVERSION -ge $OSLIBERTY ]; then
    crudini --set /etc/swift/container-server.conf DEFAULT mount_check true
fi
230

231 232 233 234 235 236
crudini --set /etc/swift/container-server.conf pipeline:main \
    pipeline 'healthcheck recon container-server'
crudini --set /etc/swift/container-server.conf filter:recon \
    use 'egg:swift#recon'
crudini --set /etc/swift/container-server.conf filter:recon \
    recon_cache_path /var/cache/swift
237

238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
crudini --set /etc/swift/container-server.conf DEFAULT log_facility LOG_LOCAL1
crudini --set /etc/swift/container-server.conf DEFAULT log_level INFO
crudini --set /etc/swift/container-server.conf DEFAULT log_name swift-container
crudini --set /etc/swift/container-server.conf app:container-server log_facility LOG_LOCAL1
crudini --set /etc/swift/container-server.conf app:container-server log_level INFO
crudini --set /etc/swift/container-server.conf app:container-server log_name swift-container
crudini --set /etc/swift/container-server.conf container-replicator log_facility LOG_LOCAL1
crudini --set /etc/swift/container-server.conf container-replicator log_level INFO
crudini --set /etc/swift/container-server.conf container-replicator log_name swift-container-replicator
crudini --set /etc/swift/container-server.conf container-updater log_facility LOG_LOCAL1
crudini --set /etc/swift/container-server.conf container-updater log_level INFO
crudini --set /etc/swift/container-server.conf container-updater log_name swift-container-updater
crudini --set /etc/swift/container-server.conf container-auditor log_facility LOG_LOCAL1
crudini --set /etc/swift/container-server.conf container-auditor log_level INFO
crudini --set /etc/swift/container-server.conf container-auditor log_name swift-container-auditor
crudini --set /etc/swift/container-server.conf container-sync log_facility LOG_LOCAL1
crudini --set /etc/swift/container-server.conf container-sync log_level INFO
crudini --set /etc/swift/container-server.conf container-sync log_name swift-container-sync

echo 'if $programname == "swift-container" then { action(type="omfile" file="/var/log/swift/swift-container.log") }' >> /etc/rsyslog.d/99-swift.conf

259 260 261 262 263 264 265 266
crudini --set /etc/swift/object-server.conf DEFAULT bind_ip $MGMTIP
crudini --set /etc/swift/object-server.conf DEFAULT bind_port 6000
crudini --set /etc/swift/object-server.conf DEFAULT user swift
crudini --set /etc/swift/object-server.conf DEFAULT swift_dir /etc/swift
crudini --set /etc/swift/object-server.conf DEFAULT devices /storage/mnt/swift
if [ $OSVERSION -ge $OSLIBERTY ]; then
    crudini --set /etc/swift/object-server.conf DEFAULT mount_check true
fi
267

268 269 270 271 272 273 274 275 276
crudini --set /etc/swift/object-server.conf pipeline:main \
    pipeline 'healthcheck recon object-server'
crudini --set /etc/swift/object-server.conf filter:recon \
    use 'egg:swift#recon'
crudini --set /etc/swift/object-server.conf filter:recon \
    recon_cache_path /var/cache/swift
if [ $OSVERSION -ge $OSKILO ]; then
    crudini --set /etc/swift/object-server.conf filter:recon \
	recon_lock_path /var/lock
David Johnson's avatar
David Johnson committed
277
fi
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298

crudini --set /etc/swift/object-server.conf DEFAULT log_facility LOG_LOCAL1
crudini --set /etc/swift/object-server.conf DEFAULT log_level INFO
crudini --set /etc/swift/object-server.conf DEFAULT log_name swift-object
crudini --set /etc/swift/object-server.conf app:object-server log_facility LOG_LOCAL1
crudini --set /etc/swift/object-server.conf app:object-server log_level INFO
crudini --set /etc/swift/object-server.conf app:object-server log_name swift-object
crudini --set /etc/swift/object-server.conf object-replicator log_facility LOG_LOCAL1
crudini --set /etc/swift/object-server.conf object-replicator log_level INFO
crudini --set /etc/swift/object-server.conf object-replicator log_name swift-object-replicator
crudini --set /etc/swift/object-server.conf object-reconstructor log_facility LOG_LOCAL1
crudini --set /etc/swift/object-server.conf object-reconstructor log_level INFO
crudini --set /etc/swift/object-server.conf object-reconstructor log_name swift-object-reconstructor
crudini --set /etc/swift/object-server.conf object-updater log_facility LOG_LOCAL1
crudini --set /etc/swift/object-server.conf object-updater log_level INFO
crudini --set /etc/swift/object-server.conf object-updater log_name swift-object-updater
crudini --set /etc/swift/object-server.conf object-auditor log_facility LOG_LOCAL1
crudini --set /etc/swift/object-server.conf object-auditor log_level INFO
crudini --set /etc/swift/object-server.conf object-auditor log_name swift-object-auditor

echo 'if $programname == "swift-object" then { action(type="omfile" file="/var/log/swift/swift-object.log") }' >> /etc/rsyslog.d/99-swift.conf
299 300 301 302 303 304

chown -R swift:swift /storage/mnt/swift

mkdir -p /var/cache/swift
chown -R swift:swift /var/cache/swift

305 306 307 308
if [ ${HAVE_SYSTEMD} -eq 0 ]; then
    swift-init all start
    service rsyslog restart
else
309 310
    service_restart rsyslog
    service_restart swift-account
311 312
    service_enable swift-proxy
    service_restart swift-proxy
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
    service_enable swift-account
    service_restart swift-account-auditor
    service_enable swift-account-auditor
    service_restart swift-account-reaper
    service_enable swift-account-reaper
    service_restart swift-account-replicator
    service_enable swift-account-replicator
    service_restart swift-container
    service_enable swift-container
    service_restart swift-container-auditor
    service_enable swift-container-auditor
    service_restart swift-container-replicator
    service_enable swift-container-replicator
    service_restart swift-container-sync
    service_enable swift-container-sync
    service_restart swift-container-updater
    service_enable swift-container-updater
    service_restart swift-object
    service_enable swift-object
    service_restart swift-object-auditor
    service_enable swift-object-auditor
    service_restart swift-object-replicator
    service_enable swift-object-replicator
    service_restart swift-object-updater
    service_enable swift-object-updater
338
fi
339 340 341

touch $OURDIR/setup-object-host-done

342 343
logtend "object-storage"

344
exit 0