Category Archives: Linux

Vagrant and Docker provisioner

Well, I am recently playing with Vagrant after playing with Docker, and was trying to use them together (since I am forced to use a Windows machine at work and thought Vagrant would be better than booting up 4 Virtualbox machines together in order to test some crazy application setup my devious mind concocted)…

I read (some of) the documentation and figured it would be better to use docker provisioning (as opposed to provider) to keep things as similar as they were before (after all I was running docker inside a VBoxed Ubuntu). So I tried the example given in the docs, and created the following Vagrantfile, exactly as stated:

Vagrant.configure("2") do |config|
  config.vm.provision "docker" do |d| "rabbitmq"

and was greeted with the following error:

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
There are errors in the configuration of this machine. Please fix
the following errors and try again:

* A box must be specified.

Ok, nothing to write home about, I needed to specify a box. Since I had recently completed the getting started examples, I thought the sensible thing to do would be use the same machine used before, hence I change my Vagrantfile to:

Vagrant.configure("2") do |config| = "hashicorp/precise32"
  config.vm.provision "docker" do |d| "rabbitmq"

Just to be greeted with the following error:

==> default: Running provisioner: docker...
    default: Installing Docker (latest) onto machine...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

apt-get install -y --force-yes -q xz-utils lxc-docker -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold'

Stdout from the command:

Reading package lists...
Building dependency tree...
Reading state information...

Stderr from the command:

stdin: is not a tty
E: Unable to locate package lxc-docker

Well, that’s not good. After some head scratching, I kinda remembered that Docker was not available on the official repos of older Ubuntu versions and tried to replace the box hashicorp/precise32 with the more recent ubuntu/trusty32, just to get the same error on the my screen.

