From 1acd4739344bea1839fc394f6ac2d68aa42e9200 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 14 Feb 2020 16:26:49 +0100 Subject: [PATCH] Changes: - the default domain is domain1, not payaradomain - port 4849 and 8081 are confusing and should be the same as on guest (always possible) - rewrote script to enable secured admin area (login: admin, password: vagrant) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- Vagrantfile | 4 +- payara_service-4.1.2.181 | 4 +- provision.sh | 110 ++++++++++++++++++++++++++++++--------- 3 files changed, 90 insertions(+), 28 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 8f0be6c..41f3f5c 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -2,10 +2,12 @@ # vi: set ft=ruby : Vagrant.configure(2) do |config| - config.vm.box = "ubuntu/trusty64" + config.vm.box = "debian/stretch64" config.vm.provider "virtualbox" do |vb| vb.memory = "4096" + vb.cpus = 4 + vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] end config.vm.provision "shell", path: "provision.sh" diff --git a/payara_service-4.1.2.181 b/payara_service-4.1.2.181 index a3467c5..d4c2187 100755 --- a/payara_service-4.1.2.181 +++ b/payara_service-4.1.2.181 @@ -18,10 +18,10 @@ stopDomain() { case "$1" in start) - startDomain "${2:-payaradomain}" + startDomain "${2:-domain1}" ;; stop) - stopDomain "${2:-payaradomain}" + stopDomain "${2:-domain1}" ;; restart) ${PAYARA_HOME}/bin/asadmin restart-domain >/dev/null diff --git a/provision.sh b/provision.sh index 0e3a284..42c5168 100755 --- a/provision.sh +++ b/provision.sh @@ -14,6 +14,10 @@ PAYARA_VERSION="4.1.2.181" # Payara directory PAYARA_HOME="/opt/payara/payara-${PAYARA_VERSION}" +# Temporary ZIP file +TEMP_ZIP="/home/vagrant/temp.zip" +TEMP_PWD_FILE="/tmp/pwdfile" + # Payara Edition URLs case "${PAYARA_VERSION}" in 4.1.2.181) @@ -77,42 +81,98 @@ installPayara() { echo "Provisioning Payara-${PAYARA_VERSION} ${PAYARA_ED} to ${PAYARA_HOME}" echo "Running update..." - sudo apt-get -qqy update # Update the repos - - echo "Installing openjdk and unzip" - sudo apt-get -qqy install openjdk-8-jdk # Install JDK 8 - sudo apt-get -qqy install unzip # Install unzip - sudo apt-get -qqy install mc # Install Midnight Commander - - echo "Downloading Payara ${PAYARA_VERSION}" - wget -q ${PAYARA_ED} -O temp.zip > /dev/null # Download Payara - sudo mkdir -p ${PAYARA_HOME} # Make dirs for Payara - unzip -qq temp.zip -d ${PAYARA_HOME} # unzip Payara to dir - sudo chown -R vagrant:vagrant ${PAYARA_HOME} # Make sure vagrant owns dir + sudo apt-get -qqy update + + JAVA_BIN=$(which java) + + if [ -z "${JAVA_BIN}" ] + then + echo "Installing openjdk and unzip" + sudo apt-get -y install aptitude || exit 255 + sudo aptitude -y install openjdk-8-jdk unzip mc || exit 255 + else + echo "OpenJDK already installed." + fi + + if [ ! -f "${PAYARA_HOME}/payara41/bin/asadmin" ] + then + # Make sure temp.zip is really gone + sudo rm -f "${TEMP_ZIP}" "${TEMP_ZIP}.md5" + echo "Downloading Payara ${PAYARA_VERSION}" + wget -q "${PAYARA_ED}" -O "${TEMP_ZIP}" || exit 255 + wget -q "${PAYARA_ED}.md5" -O "${TEMP_ZIP}.md5" || exit 255 + + echo "Validating download ..." + MD5_SUM1=$(md5sum "${PAYARA_ED}" | cut -d " " -f 1) + MD5_SUM2=$(cat "${PAYARA_ED}.md5") + if [ "${MD5_SUM1}" != "${MD5_SUM2}" ] + then + echo "MD5 sum '${MD5_SUM1}' doesn't match '${MD5_SUM2}'." + exit 255 + fi + + if [ -d "${PAYARA_HOME}" ] + then + echo "Removing existing directory ..." + sudo rm -rf "${PAYARA_HOME}" + fi + + echo "Unzipping Payara ..." + sudo mkdir -p "${PAYARA_HOME}" + unzip -qq "${TEMP_ZIP}" -d "${PAYARA_HOME}" || exit 255 + sudo chown -R vagrant:vagrant "${PAYARA_HOME}" + sudo rm -f "${TEMP_ZIP}" "${TEMP_ZIP}.md5" + else + echo "Payara was found." + fi } # Copy startup script, and create service installService() { - echo "installing startup scripts" - mkdir -p ${PAYARA_HOME}/startup # Make dirs for Payara - cp /vagrant/payara_service-${PAYARA_VERSION} ${PAYARA_HOME}/startup/ - chmod +x ${PAYARA_HOME}/startup/payara_service-${PAYARA_VERSION} - ln -s ${PAYARA_HOME}/startup/payara_service-${PAYARA_VERSION} /etc/init.d/payara - + echo "Installing startup scripts" + mkdir -p "${PAYARA_HOME}/startup" # Make dirs for Payara + cp "/vagrant/payara_service-${PAYARA_VERSION}" "${PAYARA_HOME}/startup/" || exit 255 + chmod +x "${PAYARA_HOME}/startup/payara_service-${PAYARA_VERSION}" || exit 255 + sudo ln -sf "${PAYARA_HOME}/startup/payara_service-${PAYARA_VERSION}" /etc/init.d/payara + sudo ln -sf "${PAYARA_HOME}/payara41/glassfish/domains/domain1" /home/vagrant/domain1 + echo "Adding payara system startup..." - update-rc.d payara defaults > /dev/null - - echo "Starting Payara..." - - # Explicitly start payaradomain by default + sudo update-rc.d payara defaults > /dev/null + + # echo "Starting Payara..." + + # Start default domain + case "${PAYARA_VERSION}" in + 4.1.2.181) + sudo /etc/init.d/payara start + ;; + /*) + echo "Unknown Payara version, attempting to start domain1..." + sudo /etc/init.d/payara start + esac + + echo "Setting logín 'admin' and password 'vagrant' ..." + echo "AS_ADMIN_PASSWORD=" > "${TEMP_PWD_FILE}" + echo "AS_ADMIN_NEWPASSWORD=vagrant" >> "${TEMP_PWD_FILE}" + "${PAYARA_HOME}/payara41/bin/asadmin" --host localhost --port 4848 --user admin --passwordfile="${TEMP_PWD_FILE}" change-admin-password || exit 255 + rm -f "${TEMP_PWD_FILE}" + + # Enable secure admin + echo "AS_ADMIN_PASSWORD=vagrant" > "${TEMP_PWD_FILE}" + "${PAYARA_HOME}/payara41/bin/asadmin" --host localhost --port 4848 --user admin --passwordfile="${TEMP_PWD_FILE}" enable-secure-admin || exit 255 + rm -f "${TEMP_PWD_FILE}" + + # Restart default domain case "${PAYARA_VERSION}" in 4.1.2.181) - su - vagrant -c 'service payara start payaradomain' + sudo /etc/init.d/payara stop || exit 255 + sudo /etc/init.d/payara start ;; /*) echo "Unknown Payara version, attempting to start domain1..." - su - vagrant -c 'service payara start domain1' + sudo /etc/init.d/payara stop || exit 255 + sudo /etc/init.d/payara start esac } -- 2.39.5