From 0350c0b1227167eb53a0139005de591c5cc6d608 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 2 Dec 2010 04:32:06 +0100 Subject: [PATCH] add build script to build virtual machine image for pan.do/ra --- vm/README.txt | 55 ++++++++++++++++++++++++++++++++++++ vm/build.sh | 45 +++++++++++++++++++++++++++++ vm/firstboot.sh | 54 +++++++++++++++++++++++++++++++++++ vm/install.sh | 7 +++++ vm/virtualbox_vm.py | 69 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 230 insertions(+) create mode 100644 vm/README.txt create mode 100755 vm/build.sh create mode 100755 vm/firstboot.sh create mode 100755 vm/install.sh create mode 100644 vm/virtualbox_vm.py diff --git a/vm/README.txt b/vm/README.txt new file mode 100644 index 00000000..98aa01c1 --- /dev/null +++ b/vm/README.txt @@ -0,0 +1,55 @@ +Create virtual disk of pan.do/ra + +== ubuntu-vm-builder setup == + +due to https://bugs.launchpad.net/ubuntu/+source/vm-builder/+bug/676132 +we need to use maverick-proposed repository: + + echo "deb http://archive.ubuntu.com/ubuntu/ maverick-proposed restricted main multiverse universe" > /etc/apt/sources.list.d/ubunt-proposed.list + apt-get update + apt-get -t maverick-proposed install ubuntu-vm-builder + + +due to https://bugs.launchpad.net/vmbuilder/+bug/683614 +building vbox images does not work. install virtualbox_vm.py: + sudo cp virtualbox_vm.py /usr/lib/python2.6/dist-packages/VMBuilder/plugins/virtualbox/vm.py + +(or change vbox to kvm to build kvm image) + +with that installed build image: + + ./build.sh + +this will create a vdi image in pandora/ + +== VirtualBox Usage == +Now you can create a new VirtualBox machine, use vdi image as existing hard disk. +Before starting up you have to adjust some settings: + In System -> Processor enable PAE/NX + In Storage remove disk from SATA Controller + add disk to IDE Controler and enable "Use host I/O cache" + + In Network -> Adpater 1 set to Bridged Adapter with your connected controller + +== Use for development == +Login via ssh or in terminal as pandora with password pandora + +Adjust your bzr configuration with bzr whoami: + bzr whoami "Pando the Panda " + +Pan.do/ra is installed in /srv/pandora and is served with nginx on http://pandora.local + + +== Update == +to get the latest version of pan.do/ra + cd /srv/pandora + bzr pull + cd static/oxjs + bzr pull + +you might have to adjust the database at this point. now restart pandora daemons + + service pandora restart + service pandora-tasks restart + service pandora-encoding restart + diff --git a/vm/build.sh b/vm/build.sh new file mode 100755 index 00000000..8937ce7b --- /dev/null +++ b/vm/build.sh @@ -0,0 +1,45 @@ +#!/bin/sh +base=$(pwd) +sudo vmbuilder vbox ubuntu --suite=maverick \ + --verbose --debug \ + --arch i386 \ + --dest $base/pandora \ + --hostname pandora \ + --swapsize 512 \ + --rootsize 8192 \ + --user pandora \ + --pass pandora \ + --components main,universe,multiverse \ + --ppa j/pandora \ + --ppa gstreamer-developers/ppa \ + --addpkg openssh-server \ + --addpkg acpid \ + --addpkg vim \ + --addpkg wget \ + --addpkg pwgen \ + --addpkg nginx \ + --addpkg rabbitmq-server \ + --addpkg bzr \ + --addpkg git \ + --addpkg subversion \ + --addpkg mercurial \ + --addpkg avahi-daemon \ + --addpkg python-setuptools \ + --addpkg python-pip \ + --addpkg python-virtualenv \ + --addpkg ipython \ + --addpkg python-imaging \ + --addpkg python-dev \ + --addpkg python-imaging \ + --addpkg python-numpy \ + --addpkg python-psycopg2 \ + --addpkg python-simplejson \ + --addpkg python-transmissionrpc \ + --addpkg transmission-daemon \ + --addpkg oxtimeline \ + --addpkg oxframe \ + --addpkg mkvtoolnix \ + --execscript=$base/install.sh \ + --firstboot=$base/firstboot.sh + +#kvm-img convert -O vdi pandora/*.qcow2 pandora.vdi diff --git a/vm/firstboot.sh b/vm/firstboot.sh new file mode 100755 index 00000000..f98eaff4 --- /dev/null +++ b/vm/firstboot.sh @@ -0,0 +1,54 @@ +#!/bin/sh +#ffmpeg +wget http://firefogg.org/nightly/ffmpeg.linux -O /usr/local/bin/ffmpeg +chmod 755 /usr/local/bin/ffmpeg + +wget http://firefogg.org/nightly/ffmpeg2theora.linux -O /usr/local/bin/ffmpeg2theora +chmod 755 /usr/local/bin/ffmpeg2theora + +#postgresql +apt-get -y install postgresql +sudo -u postgres createuser -S -D -R pandora +sudo -u postgres createdb -O pandora pandora + +#do not start systemwide transmission-daemon +/etc/init.d/transmission-daemon stop +sed -i "s/ENABLE_DAEMON=1/ENABLE_DAEMON=0/g" /etc/default/transmission-daemon + +#rabbitmq +RABBITPWD=$(pwgen -n 16 -1) +rabbitmqctl add_user pandora $RABBITPWD +rabbitmqctl add_vhost /pandora +rabbitmqctl set_permissions -p /pandora pandora ".*" ".*" ".*" + +#pandora +cat > /srv/pandora/pandora/local_settings.py << EOF +DATABASE_ENGINE = 'postgresql_psycopg2' +DATABASE_NAME = 'pandora' +DATABASE_USER = 'pandora' + +POSTER_SERVICES=['http://data.0xdb.org/poster/'] + +BROKER_PASSWORD = "$RABBITPWD" + +XACCELREDIRECT = True +EOF + +cd /srv/pandora/pandora +sudo -u pandora python manage.py syncdb --noinput +sudo -u pandora python manage.py loaddata fixtures/0xdb_properties.json +echo "UPDATE django_site SET domain = 'pandora.local', name = 'pandora.local' WHERE 1=1;" | sudo -u pandora python manage.py dbshell + +mkdir /srv/pandora/data +chown -R pandora:pandora /srv/pandora + +cp /srv/pandora/etc/init/* /etc/init/ + +service pandora-encoding start +service pandora-tasks start +service pandora start + +#nginx +sed "s/__PREFIX__/\/srv\/pandora/g" "/srv/pandora/nginx/vhost.in" > "/etc/nginx/sites-available/default" +service nginx restart + diff --git a/vm/install.sh b/vm/install.sh new file mode 100755 index 00000000..7228597f --- /dev/null +++ b/vm/install.sh @@ -0,0 +1,7 @@ +#!/bin/sh +CH="chroot $1" +$CH bzr branch http://code.0x2620.org/pandora /srv/pandora +$CH bzr branch http://code.0x2620.org/oxjs /srv/pandora/static/oxjs +$CH virtualenv /srv/pandora +$CH pip -E /srv/pandora install -r /srv/pandora/requirements.txt + diff --git a/vm/virtualbox_vm.py b/vm/virtualbox_vm.py new file mode 100644 index 00000000..fad5296a --- /dev/null +++ b/vm/virtualbox_vm.py @@ -0,0 +1,69 @@ +# +# Uncomplicated VM Builder +# Copyright (C) 2007-2009 Canonical Ltd. +# +# See AUTHORS for list of contributors +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3, as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import os +import os.path +import stat +import VMBuilder +from VMBuilder import register_hypervisor, Hypervisor +from VMBuilder.disk import vbox_manager_path +import VMBuilder.hypervisor + +class VirtualBox(Hypervisor): + preferred_storage = VMBuilder.hypervisor.STORAGE_DISK_IMAGE + needs_bootloader = True + name = 'VirtualBox' + arg = 'vbox' + + def register_options(self): + group = self.setting_group('VM settings') + group.add_setting('mem', extra_args=['-m'], type='int', default=128, help='Assign MEM megabytes of memory to the guest vm. [default: %default]') + group.add_setting('cpus', type='int', default=1, help='Assign NUM cpus to the guest vm. [default: %default]') + group.add_setting('vbox-disk-format', metavar='FORMAT', default='vdi', help='Desired disk format. Valid options are: vdi vmdk. [default: %default]') + + def convert(self, disks, destdir): + self.imgs = [] + for disk in disks: + img_path = disk.convert(destdir, self.context.get_setting('vbox-disk-format')) + self.imgs.append(img_path) + self.call_hooks('fix_ownership', img_path) + + def deploy(self, destdir): + hostname = self.context.distro.get_setting('hostname') + mac = self.context.get_setting('mac') + ip = self.context.get_setting('ip') + vm_deploy = VMBuilder.util.render_template('virtualbox', + self.context, + 'vm_deploy_script', + { 'os_type' : self.context.distro.__class__.__name__, + 'vm_name' : hostname, + 'vm_disks' : self.imgs, + 'mac' : mac, + 'ip' : ip, + 'memory' : self.context.get_setting('mem'), + 'cpus' : self.context.get_setting('cpus') }) + + script_file = '%s/deploy_%s.sh' % (destdir, hostname) + fp = open(script_file, 'w') + fp.write(vm_deploy) + fp.close() + os.chmod(script_file, stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH) + self.call_hooks('fix_ownership', script_file) + +register_hypervisor(VirtualBox)