Changing the time zone in Ubuntu

Posted on Monday, January 4th, 2010 under , ,

Ubuntu This one is from the “d’oh” category. As recently I’ve moved to Barcelona and since Bucharest and Barcelona are in different time zones, I wanted to set my system’s time an hour back, in order to display the correct time.

I went the easy way: right clicked on the clock in the upper right, selected “Adjust date and time” and made the modifications. After a few minutes the clock was showing Bucharest’s time and my changes were overwritten. I though I must have imagined setting the clock right in the first place – since I “tasted” Moritz thoroughly – and did it again.

I’ve ignored the clock for a while and, later on, when I looked at it, it was displaying Bucharest’s time again :(

D’oh! Ubuntu queries it’s time servers from time to time and sets the hour according to the information retrieved from these servers. And since my timezone was still set to Europe/Bucharest, on each update my system was receiving the time for that area. I’ve changed the timezone accordingly and everything started working. Magic!

To change the timezone of on you Ubuntu system go to System > Administration > Time and date. Or, if you’re a console freak, just punch in:

sudo dpkg-reconfigure tzdata

in order to set the correct time zone.

Web svn administration on Debian

Posted on Friday, October 30th, 2009 under , ,

When I work alone on some projects, I usually use git for versioning. I have a github account and I throw there my code, for safe keeping, since GitHub’s datacenter is much more reliable than anything I could ever improvise at home. And it’s quite cheap also.

But at work I’ve always used SVN and I also wanted to use it at my current workplace. So I had to install it. Since we’re using Debian and all the components are in the repositories, things went pretty smooth:

sudo apt-get install subversion libapache2-svn 
sudo a2enmod dav
sudo a2enmod dav-svn

And basically that’s it. It works. But since I’m lazy, I wanted a simple way to create repositories, manage the users’ rights and so on. That “svn admin create” stuff just doesn’t cut it for me. Thus I looked over the web in search of a suitable web interface for SVN. And I’ve found one developed by some French guys, called User Friendly SVN. It’s built on Zend Framework, it’s simple, very simple for that matter – just the essentials – but it gets the job done. It really easy to use and easy to install. If you want a SVN management tool, give it a try.

Now I’m looking for a way to tie – as simple as possible – the system user accounts with SVN’s user account. Use password to rule them all :P

WhiteHouse goes Drupal – governments and open source

Posted on Wednesday, October 28th, 2009 under , , ,

DrupalWhitehouse.gov goes Drupal – this was a headline on all technology blogs. This alone is a huge step for Drupal. It has proved itself and the debates like Drupal vs. Joomla or Drupal vs. Wordpress are now over. Buytaert’s followers will just go “yes we can”.

But it’s also a big day for Open Source as a whole since the Whitehouse.gov website runs now on a LAMP solution. And if it’s good enough for the WhiteHouse, then it’s good enough for companies.

Back in the days, Microsoft’s solutions were considered to be the (only) “safe choice” for IT managers to make. Linux servers or open source implementations were considered to be…experimental at best, and that if you want a bullet-proof and reliable infrastructure you should always go with Microsoft. In reality nothing could be further from the truth, as most Microsoft servers I’ve encountered so far were inferior to their Linux/Unix/Macintosh counterparts.

The FUD that Linux and open source are not suitable for big companies or governments has received today a(nother) blow. I consider that this move should be widely imitated by governments in Europe, as it will create jobs here and we won’t spend billions of euros importing software from the US.

MySQL backup script

Posted on Monday, September 28th, 2009 under ,

mysql-logo
What is a bad day? How do you define it? Its very definition varies from person to person and from job to job. For some, a bad day is when they lose the bus or the subway and are late for work.

For others, a bad day is when their hair looks weird or they can’t find a good parking lot. For economists and bankers, a bad day is when…well, everyday, given the current economical climate.

For the average programmer a bad day is when he manages to fuck up something on a epic scale on the production server. Let’s say a database with thousands of users. Today it happened to…well…this friend of mine.

Luckily my friend backups his work on a daily basis and is prepared for such situations. One of the scripts he uses for this is the awesome AutoMySQLBackup script, which I – I mean he recommends to all of you. It’s really simple to use, all you have to do are some minor configurations and add the script to be ran daily as a cron job.

Real men *do* use backups!

Monitor free space on your Linux server

Posted on Tuesday, September 22nd, 2009 under ,

Warning: After consulting with some of my friends, I’ve concluded that Nagios is a much better solution, so this article is now obsolete. Read it only if you don’t want to install Nagios on your server.

Now that I have some server that I need to administer and look after, I’m starting to notice potential issues that until several months ago were just somebody’s else’s problems and I didn’t cared much for them. One of which is to monitor the server’s free space, since it’s better to know when your server’s storage capacity is running low. Saves me some money on the headache pills. Well, knowing a scripting language like python comes in handy in times like these, because it helped me to put together a simple script that warns me whenever one or more hard-drives are over 85% full.

Here it is:

#!/usr/bin/python
import commands
WARNING_PERCENTAGE = 85
 
def main():
    global WARNING_PERCENTAGE
    warnings = []
    status, output = commands.getstatusoutput( """df -k | awk '{if ($6 !~ /cdrom/ && NR != 1) print $1 " " ($5 + 0) }'""" )
    for line in output.splitlines():
        hdd, used = line.split( ' ' )
        if int( used ) >= WARNING_PERCENTAGE:
            warnings.append( line )
    if len( warnings ) is not 0:
        send_warning( warnings )
 
def send_warning( warnings ):
    # here you should send e-mails, smses and so on
    print warnings
 
if __name__ == '__main__':
    main()

Since it uses df and awk, it’s obvious that it won’t run on Windows. But who need Windows anyway…

PS: do I have to mention that this script should be ran as a cron job?

ALERT – configured POST variable limit exceeded

Posted on Tuesday, September 15th, 2009 under ,

ALERT – configured POST variable limit exceeded…this error kept poping in my server’s logs all morning, and – what a strange coincidence – an application stopped working in that exact time frame :)

