The Rails ninjas' blog

Foreman and Upstart

Duccio Giovannelli on Aug 18 2015.

Upstart supervises tasks and processes while the system is running, here's how to use Foreman and Capistrano to configure and use it.

Read more...

Preparing old Datastax EC2 machines for the Leap Second

Silvio Relli on Jun 26 2015.

Most of our DSE Cassandra and Solr nodes are hosed on AWS EC2 and created starting from the offical Datastax AMI, an old Ubuntu 12.04.5 LTS (Precise Pangolin).

Some of those machines were still running Linux kernels older than 3.4.x and Java antecedent to version 7u60.

As said in the DataStax Developer Blog post Preparing for the Leap Second, those instances would fail quite for sure on June 30th.

To avoid getting stuck in the Leap Second bug we proceeded with the following steps, updating both the Java JDK and the Linux kernel:

1
2
uname -r
java -version
Read more...

SSLv3 read server certificate B: certificate verify failed

Duccio Giovannelli on May 23 2015.

After the 10.10.3 Yosemite update I got an error connecting to datasift using their gem:

ConnectionError: : Failed to complete SSL verification (Network error: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed)

Read more...

How to add OpenCV 2.4.11 in your iOS project

Matteo Alessani on May 22 2015.

I normally use CocoaPods inside my project, but the latest version of OpenCV (2.4.11) is not available through pod and 2.4.10 is not compiling successfully. So I decide to add the framework directly. After downloading the file from the download page and dragging the framework on your project, if you try to compile it you will probably get:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Undefined symbols for architecture x86_64:
  "_jpeg_free_large", referenced from:
      _free_pool in opencv2(jmemmgr.o)
  "_jpeg_free_small", referenced from:
      _free_pool in opencv2(jmemmgr.o)
      _self_destruct in opencv2(jmemmgr.o)
  "_jpeg_get_large", referenced from:
      _alloc_large in opencv2(jmemmgr.o)
      _alloc_barray in opencv2(jmemmgr.o)
  "_jpeg_get_small", referenced from:
      _jinit_memory_mgr in opencv2(jmemmgr.o)
      _alloc_small in opencv2(jmemmgr.o)
  "_jpeg_mem_available", referenced from:
      _realize_virt_arrays in opencv2(jmemmgr.o)
  "_jpeg_mem_init", referenced from:
      _jinit_memory_mgr in opencv2(jmemmgr.o)
  "_jpeg_mem_term", referenced from:
      _jinit_memory_mgr in opencv2(jmemmgr.o)
      _self_destruct in opencv2(jmemmgr.o)
  "_jpeg_open_backing_store", referenced from:
      _realize_virt_arrays in opencv2(jmemmgr.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Read more...

How to localize a Storyboard and update it in Xcode 6.x

Matteo Alessani on May 21 2015.

With Xcode 6.x you can easily design your user interface in Interface Builder. Once you have done it you can localize your application adding a localization inside your project info:

xcode settings

Adding a localization will create a new file under your storyboard named your_storyboard.strings, where you can put your translations starting from the base text. But what happen if you add a new UILabel to your storyboard?

You have to generate by yourself the new file running this command inside your Base.lproj folder:

1
ibtool Main.storyboard --generate-strings-file main_new.strings

This file will have all the original text and not your translations, so you have to do a manual diff and pick the right sections from the two files.

View post...

How to unmount an NFS share if the folder becomes unreachable

Matteo Alessani on May 06 2015.

As pointed out by Silvio on Quick NFS share between AWS EC2 instances, sometime is very useful to attach a network folder to faster transfer big files. If the instance of the network folder suddenly become unavailable you can find some problem on unmounting this folder, because if you try to access this folder or doing simple df -h commands will hang your console. To unmount your folder you should run this command:

1
umount.nfs4 "/mnt/solr (deleted)" -f 

If you got this error: umount.nfs4: /mnt/solr (deleted): not found you need to find your mount point name with cat /proc/mounts. If the mount point is something like that:

1
2
3
...
xx.xx.xx.xx:/raid0/cassandra /mnt/solr\040(deleted) nfs4 rw,relatime,vers=4,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=xx.xx.xx.xx,minorversion=0,local_lock=none,addr=xx.xx.xx.xx 0 0
...

you need to change on /etc/mtab the line that points to the same mount but without the \040(deleted) string.

Edit the /etc/mtab, add the \040(deleted) to the end of mount path, then use mount to show the new path.

Then you can use:

1
umount.nfs4 "/mnt/solr (deleted)" -f 

to successfully unmount your folder.

View post...

Installing ruby 2.2.0 on Ubuntu 14.04 with rbenv

Matteo Alessani on Jan 23 2015.

Today I had an issue installing ruby 2.2.0 on Ubuntu. After upgrading definitions of ruby-build, I tried to run the command:

1
rbenv install 2.2.0

but the process exited with this error:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
linking shared-object fiddle.so
linking shared-object date_core.so
compiling ossl_pkey.c
/usr/bin/ld: ./libffi-3.2.1/.libs/libffi.a(raw_api.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
./libffi-3.2.1/.libs/libffi.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [../../.ext/x86_64-linux/fiddle.so] Error 1
make[2]: Leaving directory `/tmp/ruby-build.20150123170726.9800/ruby-2.2.0/ext/fiddle'
make[1]: *** [ext/fiddle/all] Error 2
make[1]: *** Waiting for unfinished jobs....
compiling ossl_x509req.c
linking shared-object psych.so
make[2]: Leaving directory `/tmp/ruby-build.20150123170726.9800/ruby-2.2.0/ext/date'
installing default psych libraries
compiling constants.c
compiling ossl_bio.c
make[2]: Leaving directory `/tmp/ruby-build.20150123170726.9800/ruby-2.2.0/ext/psych'
compiling ossl_pkey_rsa.c
compiling ossl_x509ext.c
compiling ossl_x509crl.c
compiling ossl_hmac.c
installing default openssl libraries
linking shared-object openssl.so
make[2]: Leaving directory `/tmp/ruby-build.20150123170726.9800/ruby-2.2.0/ext/openssl'
linking shared-object socket.so
make[2]: Leaving directory `/tmp/ruby-build.20150123170726.9800/ruby-2.2.0/ext/socket'
linking shared-object zlib.so
make[2]: Leaving directory `/tmp/ruby-build.20150123170726.9800/ruby-2.2.0/ext/zlib'
linking shared-object ripper.so
make[2]: Leaving directory `/tmp/ruby-build.20150123170726.9800/ruby-2.2.0/ext/ripper'
make[1]: Leaving directory `/tmp/ruby-build.20150123170726.9800/ruby-2.2.0'
make: *** [build-ext] Error 2

To fix this issue you can just install the libffi-dev package with

1
sudo apt-get install libffi-dev

and re-run the command rbenv install 2.2.0

View post...

Problem compiling latest rmagick on ruby 1.8.7 and Yosemite

Matteo Alessani on Dec 22 2014.

If you are trying to setup an old project using ruby 1.8.7 and you are trying to install latest version of rmagick, you'll probably get this error message:

1
2
3
4
5
6
7
gem install rmagick -v '2.13.4'
Building native extensions.  This could take a while...
ERROR:  Error installing rmagick:
    ERROR: Failed to build gem native extension.

        /Users/user/.rbenv/versions/1.8.7-p375/bin/ruby extconf.rb
extconf.rb:153: undefined (?...) sequence: /^Version: ImageMagick\s+(?<Version>\d+\.\d+\.\d+\-\d+)\s+(?<Unknown>\S+)\s+(?<Arch>\S+)\s+(?<Date>\S+)/

To avoid this problem you can try to install the previous version executing gem install rmagick -v '2.13.3'.

View post...

Quick NFS share between AWS EC2 instances

Silvio Relli on Dec 22 2014.

When we need to quickly move large files across EC2 servers inside the same security group we use to create a simple NFS share.

For first we need to open few ports in the Security Group, using the AWS Management Console

Add the following custom TCP rules:

1
2
3
4
5
111
2049
32768
44182
54508

And those custom UDP rules:

1
2
3
4
111
2049
32768
32770 – 32800
Read more...

Capistrano rake file for cities gem

Duccio Giovannelli on Nov 21 2014.

To use cities gem, you'll need the JSON data. So download it, extract it and connect it up as follows.

1
2
$ wget https://s3-us-west-2.amazonaws.com/cities-gem/cities.tar.gz
$ tar -xzf cities.tar.gz

Here how to use it:

1
2
3
Cities.data_path = '/path/to/cities'
cities = Cities.cities_in_country('GB')
  #=> { "abberley"=> #<City:0x000001049b9ba0>, "abberton"=> #<City:0x000001049b9b50>, ... }
Read more...

How to detach a ruby process with Capistrano 3

Duccio Giovannelli on Oct 14 2014.

To run a ruby script from Capistrano 3 demonizing it, remember to:

Read more...

Solr error request exception: Illegal character

Duccio Giovannelli on Sep 01 2014.

I'm getting Illegal character error during Solr indexing due to unicode chars present in my indexed element. I prefer to escape unicode chars before saving them on my database so during data extractor process we will avoid this error:

Read more...

Puppet server always in Changed state

Matteo Alessani on Aug 21 2014.

Puppet is a very handful tool to manage your server infrastructure. I hope soon to do a detailed post on how to setup a Puppet server from which orchestrate your whole farm.

Puppet runs every 30 minutes on all the servers of your farm, including the puppet server itself. If the run doesn't alter the configuration or the state of an instance you get the result "Unchanged" for your instance. Due to a small bug on puppet 3.3.0 (should be fixed on version 3.3.1) and Ubuntu 14.04 I was getting the "Changed" state inside the puppet server because process pe-activemq wasn't able to create the pidfile of the process and puppet was trying to start the process even if it was already running.

1
2
Notice: /Stage[main]/Pe_mcollective::Activemq/Service[pe-activemq]/ensure: ensure changed 'stopped' to 'running' 
Info: /Stage[main]/Pe_mcollective::Activemq/Service[pe-activemq]: Unscheduling refresh on Service[pe-activemq] 

To avoid this problem you can create a directory and change ownership to it so that the process can create the right pidfile:

1
2
mkdir -p /var/run/pe-activemq
mkdir pe-activemq /var/run/pe-activemq

then you have to kill with sudo kill -9 process_id your running pe-activemq process and start it with sudo service pe-activemq start

Now you should get the right pid for your pe-activemq process and the right state "Unchanged" on your puppet enterprise console.

View post...

How to use instance storage provided on EC2

Matteo Alessani on Jul 25 2014.

When you launch an EC2 instance, based on the type you choose, you have one or more device included in the price, but if you launch an EBS backed instance you'll get mounted only the first drive on /mnt.

If you want to use all the devices included in the instance you have to mount all instance stores at launch to have block devices initialized when your ec2 instance boots.

Instance store during EC2 launch

Then we have two options:

In this post I'll show you how to build the array.

Read more...

ActiveRecord::Associations has_many and before_add callback

Duccio Giovannelli on Jul 23 2014.

My need is to create a polymorphic has_many association with inheritance, where each inherited class has a sub_type that let me to list associations and create them without passing params to the create method.

You could say why don't use two level inheritance? Well, too many sub-classes aren't the best in our case so we decided to use a sub_type field, to manage small differences, but not the main type which would have obliged us to use inheritance again.

Read more...

This blog is operated by Extendi, a web dev company based in Florence, Italy.
We have created products such as Pulsar, BudgetUp and Recipefy.