From d48c75bdbf186d57276db28aff1abc5c7238a9c3 Mon Sep 17 00:00:00 2001 From: Rui Lopes Date: Mon, 10 Jul 2017 20:42:59 +0100 Subject: [PATCH] move the nexus provisioning to a separate script file --- Vagrantfile | 3 +- provision/{provision.sh => provision-base.sh} | 82 ------------------- provision/provision-nexus.sh | 80 ++++++++++++++++++ 3 files changed, 82 insertions(+), 83 deletions(-) rename provision/{provision.sh => provision-base.sh} (55%) create mode 100644 provision/provision-nexus.sh diff --git a/Vagrantfile b/Vagrantfile index 134105f..f5284b8 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -7,7 +7,8 @@ Vagrant.configure(2) do |config| vb.cpus = 2 vb.memory = 4096 end - config.vm.provision :shell, path: 'provision/provision.sh' + config.vm.provision :shell, path: 'provision/provision-base.sh' + config.vm.provision :shell, path: 'provision/provision-nexus.sh' config.vm.provision :shell, path: 'provision/test.sh' config.vm.provision :shell, path: 'provision/summary.sh' end diff --git a/provision/provision.sh b/provision/provision-base.sh similarity index 55% rename from provision/provision.sh rename to provision/provision-base.sh index 434a79a..8ec4751 100644 --- a/provision/provision.sh +++ b/provision/provision-base.sh @@ -113,85 +113,3 @@ server { EOF ln -s ../sites-available/$config_fqdn.conf /etc/nginx/sites-enabled/ systemctl restart nginx - - -# install java. -apt-get install -y default-jre - - -# add the nexus user. -groupadd --system nexus -adduser \ - --system \ - --disabled-login \ - --no-create-home \ - --gecos '' \ - --ingroup nexus \ - --home /opt/nexus \ - nexus -install -d -o root -g nexus -m 750 /opt/nexus - - -# download and install nexus. -pushd /opt/nexus -# see http://www.sonatype.com/download-oss-sonatype -# see https://books.sonatype.com/nexus-book/3.3/reference/index.html -nexus_tarball=nexus-3.3.1-01-unix.tar.gz -nexus_download_url=https://sonatype-download.global.ssl.fastly.net/nexus/3/$nexus_tarball -nexus_download_sha1=e7859e13622ea7e04474a2719c07b045c5fabb53 -wget -q $nexus_download_url -if [ "$(sha1sum $nexus_tarball | awk '{print $1}')" != "$nexus_download_sha1" ]; then - echo "downloaded $nexus_download_url failed the checksum verification" - exit 1 -fi -tar xf $nexus_tarball --strip-components 1 -rm $nexus_tarball -chmod 700 nexus3 -chown -R nexus:nexus nexus3 -install -d -o nexus -g nexus -m 700 .java # java preferences are saved here (the default java.util.prefs.userRoot preference). -install -d -o nexus -g nexus -m 700 nexus3/etc -grep -v -E '\s*##.*' etc/nexus-default.properties >nexus3/etc/nexus.properties -sed -i -E 's,(application-host=).+,\1127.0.0.1,g' nexus3/etc/nexus.properties -sed -i -E 's,nexus-pro-,nexus-oss-,g' nexus3/etc/nexus.properties -diff -u etc/nexus-default.properties nexus3/etc/nexus.properties || true -sed -i -E 's,\.\./sonatype-work/,,g' bin/nexus.vmoptions -popd - - -# start nexus. -cat >/etc/systemd/system/nexus.service <<'EOF' -[Unit] -Description=Nexus -After=network.target - -[Service] -Type=simple -User=nexus -Group=nexus -ExecStart=/opt/nexus/bin/nexus run -WorkingDirectory=/opt/nexus -Restart=always - -[Install] -WantedBy=multi-user.target -EOF -systemctl enable nexus -systemctl start nexus - -# install tools. -apt-get install -y --no-install-recommends httpie -apt-get install -y --no-install-recommends jq - -# wait for nexus to come up. -bash -c 'while [[ "$(wget -qO- http://localhost:8081/service/extdirect/poll/rapture_State_get | jq -r .data.data.status.value.edition)" != "OSS" ]]; do sleep 5; done' - -# print the version using the API. -wget -qO- http://localhost:8081/service/extdirect/poll/rapture_State_get | jq --raw-output .data.data.uiSettings.value.title -wget -qO- http://localhost:8081/service/extdirect/poll/rapture_State_get | jq .data.data.status.value - -# configure nexus with the groovy script. -bash /vagrant/provision/execute-provision.groovy-script.sh - -# clean packages. -apt-get -y autoremove -apt-get -y clean diff --git a/provision/provision-nexus.sh b/provision/provision-nexus.sh new file mode 100644 index 0000000..86a69e4 --- /dev/null +++ b/provision/provision-nexus.sh @@ -0,0 +1,80 @@ +#!/bin/bash +set -eux + + +# install java. +apt-get install -y default-jre + + +# add the nexus user. +groupadd --system nexus +adduser \ + --system \ + --disabled-login \ + --no-create-home \ + --gecos '' \ + --ingroup nexus \ + --home /opt/nexus \ + nexus +install -d -o root -g nexus -m 750 /opt/nexus + + +# download and install nexus. +pushd /opt/nexus +# see http://www.sonatype.com/download-oss-sonatype +# see https://books.sonatype.com/nexus-book/3.3/reference/index.html +nexus_tarball=nexus-3.3.1-01-unix.tar.gz +nexus_download_url=https://sonatype-download.global.ssl.fastly.net/nexus/3/$nexus_tarball +nexus_download_sha1=e7859e13622ea7e04474a2719c07b045c5fabb53 +wget -q $nexus_download_url +if [ "$(sha1sum $nexus_tarball | awk '{print $1}')" != "$nexus_download_sha1" ]; then + echo "downloaded $nexus_download_url failed the checksum verification" + exit 1 +fi +tar xf $nexus_tarball --strip-components 1 +rm $nexus_tarball +chmod 700 nexus3 +chown -R nexus:nexus nexus3 +install -d -o nexus -g nexus -m 700 .java # java preferences are saved here (the default java.util.prefs.userRoot preference). +install -d -o nexus -g nexus -m 700 nexus3/etc +grep -v -E '\s*##.*' etc/nexus-default.properties >nexus3/etc/nexus.properties +sed -i -E 's,(application-host=).+,\1127.0.0.1,g' nexus3/etc/nexus.properties +sed -i -E 's,nexus-pro-,nexus-oss-,g' nexus3/etc/nexus.properties +diff -u etc/nexus-default.properties nexus3/etc/nexus.properties || true +sed -i -E 's,\.\./sonatype-work/,,g' bin/nexus.vmoptions +popd + + +# start nexus. +cat >/etc/systemd/system/nexus.service <<'EOF' +[Unit] +Description=Nexus +After=network.target + +[Service] +Type=simple +User=nexus +Group=nexus +ExecStart=/opt/nexus/bin/nexus run +WorkingDirectory=/opt/nexus +Restart=always + +[Install] +WantedBy=multi-user.target +EOF +systemctl enable nexus +systemctl start nexus + +# install tools. +apt-get install -y --no-install-recommends httpie +apt-get install -y --no-install-recommends jq + +# wait for nexus to come up. +bash -c 'while [[ "$(wget -qO- http://localhost:8081/service/extdirect/poll/rapture_State_get | jq -r .data.data.status.value.edition)" != "OSS" ]]; do sleep 5; done' + +# print the version using the API. +wget -qO- http://localhost:8081/service/extdirect/poll/rapture_State_get | jq --raw-output .data.data.uiSettings.value.title +wget -qO- http://localhost:8081/service/extdirect/poll/rapture_State_get | jq .data.data.status.value + +# configure nexus with the groovy script. +bash /vagrant/provision/execute-provision.groovy-script.sh