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|
    d.run "rabbitmq"
  end
end

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:

vm:
* 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|
  
  config.vm.box = "hashicorp/precise32"
  
  config.vm.provision "docker" do |d|
    d.run "rabbitmq"
  end
end

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 (https://docs.docker.com/installation/ubuntulinux/) 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|

  config.vm.box = "ubuntu/trusty64"

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

And it all went smoothly.

Share Button

How to create a Mac OS X Yosemite boot disk

You don’t need any apps, you can do it in your own Mac OS X terminal, you don’t even need to upgrade to Yosemite prior to doing this, you just need to download it beforehand. This guide assumes you have some Terminal knowledge and somewhat understands what are Volumes on your Mac (hint: they’re what Windows calls “Drives”).

I guess not many people will use an actual disk, but an empty USB drive larger than 4 GB will also do. Beware, it will erase your entire drive (the USB one).

After downloading Yosemite throug the Mac App Store, plug an USB drive – it should be a Mac OS X Extended (Journaled) partition, if you’re not sure, use Disk Utility to check it. If not, under Disk Utility, select the USB drive and choose then the “Erase” tab. On the “Format” combo box select the  “Mac OS X Extended (Journaled)” option  and click on the “Erase” button. Notice the “Name” field under the “Format” option – this is your volume name and will be necessary.

Open your terminal and type the following command:

sudo /Applications/Install\ OS\ X\ Yosemite.app/Contents/Resources/createinstallmedia --volume /Volumes/yosemite --applicationpath /Applications/Install\ OS\ X\ Yosemite.app

If your partition (USB drive) is not named “yosemite” (and there’s a good chance it is not), just replace the “yosemite” on “Volumes/yosemite” whith your actual volume name (the displayed “Name” under “Format” on Disk Utility).

Let me explain a lit bit better what the command does:

sudo: sudo lets you run a command using super user privileges, that’s why when you run the command, it asks you for your password.

/Applications/Install\ OS\ X\ Yosemite.app/Contents/Resources/createinstallmedia: This tells you want to invoke the “createinstallmedia” command, that is under /Applications/Install OS X Yosemite.app/Contents/Resources directory. This is the utility used to actually create the bootable disk. The forward slashes (“/”) are used because the terminal does not deal well with spaces.

–volume /Volumes/yosemite: This tells the createinstallmedia utility where it should create the bootable disk.

–nointeractions: You could add this switch – it erases the disk without confirmation (dangerous one – just kidding).

That’s it, after you run the command, input your password and confirm that the volume will be erased, wait for it to finish, eject the drive and take it somewhere else to install on another computer.

BTW, that’s what your terminal screen will look like when it is done:

Erasing Disk: 0%... 10%... 20%... 30%...100%...
Copying installer files to disk...
Copy complete.
Making disk bootable...
Copying boot files...
Copy complete.
Done.
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.

template1=#

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/absinthe-mac-0.4.zip" 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

Remote Debug on JBoss AS 7

Enabling remote debugging on JBoss AS 7 is pretty easy – instead of changing the /JBOSS-HOME/bin/run.conf file (as it was the case with JBoss 5) you will change the /JBOSS-HOME/bin/standalone.conf file. It makes a lot of sense, since you no longer have run.sh, but standalone.sh.

Anyway, open the standalone.conf file and look for the following lines (you should shut JBoss down prior to doing this):

# Sample JPDA settings for remote socket debugging
#JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"

Then, just remove the ‘#‘ char prior to JAVA_OPTS, so that it would look like:

# Sample JPDA settings for remote socket debugging
JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"

That’s it. Save the file and start JBoss normally. It will be accepting remote debug connections on port 8787.

UPDATE:

If you’re running JBoss AS 7 on Windows, you should look for the file JBOSS-HOME\bin\standalone.conf.bat and then look for the section:

rem # Sample JPDA settings for remote socket debugging
rem set "JAVA_OPTS=%JAVA_OPTS% -agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n"

You should then remove the “rem” word from the second line (“rem” marks a comment for .bat files – same as “#” in Linux), so the section would look like this:

rem # Sample JPDA settings for remote socket debugging
set "JAVA_OPTS=%JAVA_OPTS% -agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n"

Save your file and start JBoss again.

When it starts you should see the JAVA_OPTS are set:

===============================================================================

JBoss Bootstrap Environment (...)

JBOSS_HOME: "..."

JAVA: "C:\Program Files\Java\jdk1.7.0\bin\java"

JAVA_OPTS: "-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=3M 
-XX:-TraceClassUnloading -XX:+UseCompressedOops -Dprogram.name=standalone.bat -Xms1G -Xmx1G -XX:MaxPermSize=256M -Djava.net.preferIPv4Stack=true -Djboss.modules.policy-permissions=true -Djboss.modules.system.pkgs=org.jboss.byteman
-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n" ===============================================================================

 

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:

ONBOOT="no"

to

ONBOOT="yes"

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

Solution:

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

Change charset encoding on MySQL databases

It’s pretty simple, just issue an ALTER DATABASE command:

ALTER DATABASE database_name CHARACTER SET charset

To check if it was changed:

SELECT default_character_set_name FROM information_schema.SCHEMATA
WHERE schema_name = "database_name";

 

Share Button