Well, upon investigation, this exception is thrown by suhosin when a client application sends too many variables to the server. In my case, via HTTP POST.

The solution is simple, just increase the maximum number of allowed variables in php.ini. If you don’t have a suhosin section, just create one. Like such:

[suhosin]
suhosin.request.max_vars = 1000
suhosin.post.max_vars = 1000

Advertising blog entries on Pidgin’s status

Posted on Friday, August 21st, 2009 under , , ,

I wanted to write this post ever since I’ve read Radu’s Fortune and Pidgin’s status on Ubuntu post. Radu’s approach is quite lame and hard to use, because it relies on the user exporting a SQL dump file every time he posts something on the blog.

And really, do you need *all* the posts in the database? Do you really want to advertise blog entries from 2 years ago? Come on!

My idea is much better…obviously :P …and it goes like this: parse the blog’s RSS and take “inspiration” from there for the statuses. The weapon of choice for this task is python with its feedparser library.

First, some prerequisites:

sudo apt-get install python-feedparser

…and then, the python script:

#!/usr/bin/python
import feedparser
import random
import os
 
# feed url
FEED = 'http://feeds2.feedburner.com/motanelu'
 
feed = feedparser.parse( FEED )
index = random.randrange(0, len( feed['items'] ) - 1 )
status = 'purple-remote "setstatus?status=available&message=%s %s"' % ( feed['items'][index].title, feed['items'][index].link )
os.system( status )
 
# EOF

I consider this approach better than Radu’s, because it doesn’t require exporting the database or messing around with fortune. Read this post to see how to update Pidgin’s status using cron. And enjoy :P

Limit a script’s execution time

Posted on Monday, July 13th, 2009 under ,

Sometimes you might want to limit a script’s maximum execution time, so that if it’s not done in X seconds, you’ll discard any results you’ve got so far and move on. And if you’re lazy and don’t want to implement threading and semaphores and so on, or you just need a quick way to achieve this limitation and you’re okay with killing the script after a certain number of seconds – note that you will lose any unsaved data when you kill the program – then this Perl one liner might just do the trick for you:

perl -e '$s = shift; $SIG{ALRM} = sub { print STDERR "Timeout!\n"; kill INT => $p }; exec(@ARGV) unless $p = fork; alarm $s; waitpid $p, 0' {max. execution time in seconds} {/path/to/script}

Don’t try to read it…just go with it ;) It works and that all that matters.

Pywebkitgtk under Debian Lenny

Posted on Wednesday, July 8th, 2009 under , ,

If you’ve read the previous post, you know that I consider using python with Webkit and Qt a much better solution than using GTK, so that’s what I recommend. But if you want to give it a try with GTK and need to install pywebkitgtk under Debian Lenny, this is what you need to do:

  1. Open /etc/apt/sources.list and append the following lines to the file.

    # Unstable Sid
    deb http://http.us.debian.org/debian/ unstable main contrib non-free 
    # Unstable Sources
    deb-src http://http.us.debian.org/debian/ unstable main contrib non-free
  2. Run apt-get update in the shell, so that apt will become aware of the changes in the sources.list file
  3. Run apt-get install pywebkitgtk

Note that you have to be logged in as root or be able to sudo.

Pidgin, Ubuntu and Yahoo! Messenger

Posted on Wednesday, June 24th, 2009 under , , ,

Pidgin Starting yesterday, my Pidgin stopped connecting to Yahoo!’s messenger service (MSN kept working). Being lazy, I’ve just changed the scs.msg.yahoo.com host to 66.163.181.166 in the user profile panel – the first solution I’ve came across on Google – and it started working again. For another day or so.

But today, it stopped working again and I couldn’t get it working again. So I’ve used Meebo to go online and ask others if their YM! clients worked, if they’ve also encountered this problem, and, most important, what did they do to fix it. And – thanks to Radu – I’ve found out the root of this problem: Yahoo! changed the specifications of its im protocol. Fortunately, the Pidgin guys don’t waste time and the problem can be solved by upgrading to Pidgin 2.5.7.

Details here and here.