|

Vagrant: Ubuntu, Oracle JDK, Payara and MySQL

Here is how to setup a JEE dev box with VirtualBox and Vagrant.

Overview

  • Ubuntu 14.04
  • Oracle JDK 8
  • Payara 4.1
  • MySQL 5.6

Access from host environment:

Scripts

Vagrant file: Provisioned ubuntu/trusty64 with forwarded ports to access Payara and MySQL from the host environment.

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
 config.vm.box = "ubuntu/trusty64"
 config.vm.box_version = "20170505.0.0"
 config.vm.provision :shell, path: "bootstrap/run.sh"
 config.vm.network :forwarded_port, guest:4848, host:14848
 config.vm.network :forwarded_port, guest:3306, host:13306
end

Oracle JDK 8: a fully automated installation script.

echo "Installing Java 8"
sudo apt-get -y install software-properties-common python-software-properties
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
sudo apt-get -y install oracle-java8-installer
sudo apt-get -y install oracle-java8-set-default

Payara 4.1.1: installation script including config for remote access.

PAYARA_DIR="payara41"
INSTALL_DIR="/opt/$PAYARA_DIR"
if [ ! -d "$INSTALL_DIR" ]; then
echo "Installing Payara 4.1.1"
  VERSION=4.1.1.171.1
  ZIP_ARCHIVE="$PAYARA_DIR.zip"
  sudo apt-get -y install unzip
  wget -O "$ZIP_ARCHIVE" http://search.maven.org/remotecontent?filepath=fish/payara/distributions/payara/"$VERSION"/payara-"$VERSION".zip
  unzip ./$ZIP_ARCHIVE
  mv ./$PAYARA_DIR /opt/
  rm ./$ZIP_ARCHIVE
fi

echo "Enabling Secure Admin to access the DAS remotely"
ADMIN_USER=admin
ADMIN_PASSWORD=admin

function create_password_file {
  sudo touch $1
  sudo chown vagrant:vagrant $1
  chmod 777 $1
  echo -e $2 >> $1
}

echo ".. creating tmp file"
TMP_FILE=/opt/tmpfile
create_password_file $TMP_FILE "AS_ADMIN_PASSWORD=\nAS_ADMIN_NEWPASSWORD=$ADMIN_PASSWORD"

echo ".. creating pwd file"
PWD_FILE=/opt/pwdfile
create_password_file $PWD_FILE "AS_ADMIN_PASSWORD=$ADMIN_PASSWORD"

echo ".. restarting domain"
ASADMIN_CMD=$INSTALL_DIR/bin/asadmin

$ASADMIN_CMD start-domain && \
$ASADMIN_CMD --user $ADMIN_USER --passwordfile="$TMP_FILE" change-admin-password && \
$ASADMIN_CMD --user $ADMIN_USER --passwordfile="$PWD_FILE" enable-secure-admin && \
$ASADMIN_CMD restart-domain

echo ".. cleaning up"
rm $TMP_FILE

MySQL 5.6: installation script allowing a remote root access (don’t use in production!).

VERSION=5.6
ADMIN_PWD=root

echo "Installing MySQL 5.6"
sudo debconf-set-selections <<< 'mysql-server-'"$VERSION"' mysql-server/root_password password '"$ADMIN_PWD"''
sudo debconf-set-selections <<< 'mysql-server-'"$VERSION"' mysql-server/root_password_again password '"$ADMIN_PWD"''
sudo apt-get -y install mysql-server-"$VERSION"

echo "Enabling remote access"
for flag in {skip-external-locking,bind-address}
do
  sudo sed -i.bak "s/$flag/#$flag/g" /etc/mysql/my.cnf
done

echo "Restarting mysql service"
sudo service mysql restart

echo "Granting privileges"
mysql -u root -proot -Bse "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';"

Thanks for reading and happy coding.

View the project on GitHub.

Similar Posts