Saturday, November 29, 2008

Setting up a Firewall for Ubuntu

Ubuntu 8.04 has ufw, a built-in tool that is way easier to use than iptables. Setup the default rule to deny everything we don't specifically accept
ufw default deny
Allow anything from local network
ufw allow
Allow access to specific ports, in this case ssh and http
ufw allow 22/tcp
ufw allow 80/tcp
Enable the firewall
ufw enable
Review the rules that were setup
ufw status

Wednesday, November 26, 2008

Fooling around with Joomla: Installation

Operating System: Ubuntu 8.04 Installed LAMP stack with:
apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server
Downloaded joomla with:
Unzip the archive using:
sudo unzip -d /var/www/joomla
Change the owner of the directory and the permissions
sudo chown -R www-data:www-data /var/www/joomla
sudo find /var/www/joomla -type f -exec chmod 644 {} \;
sudo find /var/www/joomla -type d -exec chmod 755 {} \;
Create the database and set permissions:
mysqladmin -u root -p create joomla
mysql -u root -p --database=joomla -e "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON joomla.* TO 'joomlauser'@'localhost' IDENTIFIED BY 'joomlapass'"
mysql -u root -p --database=joomla -e "FLUSH PRIVILEGES"
Access http://servername/joomla/administrator to complete the installation

Friday, November 21, 2008

Simple Periodic Task Scheduling with Grails

Need to run a periodic background task in your grails app? Here's how you can do it with no additional plug-ins. I tried this with Grails version 1.03 but I believe its valid even for older versions. This approach assumes that you need to execute a method in one of your service components periodically. In this example, I need to run the doFoo() method of the FooService every minute with an initial delay of 1 minute. Open the resources.groovy file located in the spring folder inside your conf folder inside the grails-app directory of your project. So if your project is in a directory myproject, you can find it at ~/myproject/grails-app/conf/spring Add or modify the contents of the file to include the following declarations:
beans = {
        targetObject = ref("fooService")
        targetMethod = 'doFoo'
        delay = 60000
        period = 60000
        timerTask = ref('doFooTimerTask')
        scheduledTimerTasks = [ref('doFooScheduledTimerTask')]

The code above uses Grails' Spring DSL to define the necessary beans to implement the needed functionality. The first segment defines a MethodInvokingTimerTaskFactoryBean which sets up the service and the metod to be called. The next segment defines a ScheduledTimerTask which setups the initial delay and the period between calls. The third and last bean initializes the timer factory which is a TimerFactoryBean which is responsible for running each timer task at the specified intervals.