After a lot of cursing and reading sites about Docker and Vagrantfile, I went to the Docker Installation page ( and finally, at the Prerequisites section, one line caught my eye:

Docker requires a 64-bit installation regardless of your Ubuntu version.

So, not only I needed a 14.04 or newer Ubuntu version, but I also needed 64 bit! So I changed my Vagrantfile to:

Vagrant.configure("2") do |config| = "ubuntu/trusty64"

  config.vm.provision "docker" do |d| "rabbitmq"

And it all went smoothly.

Share Button

Install PostgreSQL on Ubuntu

Installing the postgresql package

You would think that installing PostgreSQL on Ubuntu (actually as I write I’m using Mint 14, but it is still Ubuntu based, so bear with me on that one) is as simple as opening a terminal and typing:

$ sudo apt-get install postgresql

While the above command will install the latest PostgreSQL database server on your machine, you still need to configure some parts for it to become fully functional.

Disclaimer: The steps described below are intended to be used on a local development machine, production servers should be configured with a more tight security setup in mind. Please refer to the PostgreSQL Server Administration Documentation for further information.

Allowing TCP/IP connections

There’s not much use for a database server if nobody can connect to it, is there? And most clients will want to connect via TCP/IP, which is disabled by default. So let’s enable it.

Edit the /etc/postgresql/9.1/main/postgresl.conf file (please replace the 9.1 with the appropriate version). I really like vim, but it is not installed by default on most distros. If you’re not comfortable with it, use gedit (or pluma if you also use Mint wink wink) with gksudo.

$ gksudo gedit /etc/postgresql/9.1/main/postgresl.conf

Locate the line that starts with #listen_addresses – it should look like:

#listen_addresses = 'localhost'

And just remove the leading ‘#’ char, so that it will look like:

listen_addresses = 'localhost'

The file has a lot of comments that help understand what goes on there, but what we’re doing is that this server will accept TCP/IP connections originated on ‘localhost’, that is, the same machine running the PostgreSQL server.

Save the file and leave the editor.

Establishing user permissions

Now that we can connect to the PostgreSQL server, we need a user to do so. Since we’re on a development machine and want to keep it simple, we’re gonna use the already present postgres (yes, I wrote it right, the user does not have the ql suffix) user.

First, let’s connect to the template database (we’re impersonating the postgres user and using psql to connect to the template1 database):

$ sudo -u postgres psql template1

A prompt like this should show up:

psql (9.1.9)
Type "help" for help.


Now we’re gonna create a passwor for the postgres user:

template1=# \password postgres

Type and confirm the password and quit the psql program (\q at prompt).
Now we’re gonna edit the /etc/postgresql/9.1/main/pg_hba.conf file and add the following line:

local   all             postgres                                md5

Just go ahead and add it at the bottom of the file, save it and quit the editor.
Now, just one more step:

Restarting the Server

To apply the settings, you should restart the server by typing:

$ sudo service postgresql restart

You should see something like:

* Restarting PostgreSQL 9.1 database server                                [ OK ]

And you’re good to go!

Testing the connection

Just type (we’re using the psql program with the postgres user. If the -U postgres is ommited, the psql will try to use the current user as the database user, and therefore will fail) :

$ psql -U postgres

You should be prompted for a password – that is the one you’ve typed and confirmed for the postgres user.

If the following error is displayed:

psql: FATAL:  Peer authentication failed for user "postgres"

Just add the -W switch to the command:

$ psql -U postgres -W

and you will be prompted for a password. After you type it, you will be presented with the psql prompt, where you can issue commands and queries to your PostgreSQL database.

Share Button

rsync to an exFAT partition in Linux

I do most of my work on Linux machines, but I have a Mac at home, I love the build quality and the fact that, after all, it is still *nix.

Yesterday I tried to copy a large file (8.8GB) to my flash drive, but as it was FAT32 formatted, it failed because of the file size cap (4GB) on such partitions. So I rsync’d the contents of the flash drive to a temp dir on my Linux machine and partitioned the flash drive as exFAT (it is native from OSX Snow Leopard and later, and if it is not already on your Linux box, try installing the exfat-fuse and exfat-utils packages on a recent Debian based Distro).

The problem is when I tried to rsync the contents of the temp directory back to the flash drive, I got a lot of errors such as:

rsync: chgrp "util/iphone/" failed: Function not implemented (38)

I googled for answers, found some, but nothing that would solve my problem, until some pages deep, after looking inside a lot of posts on a page I found the solution.

It happens that I automatically use rsync as follows:

rsync -av [SRC] [DESTINATION]

I always use the av switch, that states for:

v: increases verbosity, shows the files being synchronized
a: archive, replaces the rlptgoD switches (recurse dirs, preserve symlinks, preserve permissions, preserves modification times, preserve groups, preserve owner and preserve Device files).

The problem is that the Linux exFAT does not cope well with the switches that relate to permissions (the pgo), so the solution is to run rsync with the following switches, removing the p, g and o:

rsync -rltDv [SRC] [DESTINATION]

Of course, rembering the switch is much easier than remembering rltD, but a quick rsync –help will help you remind that.

Share Button

MySQL Job failed to start on Ubuntu

That’s one reason (of many) for this blog title (grinding, ranting…)

Today, when I tried to access the blog I got a nice “Database connection error”. I really hadn’t done anything unusual (other than an apt-get upgrade, but I don’t really think it should fall at the “unusual” category), so I logged on my VPS provider and restarted the server, only to have the same error displayed.

(sigh here)

As you guessed by the post title, I use MySQL, so I logged on my machine (my VPS offers me full ssh access, which is both a bless and a curse) and found out (obviously) that the mysql daemon was not started. Tried to restart it with (I know, I’m both lazy and stubborn):

# service mysql start

and had the informative (not!) error displayed:

start: Job failed to start

That’s it! The only thing printed on the console after I tried to start the service… Since the console was not helping me, I decided to take a look a the logs at /var/log. Both the mysql.err and mysql.log files were empty. The /var/log/mysql/error.log file was also empty. Now, that’s helpful.

So, I Googled the problem and found some hints pointing to permission errors regarding the place where the mysqld.lock file is stored. I looked at /etc/mysql/my.cnf and at the directory /var/run/mysqld (that’s where the /etc/mysql/my.cnf file told me it should be), but the permissions were ok, mysql was the owner of the directory and it had 755 permission.

So I came back to /var/log and noticed that /var/log/mysql directory and that both the /var/log/mysql.err file were both root owned. Hm… Weird… That’s what ‘ls -l’ returned:

drwxr-s--- 2 root root 4096 Mar 20 07:35 mysql
-rw-r----- 1 root root    0 Mar 6  19:53 mysql.err

I then changed the owner of both the file and directory:

# chown -R mysql:adm /var/log/mysql
# chown mysql:adm /var/log/mysql.err

Maybe now some error would be written to the logs… And it really did after I tried to start the service once more; at least now the /var/log/mysql/error.log file had some content, and upon inspecting it I saw a really suspect line:

/usr/sbin/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
130320 18:40:13 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.

Ok, so either the ./mysql/plugin.frm file really did not exist or its permissions were wrong. Now I had to find out where this file should be. Upon inspecting once again the /etc/mysql/my.cnf file, I saw some directories worth looking at:

datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql

And that was it, the /var/lib/mysql directory had root as owner and 700 permissions:

drwx------ 6 root root 4096 Mar 20 18:46 mysql

One more chown:

# sudo chown -R mysql:root /var/lib/mysql

And I was able to start mysql again!


Share Button

XFCE 4 and Eclipse Keyboard Shortcuts

I’m a big fan of keyboard shortcuts. So I was really disappointed when they did not work in Eclipse when I switched to Xfce from Gnome.

My first idea wast to review the Eclipse shortcuts, but they were correctly set. I then looked at Xfce keyboard shortcuts (Settings Manager->Keyboard->Application Shortcuts) and only a few were listed there, none that conflicted with the Eclipse default shortcuts. A quick Google search did not point me to anything concrete, until I saw this Peter Butkovic post in Dzone.

It turns out you have to edit the ~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml file! The before mentioned post is extensive and covers every modification you have to do, but to make things easier, I made the edited file available (please backup yours firsthere.


Share Button

CentOS 6.3 minimal install problems

Problem: Booted and only lo interface was enabled.

Solution: Edit the /etc/sysconfig/network-scripts/ifcfg-eth0 and change the following line:




and reboot. Probably a network restart would suffice.

Problem: Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory in Tomcat 6

Solution: tomcat-dbcp.jar is not included on the tomcat6 package on yum. Download it from here or copy it from another Tomcat 6 install (copy it to /usr/share/tomcat6/lib).

Problem: Commands not present in /usr/bin or /usr/sbin don’t seem to work, even when you have changed to the command’s directory


I don’t know if it happens with all commands, but happened to the “keytool” utility within the Oracle JDK directory. At the prompt I would type:

$ keytool

And it would not work, I double checked that I has cd’ed to the directory where keytool was (an ls -l would show it). Then, I remembered that I used to have to type it like this on some Linux installs:

$ ./keytool

And it worked!!

Share Button

MySQL Server on Ubuntu 12.04

Install mysql-server via apt-get:

$ sudo apt-get install mysql-server

Set the root password

Activate MySQL:

$ sudo mysql_install_db

Finish the setup by running:

$ sudo /usr/bin/mysql_secure_installation

If you have setup the root password on the first step, confirm it and answer “No” to the change root password question, and accept the default answer for the rest (just press Enter).

To access the mysql console:

$ mysql -u root -p

Here you can issue any other command you want to…

That’s it!

Share Button

Apache2 a2enmod rewrite on Ubuntu 12.04 and .htaccess for WordPress Permalinks

When I was setting WordPress up in order to make this blog work, I was changing the Settings>Permalinks section to make the post url look pretty. So I changed the “Common Settings” to “Day and Name” and saved.

When you do that WordPress writes the .htaccess file on the /var/www directory.

Ok, enough introductory small talk! What happens is that the above feature requires that the mod_rewrite (or simply rewrite) module is installed and enabled. Fortunately, it comes pre-installed on Ubuntu 12.04.1, and you just need to issue the

$ sudo a2enmod rewrite

command and that should work, right?

Well, not really… Even though the issued command creates the symlink for the rewrite.load file at /etc/apache2/mods-enabled, you still have to manually edit your /etc/apache2/sites-enabled/000-default file and change the AllowOverride directive from None to All at the /var/www Directory section.

So the section that looks like:

<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None # change this line
    Order allow,deny
    allow from all

Should look like:

<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All # now it will read .htaccess
    Order allow,deny
    allow from all

Restart apache and everything should work. By changing the AllowOverride directive to All you’re telling Apache to read and load the configuration found at the .htaccess file on that Directory. If it is set to None, the .htaccess file is ignored.

More info at:

Share Button

Tomcat 6 on Ubuntu 12.04

Supposing you don’t want to install the Tomcat version that is packaged on Ubuntu (if you need a differente version), this is what you should do:

Download Tomcat here to your home dir.

Add the Tomcat user and group

$ sudo groupadd tomcat
$ sudo useradd -g tomcat -s /usr/sbin/nologin -M tomcat

Go to /usr/local dir and unzip (beware of the file name, you may have downloaded a different/newer version), give appropriate permissions and create a simlink to ‘tomcat’

$ cd /usr/local
$ sudo tar -zxvf ~/apache-tomcat-6.0.36.tar.gz
$ sudo chown -R tomcat. /usr/local/apache-tomcat-6.0.36
$ sudo ln -s apache-tomcat-6.0.36 tomcat

Check if you can start it:

$ sudo /usr/local/tomcat/bin/

There should be something like this on the screen:

Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar

Open the following addres on your web browser: http://localhost:8080 (or replace localhost with your server name/ip address) and verify that Tomcat started properly (a pretty page should be displayed telling you that you’ve installed Tomcat succesfully, or something like that).

Now shut it down:

$ sudo /usr/local/tomcat/bin/

The same messages that appeared when you started it up should appear again (I know, I know, pretty weird).

Now you can use the following script to start and stop Tomcat. Download it to your home directory and place it at /etc/init.d

$ sudo mv tomcat /etc/init.d

To start/stop as the tomcat user, run the following command (it’s already on the script):

$ sudo su -s /bin/bash tomcat -c /usr/local/tomcat/bin/
Share Button