2011-11-09 22:26:23 +01:00
|
|
|
#Airtime install/upgrade infrastructure
|
|
|
|
#author martin.konecny@sourcefabric.org
|
|
|
|
|
|
|
|
#Documentation for this page:
|
|
|
|
#http://wiki.sourcefabric.org/x/OwCD
|
|
|
|
|
|
|
|
|
2011-10-06 01:01:36 +02:00
|
|
|
import os
|
|
|
|
import time
|
2011-11-09 22:26:23 +01:00
|
|
|
import sys
|
2011-10-06 01:01:36 +02:00
|
|
|
from fabric.api import *
|
|
|
|
from fabric.contrib.files import comment, sed, append
|
|
|
|
|
2011-11-09 22:26:23 +01:00
|
|
|
from xml.dom.minidom import parse
|
|
|
|
from xml.dom.minidom import Node
|
|
|
|
from xml.dom.minidom import Element
|
|
|
|
|
2011-10-06 01:01:36 +02:00
|
|
|
env.user = 'martin'
|
2011-10-11 16:16:38 +02:00
|
|
|
env.password = 'test'
|
2011-10-06 23:54:45 +02:00
|
|
|
env.hosts = []
|
|
|
|
env.host_string
|
2011-10-06 01:01:36 +02:00
|
|
|
|
2011-10-09 19:38:36 +02:00
|
|
|
env.vm_download_url = "http://host.sourcefabric.org/vms/VirtualBox"
|
|
|
|
|
|
|
|
#fab -f fab_setup.py ubuntu_lucid_64 airtime_182_tar airtime_190_tar
|
2011-10-06 01:01:36 +02:00
|
|
|
|
|
|
|
|
2011-11-09 23:31:59 +01:00
|
|
|
def shutdown():
|
|
|
|
sudo("shutdown -hP now")
|
|
|
|
time.sleep(30)
|
|
|
|
|
2011-10-06 01:01:36 +02:00
|
|
|
def test():
|
|
|
|
x = sudo('airtime-check-system')
|
|
|
|
print x.failed
|
|
|
|
print x.succeeded
|
|
|
|
print x.return_code
|
2011-10-09 19:38:36 +02:00
|
|
|
|
2011-10-11 17:49:35 +02:00
|
|
|
def download_if_needed(vdi_dir, xml_dir, vm_name, vm_vdi_file, vm_xml_file):
|
2011-10-11 16:16:38 +02:00
|
|
|
if not os.path.exists(vdi_dir):
|
|
|
|
os.makedirs(vdi_dir)
|
2011-10-09 19:38:36 +02:00
|
|
|
|
2011-10-11 16:16:38 +02:00
|
|
|
if os.path.exists(os.path.join(vdi_dir, vm_vdi_file)):
|
|
|
|
print "File %s already exists. No need to re-download" % os.path.join(vdi_dir, vm_vdi_file)
|
2011-10-09 19:38:36 +02:00
|
|
|
else:
|
|
|
|
print "File %s not found. Downloading" % vm_vdi_file
|
2011-10-11 16:16:38 +02:00
|
|
|
local("wget %s/%s/%s -O %s"%(env.vm_download_url, vm_name, vm_vdi_file, os.path.join(vdi_dir, vm_vdi_file)))
|
2011-10-11 17:49:35 +02:00
|
|
|
|
2011-11-10 18:28:38 +01:00
|
|
|
local("rm -f %s"%os.path.join(xml_dir, vm_xml_file))
|
|
|
|
local("wget %s/%s/%s -O %s"%(env.vm_download_url, vm_name, vm_xml_file, os.path.join(xml_dir, vm_xml_file)))
|
|
|
|
|
2011-10-06 01:01:36 +02:00
|
|
|
|
2011-11-10 18:45:04 +01:00
|
|
|
def create_fresh_os(vm_name, update_virtualenv=False, debian=False):
|
2011-10-09 19:38:36 +02:00
|
|
|
|
2011-11-10 00:21:44 +01:00
|
|
|
vm_vdi_file = '%s.vdi'%vm_name
|
|
|
|
vm_xml_file = '%s.xml'%vm_name
|
2011-10-11 16:16:38 +02:00
|
|
|
vdi_dir = os.path.expanduser('~/tmp/vms/%s'%vm_name)
|
|
|
|
vdi_snapshot_dir = os.path.expanduser('~/tmp/vms/%s/Snapshots'%vm_name)
|
|
|
|
xml_dir = os.path.expanduser('~/.VirtualBox')
|
2011-11-09 22:26:23 +01:00
|
|
|
vm_xml_path = os.path.join(xml_dir, vm_xml_file)
|
2011-10-09 19:38:36 +02:00
|
|
|
|
2011-11-10 18:28:38 +01:00
|
|
|
"""
|
2011-11-09 22:26:23 +01:00
|
|
|
if not os.path.exists("%s/vm_registered"%vdi_dir) and os.path.exists(vm_xml_path):
|
|
|
|
#vm_xml file exists, but it wasn't registered. Did something go wrong on a previous attempt?
|
|
|
|
#Let's attempt to correct this by completely removing the virtual machine.
|
|
|
|
|
|
|
|
dom = parse(vm_xml_path)
|
|
|
|
root = dom.childNodes[0]
|
|
|
|
rootChildren = root.childNodes
|
|
|
|
|
|
|
|
#manually remove all snapshots before removing virtual machine
|
|
|
|
for rc in rootChildren:
|
|
|
|
if rc.nodeType == Node.ELEMENT_NODE and rc.localName == "Machine":
|
|
|
|
snapshotNodes = rc.getElementsByTagName("Snapshot")
|
|
|
|
for sn in snapshotNodes:
|
|
|
|
local("VBoxManage snapshot %s delete %s"% (vm_name, sn.getAttribute("uuid")[1:-1]))
|
|
|
|
|
|
|
|
os.remove(vm_xml_path)
|
|
|
|
local("VBoxManage unregistervm %s --delete"% vm_name)
|
2011-11-10 18:28:38 +01:00
|
|
|
"""
|
2011-11-09 22:26:23 +01:00
|
|
|
|
|
|
|
download_if_needed(vdi_dir, xml_dir, vm_name, vm_vdi_file, vm_xml_file)
|
|
|
|
|
|
|
|
if not os.path.exists("%s/vm_registered"%vdi_dir):
|
2011-10-11 16:16:38 +02:00
|
|
|
local("VBoxManage registervm %s"%os.path.join(xml_dir, vm_xml_file), capture=True)
|
|
|
|
local('VBoxManage storagectl "%s" --name "SATA Controller" --add sata'%vm_name)
|
2011-11-09 22:26:23 +01:00
|
|
|
local('VBoxManage storageattach "%s" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium %s'%(vm_name, os.path.join(vdi_dir, vm_vdi_file)))
|
2011-10-11 16:16:38 +02:00
|
|
|
local("VBoxManage modifyvm %s --snapshotfolder %s"%(vm_name, vdi_snapshot_dir))
|
2011-11-09 22:26:23 +01:00
|
|
|
local("VBoxManage snapshot %s take fresh_install"%vm_name)
|
|
|
|
local("touch %s/vm_registered"%vdi_dir)
|
|
|
|
|
|
|
|
|
|
|
|
local('VBoxManage snapshot %s restore fresh_install'%vm_name)
|
2011-10-09 19:38:36 +02:00
|
|
|
local('VBoxManage startvm %s'%vm_name)
|
2011-11-09 22:26:23 +01:00
|
|
|
print "Please wait while attempting to acquire IP address"
|
2011-10-06 01:01:36 +02:00
|
|
|
|
2011-11-10 18:28:38 +01:00
|
|
|
time.sleep(15)
|
2011-11-09 23:50:51 +01:00
|
|
|
|
|
|
|
try_again = True
|
|
|
|
while try_again:
|
|
|
|
ret = local('VBoxManage --nologo guestproperty get "%s" /VirtualBox/GuestInfo/Net/0/V4/IP'%vm_name, capture=True)
|
|
|
|
triple = ret.partition(':')
|
|
|
|
ip_addr = triple[2].strip(' \r\n')
|
|
|
|
print "Address found %s"%ip_addr
|
|
|
|
|
|
|
|
try_again = (len(ip_addr) == 0)
|
2011-11-10 18:28:38 +01:00
|
|
|
time.sleep(1)
|
2011-11-09 23:50:51 +01:00
|
|
|
|
2011-10-06 23:54:45 +02:00
|
|
|
env.hosts.append(ip_addr)
|
|
|
|
env.host_string = ip_addr
|
2011-11-09 22:26:23 +01:00
|
|
|
|
2011-11-10 00:21:44 +01:00
|
|
|
if update_virtualenv:
|
2011-11-09 22:26:23 +01:00
|
|
|
print "Lucid detected - updating python virtualenv"
|
|
|
|
sudo('apt-get update')
|
|
|
|
sudo('apt-get install -y python-setuptools')
|
|
|
|
sudo('wget http://apt.sourcefabric.org/pool/main/p/python-virtualenv/python-virtualenv_1.4.9-3_all.deb')
|
2011-11-10 00:21:44 +01:00
|
|
|
|
2011-11-09 22:26:23 +01:00
|
|
|
sudo('dpkg -i python-virtualenv_1.4.9-3_all.deb')
|
2011-11-10 18:45:04 +01:00
|
|
|
|
|
|
|
if debian:
|
|
|
|
append('/etc/apt/sources.list', "deb http://www.debian-multimedia.org squeeze main non-free", use_sudo=True)
|
2011-10-06 01:01:36 +02:00
|
|
|
|
2011-10-09 19:38:36 +02:00
|
|
|
def ubuntu_lucid_32(fresh_os=True):
|
|
|
|
if (fresh_os):
|
2011-11-10 00:21:44 +01:00
|
|
|
create_fresh_os('Ubuntu_10.04_32', update_virtualenv=True)
|
2011-10-09 19:38:36 +02:00
|
|
|
|
|
|
|
def ubuntu_lucid_64(fresh_os=True):
|
2011-10-11 16:16:38 +02:00
|
|
|
if (fresh_os):
|
2011-11-10 00:21:44 +01:00
|
|
|
create_fresh_os('Ubuntu_10.04_64', update_virtualenv=True)
|
2011-10-09 19:38:36 +02:00
|
|
|
|
|
|
|
def ubuntu_natty_32(fresh_os=True):
|
2011-10-11 16:16:38 +02:00
|
|
|
if (fresh_os):
|
2011-11-10 00:21:44 +01:00
|
|
|
create_fresh_os('Ubuntu_11.04_32')
|
2011-10-09 19:38:36 +02:00
|
|
|
|
|
|
|
def ubuntu_natty_64(fresh_os=True):
|
2011-10-11 16:16:38 +02:00
|
|
|
if (fresh_os):
|
2011-11-10 00:21:44 +01:00
|
|
|
create_fresh_os('Ubuntu_11.04_64')
|
|
|
|
|
|
|
|
def debian_squeeze_32(fresh_os=True):
|
|
|
|
if (fresh_os):
|
2011-11-10 18:45:04 +01:00
|
|
|
create_fresh_os('Debian_Squeeze_32', debian=True)
|
2011-11-10 00:21:44 +01:00
|
|
|
|
|
|
|
def debian_squeeze_64(fresh_os=True):
|
|
|
|
if (fresh_os):
|
2011-11-10 18:45:04 +01:00
|
|
|
create_fresh_os('Debian_Squeeze_64', debian=True)
|
2011-11-10 00:21:44 +01:00
|
|
|
|
2011-10-11 16:16:38 +02:00
|
|
|
def airtime_182_tar():
|
2011-10-06 01:01:36 +02:00
|
|
|
sudo('apt-get update')
|
|
|
|
sudo('apt-get install -y tar gzip unzip apache2 php5-pgsql libapache2-mod-php5 ' + \
|
|
|
|
'php-pear php5-gd postgresql odbc-postgresql python python-configobj poc-streamer ' + \
|
|
|
|
'lame daemontools daemontools-run python-mutagen libsoundtouch-ocaml sudo ' + \
|
|
|
|
'libtaglib-ocaml libao-ocaml libmad-ocaml libesd0 icecast2 oggvideotools ' + \
|
|
|
|
'libportaudio2 libsamplerate0 libcamomile-ocaml-dev ecasound php5-curl mpg123 ' + \
|
|
|
|
'python-setuptools python-pip rabbitmq-server libvorbis-ocaml-dev libmp3lame-dev flac')
|
|
|
|
|
|
|
|
sudo('pip install kombu')
|
|
|
|
sudo('pip install poster')
|
|
|
|
|
|
|
|
sudo('mkdir -p /tmp/pear/cache')
|
|
|
|
sudo('pear channel-discover pear.phing.info || true')
|
2011-10-06 23:54:45 +02:00
|
|
|
sudo('pear install phing/phing-2.4.2 || true')
|
2011-10-06 01:01:36 +02:00
|
|
|
|
|
|
|
sudo('ln -sf /etc/apache2/mods-available/php5.* /etc/apache2/mods-enabled')
|
|
|
|
sudo('ln -sf /etc/apache2/mods-available/rewrite.* /etc/apache2/mods-enabled')
|
|
|
|
|
2011-10-11 16:16:38 +02:00
|
|
|
sed('/etc/php5/apache2/php.ini', ";upload_vdi_dir =", "upload_vdi_dir = /tmp", use_sudo=True)
|
2011-10-06 01:01:36 +02:00
|
|
|
sed('/etc/php5/apache2/php.ini', ";date.timezone =", 'date.timezone = "America/Toronto"', use_sudo=True)
|
|
|
|
|
|
|
|
put('airtime.vhost', '/etc/apache2/sites-available/airtime', use_sudo=True)
|
|
|
|
sudo('a2dissite default')
|
|
|
|
sudo('ln -sf /etc/apache2/sites-available/airtime /etc/apache2/sites-enabled/airtime')
|
|
|
|
sudo('a2enmod rewrite')
|
|
|
|
sudo('service apache2 restart')
|
|
|
|
|
|
|
|
sed('/etc/default/icecast2', 'ENABLE=false', 'ENABLE=true', use_sudo=True)
|
|
|
|
sudo('service icecast2 start')
|
|
|
|
|
|
|
|
run('wget http://downloads.sourceforge.net/project/airtime/1.8.2/airtime-1.8.2.tar.gz')
|
|
|
|
run('tar xfz airtime-1.8.2.tar.gz')
|
|
|
|
sudo('cd ~/airtime-1.8.2/install && php airtime-install.php')
|
|
|
|
|
2011-11-09 22:26:23 +01:00
|
|
|
#need to reboot because of daemon-tools.
|
2011-10-06 01:01:36 +02:00
|
|
|
reboot(45)
|
|
|
|
sudo('airtime-check-system')
|
2011-10-11 16:16:38 +02:00
|
|
|
|
2011-10-14 14:26:10 +02:00
|
|
|
def airtime_194_tar():
|
2011-11-10 00:08:00 +01:00
|
|
|
#1.9.4 doesn't do apt-get update during install, and therefore the package index
|
|
|
|
#files are not resynchronized. Need to do this here.
|
|
|
|
sudo('apt-get update')
|
|
|
|
|
2011-10-14 14:26:10 +02:00
|
|
|
run('wget http://downloads.sourceforge.net/project/airtime/1.9.4/airtime-1.9.4.tar.gz')
|
|
|
|
run('tar xfz airtime-1.9.4.tar.gz')
|
2011-11-10 18:28:38 +01:00
|
|
|
sudo('cd /home/martin/airtime-1.9.4/install_full/ubuntu && ./airtime-full-install')
|
2011-11-09 16:21:17 +01:00
|
|
|
|
2011-11-09 22:26:23 +01:00
|
|
|
def airtime_195_tar():
|
2011-11-09 23:31:59 +01:00
|
|
|
run('wget http://downloads.sourceforge.net/project/airtime/1.9.5-RC4/airtime-1.9.5-RC4.tar.gz')
|
|
|
|
run('tar xfz airtime-1.9.5-RC4.tar.gz')
|
2011-11-10 18:28:38 +01:00
|
|
|
sudo('cd /home/martin/airtime-1.9.5/install_full/ubuntu && ./airtime-full-install')
|
2011-10-14 14:26:10 +02:00
|
|
|
|
|
|
|
def airtime_latest_deb():
|
2011-10-11 16:16:38 +02:00
|
|
|
append('/etc/apt/sources.list', "deb http://apt.sourcefabric.org/ lucid main", use_sudo=True)
|
|
|
|
append('/etc/apt/sources.list', "deb http://archive.ubuntu.com/ubuntu/ lucid multiverse", use_sudo=True)
|
|
|
|
sudo('apt-get update')
|
|
|
|
sudo('apt-get install -y --force-yes sourcefabric-keyring')
|
|
|
|
sudo('apt-get install -y postgresql')
|
|
|
|
sudo('apt-get install -y icecast2')
|
|
|
|
sudo('apt-get purge -y pulseaudio')
|
|
|
|
sudo('apt-get install -y --force-yes airtime')
|
2011-10-11 17:49:35 +02:00
|
|
|
|
2011-11-09 22:26:23 +01:00
|
|
|
def airtime_git_branch(branch="devel"):
|
2011-10-11 17:49:35 +02:00
|
|
|
sudo('apt-get update')
|
|
|
|
sudo('apt-get install -y git-core')
|
|
|
|
run('git clone https://github.com/sourcefabric/Airtime.git ~/airtime')
|
2011-11-10 18:28:38 +01:00
|
|
|
sudo('cd /home/martin/airtime && git checkout %s && install_full/ubuntu/airtime-full-install || true' % branch)
|
2011-10-06 01:01:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
def airtime_200():
|
|
|
|
pass
|