Kevin Aartsen Kevin Aartsen - 7 months ago 15
Bash Question

Error after vagrant up

My Vagrantfile is so configured that if I do "vagrant up" it runs a provision script which install all my desired packages. That's exactly what I'm doing but i get an error after doing "vagrant up" (for the first time)
Here's the error:
enter image description here

Here's my provisions.sh code:

#!/usr/bin/env bash

PROJECT="foundation"
PROJECT_LOG="foundation"

MYSQL_PASSWORD="password"

set -o nounset -o errexit -o pipefail -o errtrace

error() {
local sourcefile=$1
local lineno=$2
echo "ERROR at ${sourcefile}:${lineno}; Last logs:"
grep "${PROJECT}" /var/log/syslog | tail -n 20
}

trap 'error "${BASH_SOURCE}" "${LINENO}"' ERR

oe() { "$@" 2>&1 | logger -t "${PROJECT}" > /dev/null; }
ol() { echo "[${PROJECT_LOG}] $@"; }

export DEBIAN_FRONTEND=noninteractive

ol 'Updating repository caches'
oe sudo apt-get -q -y update

ol 'Adding apt repositories'
oe sudo apt-get -q -y install python-software-properties
oe sudo add-apt-repository ppa:ondrej/php5-5.6

ol 'Updating repository caches (second time)'
oe sudo apt-get -q -y update

ol "Installing misc packages"
oe sudo apt-get -q -y install language-pack-nl

ol 'Installing Apache 2'
oe sudo apt-get -q -y install apache2
oe sudo systemctl restart apache2
oe sudo systemctl status apache2

ol "Installing PHP"
oe sudo apt-get -q -y install php5 libapache2-mod-php5 \\
php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick \\
php5-imap php5-mcrypt php5-memcached php5-ming php5-ps \\
php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy \\
php5-xmlrpc php5-xsl php5-xcache

ol 'Installing Sendmail'
oe sudo apt-get -q -y install sendmail

ol 'Restarting Apache 2'
oe sudo systemctl restart apache2
oe sudo systemctl status apache2

ol "Installing MySQL"
oe sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password ${MYSQL_PASSWORD}"
oe sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${MYSQL_PASSWORD}"
oe sudo apt-get -q -y install mysql-server mysql-client
oe sudo systemctl restart mysql
oe sudo systemctl status mysql

Answer

It complains on

==> default: Apr 22 01:06:22 vagrant-ubuntu-wily-64 foundation:  * Starting Apache httpd web server apache2
==> default: Apr 22 01:06:22 vagrant-ubuntu-wily-64 foundation: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message

in your Vagrantfile, make sure to set the hostname as a fully qualified domain, something like

config.vm.hostname = "dev.local"

should make the provisioning happy.

second it does not like the \\ in your php install package

you can put everything in one line and it will work

oe sudo apt-get -q -y install php5 libapache2-mod-php5 php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcached php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-xcache

it comes from the oe method but not sure how to handle it

Comments