Created
February 25, 2016 10:45
-
-
Save soderlind/b16297d27fd4cd42fdad to your computer and use it in GitHub Desktop.
Adding Gearman to VVV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# #!/bin/bash | |
# # | |
# # provision-post.sh (save the file in VVV/provision) | |
# # | |
# # Adding Gearman to VVV | |
# # | |
# # This file is specified in Vagrantfile and is loaded by Vagrant _after_ the primary | |
# # provisioning script whenever the commands `vagrant up`, `vagrant provision`, | |
# # or `vagrant reload` are used. | |
echo "Adding Gearman" | |
# Network Detection | |
# | |
# Make an HTTP request to google.com to determine if outside access is available | |
# to us. If 3 attempts with a timeout of 5 seconds are not successful, then we'll | |
# skip a few things further in provisioning rather than create a bunch of errors. | |
if [[ "$(wget --tries=3 --timeout=5 --spider http://google.com 2>&1 | grep 'connected')" ]]; then | |
echo "Network connection detected..." | |
ping_result="Connected" | |
else | |
echo "Network connection not detected. Unable to reach google.com..." | |
ping_result="Not Connected" | |
fi | |
# # | |
# # Gearman packages | |
# # | |
apt_package_install_list=() | |
apt_package_check_list=( | |
gearman | |
python-pip | |
libgearman-dev | |
supervisor | |
) | |
echo "Check for apt packages to install..." | |
# # Loop through each of our packages that should be installed on the system. If | |
# # not yet installed, it should be added to the array of packages to install. | |
for pkg in "${apt_package_check_list[@]}"; do | |
package_version="$(dpkg -s $pkg 2>&1 | grep 'Version:' | cut -d " " -f 2)" | |
if [[ -n "${package_version}" ]]; then | |
space_count="$(expr 20 - "${#pkg}")" #11 | |
pack_space_count="$(expr 30 - "${#package_version}")" | |
real_space="$(expr ${space_count} + ${pack_space_count} + ${#package_version})" | |
printf " * $pkg %${real_space}.${#package_version}s ${package_version}\n" | |
else | |
echo " *" $pkg [not installed] | |
apt_package_install_list+=($pkg) | |
fi | |
done | |
if [[ $ping_result == "Connected" ]]; then | |
# If there are any packages to be installed in the apt_package_list array, | |
# then we'll run `apt-get update` and then `apt-get install` to proceed. | |
if [[ ${#apt_package_install_list[@]} = 0 ]]; then | |
echo -e "No apt packages to install.\n" | |
else | |
# update all of the package references before installing anything | |
echo "Running apt-get update..." | |
apt-get update --assume-yes | |
# install required packages | |
echo "Installing apt-get packages..." | |
apt-get install --assume-yes ${apt_package_install_list[@]} | |
# Clean up apt caches | |
apt-get clean | |
fi | |
# # | |
# # Gearman | |
# # | |
echo "PECL install Gearman" | |
pecl install gearman | |
echo "Add Gearman PHP extention" | |
echo "extension=gearman.so" > /etc/php5/fpm/conf.d/gearman.ini | |
echo "extension=gearman.so" > /etc/php5/cli/conf.d/gearman.ini | |
echo "Add Gearman Startup scripts" | |
update-rc.d gearman-job-server defaults && update-rc.d supervisor defaults | |
echo "Restart gearman and supervisor deamons" | |
service gearman-job-server restart && service supervisor restart | |
else | |
echo -e "\nNo network connection available, skipping package installation" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment