Vhost per tutti con i template per Apache

by Giovanni on April 26th, 2009

Tutti i server di Mikamai usano Ubuntu Linux come distribuzione. Una delle cose migliori è il layout delle directory di Apache, in particolare il modo in cui si abilitano e disabilitano i Virtual Host.

Nonostante la loro semplicità, la creazione dei nuovi vhost è un lavoro tedioso, che abbiamo risolto (alfine!) con uno script ruby molto semplice (è richiesta la gemma optiflag):

#!/usr/bin/env ruby
 
require 'rubygems'
require 'optiflag'
 
module MyOptions extend OptiFlagSet
  flag "d" do
    description "The domain name the vhost should serve"
    long_form "domain"
  end
 
  optional_flag "a" do
    description "Email of the admin. If not specified defaults to info@domain"
    long_form "admin"
  end
 
  optional_switch_flag "w" do
    description "Adds www to non www redirection"
    long_form "www_redirect"
  end
 
  and_process!
end
 
flags = MyOptions.flags
 
admin = flags.a ? flags.a : "info@#{flags.d}"
domain = flags.d
quoted_domain = flags.d.gsub(/\./, "\\.")
 
TEMPLATE=<<-EOT
<VirtualHost *:80>
        ServerName #{domain}
        ServerAdmin #{admin} 
 
        DocumentRoot /var/apps/#{domain}
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/apps/#{domain}>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All 
                Order allow,deny
                allow from all
        </Directory>
 
        ErrorLog /var/log/apache2/#{domain}.log
 
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
 
        CustomLog /var/log/apache2/#{domain}.log combined
 
</VirtualHost>
EOT
 
REDIRECTION=<<-EOT
<VirtualHost *:80>
  ServerName www.#{domain}
  ServerAdmin #{admin} 
 
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^www\\.#{quoted_domain}
  RewriteRule (.*) http://#{domain}/$1 [R=301,L]
</VirtualHost>
EOT
 
puts TEMPLATE
puts REDIRECTION if flags.w?

Lo usiamo in questo modo:

$ vhgen -d domain.com -w > /etc/apache2/sites-available/my_vhost
$ a2ensite my_vhost
No Comments »

Ruby Social Club Milano – 16 Apr 2009

by Ivan Vaghi on April 15th, 2009

ruby social club and the ruby mine

English

The Italian Rubyists are once again meeting up for a Ruby Social Club evening in Milano on Thursday 16th of April (i.e.: tomorrow :-). All information is available as usual on TheRubyMine. Be there, bring friends, let’s socialize and… RSVP.

Italian

I Rubyisti italiani ancora una volta si trovano per il Ruby Social Club giovedì sera (domani!!!) 16 Aprile. Tutte le info sono -al solito- su TheRubyMine.  Portate voi stessi, amici, snack vari e soprattutto… RSVP.

2 Comments »

Connect to the internet of things with Pachubero, a Pachube wrapper for Ruby

by Ivan Vaghi on January 16th, 2009

pachubepic

Here at MIKAMAI we have been playing a lot with Arduino recently.

It’s all Massimo‘s fault, really :-)

My good friend Massimo has been giving us boards and books and we have been participating and helped organizing events such as the Hack-Up and the DorkBot Milano, where we played a  lot with both Arduino and Ruby.

The next logical step was to have Arduino boards talking to each other via the internet over some kind of ruby-based routing system.  Massimo pointed out an existing system, Pachube – which people in the know pronounce pach-be, but sound much cooler as pa-chu-be.

Pachube is a platform where people can register different kinds of sensors from all over the world.  You can ask for an API Key to receive semi-realtime feeds coming from any of the sensors.  The potential for artists and interaction designers is simply amazing.

A couple of weeks ago I was in London and I met the author, Usman Haque.  Besides being an all-around cool guy with whom I share many interests, Usman infected me with the pachube virus.  You can have a lamp lightning up in Milano when your loved one gets home in London, you can monitor your energy consumption or you can get your plant to twitter you when it’s running out of water.

As I left his place I took out the laptop and I started coding from the bus.. We put together Pachubero, a very very simple ruby library to connect to Pachube and request data from the feeds.

You can get Pachubero from GitHub.

First of all you must have a pachube key.  If you don’t, you can set the key variable to :mock to use fake example data.  If you don’t have a key, write us for an invitation. I have a few of them still left.

require 'pachubero'
 
PACHUBE_KEY = :mock
 
pachube = Pachube.new PACHUBE_KEY

you can then iterate through the feeds and get their titles

[1202, 1203].each do |n|
 
  puts pachube.feed(n).title
 
end

you can also get the info of a specific feed

f = pachube.feed(1202) 
 
puts f.id
 
puts f.title
 
puts f.status
 
puts f.description

and get all the data out of it

f.data do |tag, v, min, max|
 
  puts '-----'
 
  puts tag
 
  puts v
 
  puts min
 
  puts max
 
end

data can change in time, so you can keep polling while refreshing the feed. Pachube is not allowing a refresh rate greater than 5 seconds for the time being.

6.times do
 
  f.refresh
 
  f.value[0]
 
  sleep 10
 
end

Have fun with Pachube and Pachubero and let us know how you are using it.

4 Comments »

Stats for Radiant Newsletter

by Andrea Franz on May 6th, 2008

Some weeks ago Casper Fabricius sent me a patch for the Radiant Newsletter extension.  He added a statistics system to track how many times sent emails are opened. I have finally found the time to apply it and commit it to the repository. Thank you very very much for your work Casper! I’ll write an article about this extension as soon as possible.

Comments Off