Vagrant Debian support (and experimental CentOS)

This changes the Vagrant setup to support multiple installations as multiple
boxes. In addition to Ubuntu Vagrant can now be used to install on Debian
as well as on CentOS.

I took the chance to clean up the .deb install a bit and backported analyzer
and celery to SysV proper so it runs there. Some of the distro specfics were
moved to the install script from the python setup scripts to acheive this.

For the CentOS support I added a rather involved OS prepare script. In the
long term this will be added to the preparing-the-server docs we already have.

I had to switch the default port to http-alt (8080). On CentOS 9080 is registered
for ocsp and getting it to work for apache without hacking SELinux is hard. I
think 8080 is the RFC way to go anyhow. If anyone want to override this it
should be rather easy using the --web-port arg and by hacking Vagrantfile.

The PyOpenSSL code has been refactored for all the distros that the Vagrantfile
now supports.

As far as my checks go, I tried this code with all the distros, uploaded a track
and downloaded a unicode and a ssl podcast and was able to listen to them
in each case.

In the experimental CentOS case, the UI is not up to spec since services
need to get scheduled through systemctl and the status overview (ie. on the /?config page)
do not work properly. They need to be as follows:

```
sudo systemctl start airtime-playout
sudo systemctl start airtime-liquidsoap
sudo systemctl start airtime_analyzer.service
sudo systemctl start airtime-celery.service
```
This commit is contained in:
Lucas Bickel 2017-03-08 12:39:59 +01:00
parent c8b4d40eb2
commit c29285ae48
19 changed files with 448 additions and 201 deletions

122
install
View file

