|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright 2011 Henrik Ingo <henrik.ingo@openlife.cc> |
| 4 | +# License = GPLv2 or later |
| 5 | +# |
| 6 | +# This program is free software; you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU General Public License as published by |
| 8 | +# the Free Software Foundation; version 2 or later of the License. |
| 9 | +# |
| 10 | +# This program is distributed in the hope that it will be useful, |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +# GNU General Public License for more details. |
| 14 | +# |
| 15 | +# You should have received a copy of the GNU General Public License |
| 16 | +# along with this program; if not, write to the Free Software |
| 17 | +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | + |
| 19 | +set -e |
| 20 | + |
| 21 | +# Check for a local cached configuration. |
| 22 | +if test -f /etc/buildslave; then |
| 23 | + . /etc/buildslave |
| 24 | +fi |
| 25 | + |
| 26 | +# These parameters should be set and exported in the user-data script that |
| 27 | +# calls us. If they are not there, we set some defaults but they almost |
| 28 | +# certainly will not work. |
| 29 | +if test ! "$BB_MASTER"; then |
| 30 | + BB_MASTER="build.lustre.org:9989" |
| 31 | +fi |
| 32 | +if test ! "$BB_NAME"; then |
| 33 | + BB_NAME=$(hostname) |
| 34 | +fi |
| 35 | +if test ! "$BB_PASSWORD"; then |
| 36 | + BB_PASSWORD="password" |
| 37 | +fi |
| 38 | +if test ! "$BB_ADMIN"; then |
| 39 | + BB_ADMIN="Automated Lustre BuildBot slave <buildbot-admin@lustre.org>" |
| 40 | +fi |
| 41 | +if test ! "$BB_DIR"; then |
| 42 | + BB_DIR="/var/lib/buildbot/slaves/lustre" |
| 43 | +fi |
| 44 | +if test ! "$BB_USE_PIP"; then |
| 45 | + BB_USE_PIP=0 |
| 46 | +fi |
| 47 | +if test ! "$BB_URL"; then |
| 48 | + BB_URL="https://raw.githubusercontent.com/opensfs/lustre-buildbot-config/master/scripts/" |
| 49 | +fi |
| 50 | + |
| 51 | +if test ! -f /etc/buildslave; then |
| 52 | + echo "BB_MASTER=\"$BB_MASTER\"" > /etc/buildslave |
| 53 | + echo "BB_NAME=\"$BB_NAME\"" >> /etc/buildslave |
| 54 | + echo "BB_PASSWORD=\"$BB_PASSWORD\"" >> /etc/buildslave |
| 55 | + echo "BB_ADMIN=\"$BB_ADMIN\"" >> /etc/buildslave |
| 56 | + echo "BB_DIR=\"$BB_DIR\"" >> /etc/buildslave |
| 57 | + echo "BB_URL=\"$BB_URL\"" >> /etc/buildslave |
| 58 | +fi |
| 59 | + |
| 60 | +BB_PARAMS="${BB_DIR} ${BB_MASTER} ${BB_NAME} ${BB_PASSWORD}" |
| 61 | +echo "$0: BB_PARAMS is now $BB_PARAMS" |
| 62 | +echo "$0: BB_URL is now $BB_URL" |
| 63 | + |
| 64 | +set -x |
| 65 | + |
| 66 | +# Magic IP address from where to obtain EC2 metadata |
| 67 | +METAIP="169.254.169.254" |
| 68 | +METAROOT="http://${METAIP}/latest" |
| 69 | +# Don't print 404 error documents. Don't print progress information. |
| 70 | +CURL="curl --fail --silent" |
| 71 | + |
| 72 | + |
| 73 | +testbin () { |
| 74 | + BIN_PATH="$(which ${1})" |
| 75 | + if [ ! -x "${BIN_PATH}" -o -z "${BIN_PATH}" ]; then |
| 76 | + return 1 |
| 77 | + fi |
| 78 | + return 0 |
| 79 | +} |
| 80 | + |
| 81 | +case "$BB_NAME" in |
| 82 | +Amazon*) |
| 83 | + yum -y install deltarpm gcc python-pip python-devel |
| 84 | + easy_install --quiet buildbot-slave |
| 85 | + BUILDSLAVE="/usr/local/bin/buildslave" |
| 86 | + |
| 87 | + # User buildbot needs to be added to sudoers and requiretty disabled. |
| 88 | + if ! id -u buildbot >/dev/null 2>&1; then |
| 89 | + adduser buildbot |
| 90 | + echo "buildbot ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers |
| 91 | + sed -i.bak 's/ requiretty/ !requiretty/' /etc/sudoers |
| 92 | + sed -i.bak '/secure_path/d' /etc/sudoers |
| 93 | + fi |
| 94 | + ;; |
| 95 | + |
| 96 | +CentOS*) |
| 97 | + if cat /etc/redhat-release | grep -Eq "6."; then |
| 98 | + # The buildbot-slave package isn't available from a common repo. |
| 99 | + BUILDSLAVE_URL="http://build.zfsonlinux.org" |
| 100 | + BUILDSLAVE_RPM="buildbot-slave-0.8.8-2.el6.noarch.rpm" |
| 101 | + yum -y install $BUILDSLAVE_URL/$BUILDSLAVE_RPM |
| 102 | + BUILDSLAVE="/usr/bin/buildslave" |
| 103 | + else |
| 104 | + yum -y install deltarpm gcc python-pip python-devel |
| 105 | + easy_install --quiet buildbot-slave |
| 106 | + BUILDSLAVE="/usr/bin/buildslave" |
| 107 | + fi |
| 108 | + |
| 109 | + # User buildbot needs to be added to sudoers and requiretty disabled. |
| 110 | + if ! id -u buildbot >/dev/null 2>&1; then |
| 111 | + adduser buildbot |
| 112 | + fi |
| 113 | + |
| 114 | + echo "buildbot ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers |
| 115 | + sed -i.bak 's/ requiretty/ !requiretty/' /etc/sudoers |
| 116 | + sed -i.bak '/secure_path/d' /etc/sudoers |
| 117 | + ;; |
| 118 | + |
| 119 | +Debian*) |
| 120 | + apt-get --yes update |
| 121 | + |
| 122 | + # Relying on the pip version of the buildslave is more portable but |
| 123 | + # slower to bootstrap. By default prefer the packaged version. |
| 124 | + if test $BB_USE_PIP -ne 0; then |
| 125 | + apt-get --yes install gcc curl python-pip python-dev |
| 126 | + pip --quiet install buildbot-slave |
| 127 | + BUILDSLAVE="/usr/local/bin/buildslave" |
| 128 | + else |
| 129 | + apt-get --yes install curl buildbot-slave |
| 130 | + BUILDSLAVE="/usr/bin/buildslave" |
| 131 | + fi |
| 132 | + |
| 133 | + # User buildbot needs to be added to sudoers and requiretty disabled. |
| 134 | + if ! id -u buildbot >/dev/null 2>&1; then |
| 135 | + adduser --disabled-password --gecos "" buildbot |
| 136 | + fi |
| 137 | + |
| 138 | + echo "buildbot ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers |
| 139 | + sed -i.bak 's/ requiretty/ !requiretty/' /etc/sudoers |
| 140 | + sed -i.bak '/secure_path/d' /etc/sudoers |
| 141 | + ;; |
| 142 | + |
| 143 | +Fedora*) |
| 144 | + # Relying on the pip version of the buildslave is more portable but |
| 145 | + # slower to bootstrap. By default prefer the packaged version. |
| 146 | + if test $BB_USE_PIP -ne 0; then |
| 147 | + dnf -y install gcc python-pip python-devel |
| 148 | + easy_install --quiet buildbot-slave |
| 149 | + BUILDSLAVE="/usr/bin/buildslave" |
| 150 | + else |
| 151 | + dnf -y install buildbot-slave |
| 152 | + BUILDSLAVE="/usr/bin/buildslave" |
| 153 | + fi |
| 154 | + |
| 155 | + # User buildbot needs to be added to sudoers and requiretty disabled. |
| 156 | + if ! id -u buildbot >/dev/null 2>&1; then |
| 157 | + adduser buildbot |
| 158 | + fi |
| 159 | + |
| 160 | + echo "buildbot ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers |
| 161 | + sed -i.bak 's/ requiretty/ !requiretty/' /etc/sudoers |
| 162 | + sed -i.bak '/secure_path/d' /etc/sudoers |
| 163 | + ;; |
| 164 | + |
| 165 | +Gentoo*) |
| 166 | + emerge-webrsync |
| 167 | + emerge app-admin/sudo dev-util/buildbot-slave |
| 168 | + BUILDSLAVE="/usr/bin/buildslave" |
| 169 | + |
| 170 | + # User buildbot needs to be added to sudoers and requiretty disabled. |
| 171 | + echo "buildbot ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers |
| 172 | + ;; |
| 173 | + |
| 174 | +RHEL*) |
| 175 | + yum -y install deltarpm gcc python-pip python-devel |
| 176 | + easy_install --quiet buildbot-slave |
| 177 | + BUILDSLAVE="/usr/bin/buildslave" |
| 178 | + |
| 179 | + # User buildbot needs to be added to sudoers and requiretty disabled. |
| 180 | + if ! id -u buildbot >/dev/null 2>&1; then |
| 181 | + adduser buildbot |
| 182 | + echo "buildbot ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers |
| 183 | + sed -i.bak 's/ requiretty/ !requiretty/' /etc/sudoers |
| 184 | + sed -i.bak '/secure_path/d' /etc/sudoers |
| 185 | + fi |
| 186 | + ;; |
| 187 | + |
| 188 | +SUSE*) |
| 189 | + # SLES appears to not always register their repos properly. |
| 190 | + echo "solver.allowVendorChange = true" >>/etc/zypp/zypp.conf |
| 191 | + # while ! zypper --non-interactive up; do sleep 10; done |
| 192 | + while ! /usr/sbin/registercloudguest --force-new; do sleep 10; done |
| 193 | + # may need to kexec to reload kernel, need to some how do an up? |
| 194 | + |
| 195 | + # Zypper auto-refreshes on boot retry to avoid spurious failures. |
| 196 | + zypper --non-interactive install gcc python-devel python-pip |
| 197 | + easy_install --quiet buildbot-slave |
| 198 | + BUILDSLAVE="/usr/bin/buildslave" |
| 199 | + |
| 200 | + # User buildbot needs to be added to sudoers and requiretty disabled. |
| 201 | + if ! id -u buildbot >/dev/null 2>&1; then |
| 202 | + groupadd buildbot |
| 203 | + useradd buildbot |
| 204 | + echo "buildbot ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers |
| 205 | + sed -i.bak 's/ requiretty/ !requiretty/' /etc/sudoers |
| 206 | + sed -i.bak '/secure_path/d' /etc/sudoers |
| 207 | + fi |
| 208 | + |
| 209 | + mkdir "/home/buildbot" |
| 210 | + chown "buildbot:" "/home/buildbot/" |
| 211 | + ;; |
| 212 | + |
| 213 | +OpenSUSE*) |
| 214 | + # SLES appears to not always register their repos properly. |
| 215 | + echo "solver.allowVendorChange = true" >>/etc/zypp/zypp.conf |
| 216 | + # while ! zypper --non-interactive up; do sleep 10; done |
| 217 | + while ! /usr/sbin/registercloudguest --force-new; do sleep 10; done |
| 218 | + # may need to kexec to reload kernel, need to some how do an up? |
| 219 | + |
| 220 | + # Zypper auto-refreshes on boot retry to avoid spurious failures. |
| 221 | + zypper --non-interactive install gcc python-devel python-pip |
| 222 | + easy_install --quiet buildbot-slave |
| 223 | + BUILDSLAVE="/usr/bin/buildslave" |
| 224 | + |
| 225 | + # User buildbot needs to be added to sudoers and requiretty disabled. |
| 226 | + if ! id -u buildbot >/dev/null 2>&1; then |
| 227 | + groupadd buildbot |
| 228 | + useradd buildbot |
| 229 | + echo "buildbot ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers |
| 230 | + sed -i.bak 's/ requiretty/ !requiretty/' /etc/sudoers |
| 231 | + sed -i.bak '/secure_path/d' /etc/sudoers |
| 232 | + fi |
| 233 | + |
| 234 | + mkdir "/home/buildbot" |
| 235 | + chown "buildbot:" "/home/buildbot/" |
| 236 | + ;; |
| 237 | + |
| 238 | +Ubuntu*) |
| 239 | +# codename=$(lsb_release -c | awk '{print $2}') |
| 240 | +# sudo tee /etc/apt/sources.list.d/ddebs.list << EOF |
| 241 | +#deb http://ddebs.ubuntu.com/ ${codename} main restricted universe multiverse |
| 242 | +#deb http://ddebs.ubuntu.com/ ${codename}-security main restricted universe multiverse |
| 243 | +#deb http://ddebs.ubuntu.com/ ${codename}-updates main restricted universe multiverse |
| 244 | +#deb http://ddebs.ubuntu.com/ ${codename}-proposed main restricted universe multiverse |
| 245 | +#EOF |
| 246 | + |
| 247 | + sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ECDCAD72428D7C01 |
| 248 | + sudo apt-get --yes update |
| 249 | + |
| 250 | + # Relying on the pip version of the buildslave is more portable but |
| 251 | + # slower to bootstrap. By default prefer the packaged version. |
| 252 | + if test $BB_USE_PIP -ne 0; then |
| 253 | + apt-get --yes install gcc python-pip python-dev |
| 254 | + pip --quiet install buildbot-slave |
| 255 | + BUILDSLAVE="/usr/local/bin/buildslave" |
| 256 | + else |
| 257 | + apt-get --yes install buildbot-slave |
| 258 | + BUILDSLAVE="/usr/bin/buildslave" |
| 259 | + fi |
| 260 | + |
| 261 | + # User buildbot needs to be added to sudoers and requiretty disabled. |
| 262 | + if ! id -u buildbot >/dev/null 2>&1; then |
| 263 | + adduser --disabled-password --gecos "" buildbot |
| 264 | + fi |
| 265 | + |
| 266 | + echo "buildbot ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers |
| 267 | + sed -i.bak 's/ requiretty/ !requiretty/' /etc/sudoers |
| 268 | + sed -i.bak '/secure_path/d' /etc/sudoers |
| 269 | + ;; |
| 270 | + |
| 271 | +*) |
| 272 | + echo "Unknown distribution, cannot bootstrap $BB_NAME" |
| 273 | + ;; |
| 274 | +esac |
| 275 | + |
| 276 | +# Generic buildslave configuration |
| 277 | +if test ! -d $BB_DIR; then |
| 278 | + mkdir -p $BB_DIR |
| 279 | + chown buildbot.buildbot $BB_DIR |
| 280 | + sudo -u buildbot $BUILDSLAVE create-slave --umask=022 --usepty=0 $BB_PARAMS |
| 281 | +fi |
| 282 | + |
| 283 | +# Extract some of the EC2 meta-data and make it visible in the buildslave |
| 284 | +echo $BB_ADMIN > $BB_DIR/info/admin |
| 285 | +$CURL "${METAROOT}/meta-data/public-hostname" > $BB_DIR/info/host |
| 286 | +echo >> $BB_DIR/info/host |
| 287 | +$CURL "${METAROOT}/meta-data/instance-type" >> $BB_DIR/info/host |
| 288 | +echo >> $BB_DIR/info/host |
| 289 | +$CURL "${METAROOT}/meta-data/ami-id" >> $BB_DIR/info/host |
| 290 | +echo >> $BB_DIR/info/host |
| 291 | +$CURL "${METAROOT}/meta-data/instance-id" >> $BB_DIR/info/host |
| 292 | +echo >> $BB_DIR/info/host |
| 293 | +uname -a >> $BB_DIR/info/host |
| 294 | +grep MemTotal /proc/meminfo >> $BB_DIR/info/host |
| 295 | +grep 'model name' /proc/cpuinfo >> $BB_DIR/info/host |
| 296 | +grep 'processor' /proc/cpuinfo >> $BB_DIR/info/host |
| 297 | + |
| 298 | +# Finally, start it. |
| 299 | +sudo -u buildbot $BUILDSLAVE start $BB_DIR |
| 300 | + |
| 301 | +# If all goes well, at this point you should see a buildbot slave joining your |
| 302 | +# farm. You can then manage the rest of the work from the buildbot master. |
0 commit comments