@ -1,4 +1,5 @@
#!/bin/bash -e
#-e Causes bash script to exit if any of the installers
#return with a non-zero return value.
@ -75,6 +76,8 @@ _q=0
upgrade="f"
dist=""
code=""
apache_bin="apache2"
function verbose() {
if [[ ${_v} -eq 1 ]]; then
@ -299,6 +302,9 @@ echo "| |___| || \_\ \ | \/\ ___/| | | | Y Y \ ___/ "
echo "|_______ \__||___ /__| \___ >____| |__|__|_| /\___ >"
echo -e " \/ \/ \/ \/ \/\n"
if [ "$dist" = "centos" ]; then
apache_bin="httpd"
fi
if [ "$ignore_dependencies" = "f" ]; then
set +e
@ -324,7 +330,7 @@ if [ "$ignore_dependencies" = "f" ]; then
fi
set -e
else
checkCommandExists "apache2"
checkCommandExists "${apache_bin}"
checkCommandExists "rabbitmqctl"
checkCommandExists "psql"
if [ "$in_place" = "t" ]; then
@ -338,8 +344,10 @@ eval hash "composer" 2>/dev/null
commandFound=$?
set -e
if [[ ! ${commandFound} -eq 0 ]]; then
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
curl -sS https://getcomposer.org/installer > get-composer.php
php ./get-composer.php --install-dir=/usr/local/bin --filename=composer
rm get-composer.php
PATH="${PATH}:/usr/local/bin"
fi
# Run composer (install PHP dependencies) and create a VERSION file
@ -414,9 +422,13 @@ if [ "$apache" = "t" ]; then
loud "\n-----------------------------------------------------"
loud " * Configuring Apache * "
loud "-----------------------------------------------------"
apache_sitedir="/etc/apache2/sites-available/"
if [ "$dist" = "centos" ]; then
apache_sitedir="/etc/httpd/conf.d/"
fi
set +e
apache2 -v | grep "2\.4" > /dev/null
$apache_bin -v | grep "2\.4" > /dev/null
apacheversion=$?
set -e
@ -432,7 +444,7 @@ if [ "$apache" = "t" ]; then
# install apache, we should overwrite any existing configuration. If we don't do this, doing
# an in-place installation over an old Airtime install (which installs to /usr/share by default)
# will fail
if [ "$upgrade" = "t" -o ! -f /etc/apache2/sites-available/${airtimeconfigfile} ]; then
if [ "$upgrade" = "t" -o ! -f ${apache_sitedir}${airtimeconfigfile} ]; then
verbose "\n * Creating Apache config for Airtime..."
listen_port=""
if [ "$web_port" != "80" ]; then
@ -448,15 +460,19 @@ if [ "$apache" = "t" ]; then
-e "s@WEB_PORT_LISTEN@${listen_port}@g" \
-e "s@WEB_PORT@${web_port}@g" \
-e "s@WEB_ROOT@${web_root}@g" \
${apache_template_file} > /etc/apache2/sites-available/${airtimeconfigfile}
${apache_template_file} > ${apache_sitedir}${airtimeconfigfile}
loudCmd "a2dissite 000-default"
if [ "$dist" != "centos" ]; then
loudCmd "a2dissite 000-default"
fi
# If Airtime was previously installed with apt, the vhost file name is different,
# so we need to specifically disable it.
if [ -f "/etc/apache2/sites-available/${oldconfigfile}" ]; then
loudCmd "a2dissite airtime-vhost"
fi
loudCmd "a2ensite airtime"
if [ "$dist" != "centos" ]; then
loudCmd "a2ensite airtime"
fi
else
verbose "\nApache config for Airtime already exists, skipping"
fi
@ -476,9 +492,15 @@ if [ "$icecast" = "t" ]; then
loud "-----------------------------------------------------"
verbose "\n * Enabling Icecast 2..."
sed -i 's/ENABLE=false/ENABLE=true/g' /etc/default/icecast2
icecast_unit_name="icecast2"
if [ "$dist" != "centos" ]; then
sed -i 's/ENABLE=false/ENABLE=true/g' /etc/default/icecast2
else
icecast_unit_name="icecast"
fi
set +e
loudCmd "service icecast2 start"
# restart in case icecast was already started (like is the case on debian)
loudCmd "service ${icecast_unit_name} restart"
set -e
verbose "...Done"
fi
@ -491,13 +513,17 @@ verbose "\n * Installing necessary python services..."
loudCmd "pip install setuptools --upgrade"
verbose "...Done"
if [[ `lsb_release -rs` == "14.04" ]] # Ubuntu trusty needs a workaround for python version SSL downloads
then
loudCmd "pip install pyOpenSSL cryptography idna certifi --upgrade"
# Ubuntu trusty needs a workaround for python version SSL downloads
# This affects all python installs where python < 2.7.9
use_pyopenssl=""
if [ "$dist" != "debian" ] || [ "$code" = "wheezy" ]; then
use_pyopenssl="t"
fi
if [ "$use_pyopenssl" = "t" ]; then
verbose "\n * Installing pyOpenSSL and ca db for SNI support..."
loudCmd "pip install pyOpenSSL cryptography idna certifi --upgrade"
verbose "...Done"
fi
verbose "\n * Creating /run/airtime..."
mkdir -p /run/airtime
@ -519,11 +545,29 @@ verbose "...Done"
verbose "\n * Installing airtime-celery..."
loudCmd "python ${AIRTIMEROOT}/python_apps/airtime-celery/setup.py install"
# Make the airtime log directory group-writable
loudCmd "chmod 775 /var/log/airtime"
# Create the Celery user
if [ "$dist" = "centos" ]; then
loudCmd "id celery || adduser --no-create-home -c 'LibreTime Celery' -r celery || true"
loudCmd "systemctl enable airtime-celery"
else
loudCmd "id celery || adduser --no-create-home --gecos 'LibreTime Celery' --disabled-login --firstuid 1 --lastuid 999 celery"
loudCmd "update-rc.d airtime-celery defaults"
fi
# Add celery to the www-data group
loudCmd "usermod -G ${web_user} -a celery"
if [ "$dist" = "ubuntu" ]; then
loudCmd "initctl reload-configuration"
fi
verbose "...Done"
verbose "\n * Installing airtime_analyzer..."
loudCmd "python ${AIRTIMEROOT}/python_apps/airtime_analyzer/setup.py install --install-scripts=/usr/bin"
loudCmd "initctl reload-configuration"
if [ "$dist" = "ubuntu" ]; then
loudCmd "initctl reload-configuration"
fi
verbose "...Done"
for i in /etc/init/airtime*.template; do
@ -533,20 +577,31 @@ for i in /etc/init/airtime*.template; do
done
set +e
loudCmd "initctl reload-configuration"
if [ "$dist" = "ubuntu" ]; then
loudCmd "initctl reload-configuration"
fi
# airtime-celery only has an init.d startup script
loudCmd "update-rc.d airtime-celery defaults" # Start at bootup, on Debian
if [ "$dist" = "centos" ]; then
loudCmd "systemctl enable airtime-celery"
else
loudCmd "update-rc.d airtime-celery defaults" # Start at bootup, on Debian
fi
# On Ubuntu, we already have the upstart configs, so this is redundant
# and causes multiple processes to spawn on startup
if [ "$dist" != "ubuntu" ]; then
if [ "$dist" = "debian" ]; then
loudCmd "systemctl daemon-reload" #systemd hipsters
loudCmd "update-rc.d airtime-playout defaults" # Start at bootup, on Debian
loudCmd "update-rc.d airtime-liquidsoap defaults" # Start at bootup, on Debian
loudCmd "update-rc.d airtime_analyzer defaults" # Start at bootup, on Debian
fi
if [ "$dist" = "centos" ]; then
loudCmd "systemctl enable airtime-playout"
loudCmd "systemctl enable airtime-liquidsoap"
loudCmd "systemctl enable airtime_analyzer"
fi
set -e
if [ ! -d /var/log/airtime ]; then
@ -571,15 +626,21 @@ chmod -R a+x /var/tmp/airtime
chown -R ${web_user}:${web_user} /var/tmp/airtime/
# PHP Config File for Apache
if [ ! -f "/etc/php5/apache2/conf.d/airtime.ini" ]; then
verbose "\n * Creating Airtime PHP config for Apache..."
cp ${SCRIPT_DIR}/installer/php/airtime.ini /etc/php5/apache2/conf.d/airtime.ini
libretime_phpini="/etc/php5/apache2/conf.d/airtime.ini"
if [ "$dist" = "centos" ]; then
libretime_phpini="/etc/php.d/airtime.ini"
fi
if [ ! -f "${libretime_phpini}" ]; then
verbose "\n * Creating LibreTime PHP config for Apache..."
cp ${SCRIPT_DIR}/installer/php/airtime.ini ${libretime_phpini}
else
verbose "\nAirtime PHP config for Apache already exists, skipping"
fi
# Enable Apache modules
loudCmd "a2enmod rewrite php5"
if [ "$dist" != "centos" ]; then
loudCmd "a2enmod rewrite php5"
fi
loud "\n-----------------------------------------------------"
loud " * Configuring PostgreSQL * "
@ -687,9 +748,18 @@ if [ "$ignore_dependencies" = "f" ]; then
fi
verbose "\n * Reloading apache..."
loudCmd "service apache2 reload 2>/dev/null"
if [ "$dist" != "centos" ]; then
loudCmd "service ${apache_bin} reload 2>/dev/null"
verbose "...Done"
IP=$(ifconfig eth0 2>/dev/null|awk '/inet addr:/ {print $2}'|sed 's/addr://')
IP=$(ifconfig eth0 2>/dev/null|awk '/inet addr:/ {print $2}'|sed 's/addr://')
else
verbose "systemctl restart ${apache_bin} 2>/dev/null"
loudCmd "systemctl restart ${apache_bin} 2>/dev/null"
verbose "...Done"
IP=$(ip -o -4 address show dev eth0 | grep -Po 'inet \K[\d.]+')
fi
echo -e "\n-----------------------------------------------------"
echo " * Basic Setup DONE! * "