Archive | Linux RSS for this section

sphinx and WARNING: DOCID_MAX document_id, skipping

This error seems to wake-up with large ids >100.000.000 (like Ruby On Rails fixtures sys does).
Ok, like Piotr Jasiulewicz says this error appears because the sphinx was built without the –enable-id64 option.

Let’s go to solve this problem in Debian (note: I assume you use mysql, if not you have to change some dependencies packages).

Update 2012-05-31: this post refers to Debian Lenny i386. I don’t know if the binary package of Debian Squeeze (other distros, versions, architectures) is compiled with the same compile options at the moment. Anyway this post is intended to solve the specific warning (or to suggest a solution just in case you use another distro/architecture) .

Move to your preferred source folder (for example ~/src) or create it. Move to root user with su.
Download debian’s sphinxsearch sources:

#apt-get source sphinxsearch

Give permissions to your user on sphinxsearch files.

#chown -R youruser:youruser sphinxsearch*

Install mysql dev packages:

#apt-get install libmysqlclient-dev libmysqld-dev

Exit from root and return to your user. Enter in source folder of sphinxsearch (may vary with versions), configure with proper flags and make.

#exit
$cd sphinxsearch-0.9.9
$./configure –enable-id64
$make

Please note that pgsql is disabled by default and you should take a look at configure options (./configure –help) to see if you need others options, I don’t (except for libstemmer but I ignore this here).

Ok. If all was ok at make/compile time you can move on installation.

Move to root user with su (uninstall debian sphinx package if needed) and install.

#apt-get remove sphinxsearch
#make install

That’s all. Happy Sphinx On Ruby On Rails with fixtures 🙂

Sui virus informatici, e sulla sicurezza…

Vengo da una discussione fresca fresca nata a proposito dei classici annunci di nuovi virus in circolazione, pericoli abissali per gli utenti, qualcuno dice addirittura che un virus informatico ha ucciso la sua famiglia…

Quando leggo questo genere di articoli sono pervaso da un senso di nausea, non tanto perchè i virus esistono, ma piuttosto perchè oramai sembra che l’informatica non possa esistere senza di loro. A volte dico che uso lo stesso sistema operativo da 10 anni e non ho mai preso un virus… qualcuno mi guarda come se fossi un alieno, fa un passo indietro e mi dice “allora sei tu che li crei!! sei un hacker!!”, qualcuno ha quasi profetizzato che io fossi il nuovo messia…

Read More…

Netgear Readynas Duo, NFS and Debian Sid: mount.nfs: Operation not permitted

ReadyNAS Duo mount.nfs: Operation not permitted
Today I spend some time to mount one folder on Readynas Duo with NFS. All goes right from server (Debian Lenny) but i can’t mount NFS partitions from my pc (Debian Sid).

Error was “mount.nfs: Operation not permitted “.

Ok, I check my mount options

#cat /etc/fstab <ipaddress>:/c/folder  /mnt/folder nfs rw,user,noauto 0       0

Fstab is ok but problem persists.

Request mount to be verbose (from my pc – debian sid)

<myhost>:/home/giulio# mount -v /mnt/folder
mount.nfs: timeout set for Sun Jan 17 13:34:47 2010
mount.nfs: trying text-based options 'addr=<readynas-ip-address>,vers=4,clientaddr=<my-pc-address>'
mount.nfs: mount(2): Operation not permitted
mount.nfs: Operation not permitted

Request mount to be verbose (from my server – debian lenny)

mount.nfs: trying <readynas-ip-address> prog 100003 vers 3 prot TCP port 2049
mount.nfs: trying <readynas-ip-address> prog 100005 vers 3 prot UDP port 3078
<readynas-ip-address>:/c/folder on /mnt/folder type nfs (rw,noexec,nosuid,nodev,noauto,user)

Wow, ok, there is a difference.

My pc try to mount nfs with version 4, my server doesn’t use v4,  but it uses v3!

What is strange?
I’ve read a lot of tutorial/faq but my problem remains. So I read man pages but this is what I find, for example in man mount.nfs…

mount.nfs is meant to be used by the mount(8) command for mounting NFS shares. This subcommand, however, can also be used as a standalone command
with limited functionality.

mount.nfs4 is used for mounting NFSv4 file system, while mount.nfs is used to mount NFS file systems versions 3 or 2.  remotetarget is  a  server
share usually in the form of servername:/path/to/share.  dir is the directory on which the file system is to be mounted.

It seems to be false. On my pc I use mount.nfs and always mount tries with nfs4.

Ok, let’s go to solution..

You can force the NFS version to use with nfsvers=3.

So I change my /etc/fstab like this:

<readynas-ip-address>:/c/folder /mnt/folder nfs rw,user,noauto,nfsvers=3  0       0

Now mount uses the right version and all goes well.

Bye!

wiimote, wiicontrol, DrNokSnes and n900

Install DrNokSnes and wiicontrol.

Edit /usr/bin/wiicontrol to match this configuration (dont copy/paste, on python indentation level of your statements is significant):

mapping={
‘U’: [“a a”],
‘D’: [“a d”],
‘L’: [“a s”],
‘R’: [“a w”],
‘A’: [“a z”],
‘+’: [“a x”],
‘-‘: [“a c”],
‘1’: [“a v”],
‘2’: [“a b”],
‘H’: [“a n”],
‘GU’: [“a u”],
‘GD’: [“a i”],
‘GL’: [“a o”],
‘GR’: [“a p”],
‘Z’: [“a k”],
‘C’: [“a l”]
}

Start Bluetooth (or wiicontrol crashes).
Start wiicontrol (my wiicontrol freeze and I cant select key setup but it still works).
Setup wiimote (press 1+2).
Start DrNokSnes and tap un titlebar to configure keyboard.

Enjoy!

ruby on rails on nokia N900

Yes, we can! ruby on rails works well on nokia n900.
Install ruby from maemo repository (dev).
Download and install rubygems (use –no-rdoc and –no-ri).

Rubygems creates only /usr/bin/gem1.8 so you should create a soft link like this: ln -s /usr/bin/gem1.8 /usr/bin/gem

Type gem install rails -V and wait.

Now you are ready to start your rails app on nokia n900!
Just run ruby script/server in your project folder. To create a project folder use rails my_app as usual.

Your server may not start if you miss libopenssl-ruby. In this case you get an error about net/https: apt-get install libopenssl-ruby.

lighttpd, fcgi, rails and child exited with status 9, 1, 2, 3 or X

Ok, these errors are not good. They didn’t tell much about what happended.
But you can’t do as I did. Don’t wander on the dark side of the system…
Just try to execute your FCGI as your lighttpd did.
Find your lighttpd user in lighttpd configuration file (debian: /etc/lighttpd/lighttpd.conf).
On my configuration I see:
server.username  = “www-data”

so…

$ su
# cd /my_rails_root/public
# sudo -u www-data ./dispatch.fcgi

Read what’s happen and solve.
That’s all!

Validazione Codice fiscale Partita IVA con Ruby / Ruby On Rails

Cercando di validare codice fiscale e partita iva con Ruby, sono capitato nel sito di Umberto Salsi, dove si parla della validazione di Partita Iva e Codice Fiscale.

Visto che l’implementazione in Ruby non era disponibile ne ho realizzata una che ho già inoltrato all’autore della pagina perchè possa aggiungerla all’elenco.

Nel frattempo comunque, le due classi che ho preparato sono disponibili per il download.

Il codice Ruby che ho realizzato per eseguire i check di validità su codice fiscale e partita iva non è corredato da alcuna garanzia, potrebbe causare la morte di migliaia di persone, l’incendio del vostro PC, il mutamento del vostro orientamento sessuale, ma in nessun caso potrete ritenermi responsabile. Usatelo a vostro rischio e pericolo! 🙂

Scarica la validazione Ruby di codice fiscale e partita iva

updated (16/11/2009) – nuova versione con licenza GPL inclusa, descrizione, eccezioni e qualche miglioria

L’utilizzo è molto banale e potete riutilizzare, modificare e redistribuire il codice a vostro piacimento per qualsiasi utilizzo.

Un banale esempio di utilizzo per il codice fiscale:

require 'codice_fiscale'
if CodiceFiscale.valid?('ILTU0C0D1C3FISCAL3')
puts 'il codice fiscale è valido!'
else
puts 'il codice fiscale non è valido!'
end

Un banale esempio di utilizzo per la partita iva:

require 'partita_iva'
if PartitaIva.valid?('02030405060')
puts 'la partita iva è valida!'
else
puts '
la partita iva non è valida!'
end

Sull’opportunità o meno di utilizzare la validazione, vi consiglio di leggere il capitolo “Miti, superstizioni e falsità” sul sito di Umberto Salsi a proposito della validazione del codice fiscale. A tal proposito riporto riassumendo il concetto: usate la validazione ma non sempre è attendibile, potrebbe dare dei falsi negativi, bloccando per esempio la registrazione di utenti legittimi. Viceversa gli utenti malintenzionati potrebbero fabbricarsi in pochi secondi un codice fiscale falso (ma corretto) attraverso uno dei tanti servizi online. La validazione del codice fiscale risulta quindi utile solamente se si vuole eseguire un controllo formale per evitare errori di battitura, ma è solamente controproducente se si cerca con questo mezzo di tener lontano qualcosa e/o qualcuno.

Per quanto riguarda la partita iva vale quanto detto a proposito del codice fiscale.
Tuttavia ho individuato un bel webservice per la validazione delle partita iva messo a disposizione dell’Unione Europea e denominato VIES VAT number validation. Il wsdl e maggiori informazioni sul servizio potete trovarle nelle Faq. Il servizio peraltro funziona, l’ho provato oggi, ed è pure gratuito e discretamente veloce. Interroga i database dei paesi dell’Unione quindi è in grado di fornire validazione anche per le altre partite iva europee. Va sottolineato che non si limita a fare la validazione formale, ma da quanto si apprende attraverso le Faq è anche in grado di verificare se la partita iva esiste realmente ed è attiva. Per alcuni paesi inoltre, fornendo la partita iva, oltre a verificare se esiste ed è disponibile, vengono forniti anche alcuni dati utili sull’azienda tra cui nome ed indirizzo (l’italia è ovviamente esclusa da questa chicca).

Se qualcuno è interessato può scaricare la ruby class for VIES VAT number validation che ho realizzato per un applicativo su base Rails. Per altri usi dovete chiaramente adattarla, ma fa il suo dovere. Ricordate di copiare i wsdl in locale, è una scelta preferibile.

Buona giornata!

linux/debian raid 1 recovery how-to

Hi!

Today one of two harddisks on server fails. How-to repair raid? Easy.

Check raid status (find hda is not updated)

cat /proc/mdstat

If damaged disk is active (for example: only bad sectors) remove it from raid.

mdadm /dev/md0 -r /dev/hda

Turn off your server if hd is not hot-swappable.
Remove damaged hd and replace it with new hd.
Restart your server, be sure that is starts from the old ok hd (ex. hdb). Sometimes bios doesn’t properly updates boot devices and tries to start from new hd or cds, fix it.

System must boot-up properly from old ok hd.

Clean new hd (ex. /dev/hda), remove all partitions.

fdisk /dev/hda

Clean MBR of new disk (to be sure that an old mbr doesn’t exist)

dd if=/dev/zero of=/dev/hda bs=512 count=1

Copy raid partitions scheme from old ok hd.

sfdisk -d /dev/hdb > mbr_hdb.txt

Apply that scheme to your new hd.

sfdisk /dev/hda < /root/mbr_hdb.txt

Add partitions from new disk to your raid

mdadm /dev/md0 -a /dev/hda1

Raid recovery starts.
Check rebuild status

mdadm –detail /dev/md0


/dev/md0:
Version : 00.90
Creation Time : Wed Apr  1 11:10:50 2009
Raid Level : raid1
Array Size : 37110016 (35.39 GiB 38.00 GB)
Used Dev Size : 37110016 (35.39 GiB 38.00 GB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 0
Persistence : Superblock is persistent

Update Time : Fri May  8 11:52:58 2009
State : clean, degraded, recovering
Active Devices : 1
Working Devices : 2
Failed Devices : 0
Spare Devices : 1

Rebuild Status : 74% complete

UUID : b1d86bee:0e4dedf0:4ddd5836:05672650
Events : 0.680998

Number   Major   Minor   RaidDevice State
2       3        1        0      spare rebuilding   /dev/hda1
1       3       65        1      active sync   /dev/hdb1

That’s it!
Wait and be happy.

oh…. as you know this is not a complete/best/lucky tutorial, if you follow it you home may explode, your city my be destroyed, but don’t bother me! 🙂 no warranty

Good luck!! 😀

undefined method `length’ for Enumerable Enumerator on text_helper.rb:50:in `truncate’

With rails 2.0.2 and ruby 1.8.7 you can find this error using rails truncate helper

To solve this problem, paste this code in your enviroment.rb (eof).

module ActionView
  module Helpers
    module TextHelper
      def truncate(text, length = 30, truncate_string = "...")
        if text.nil? then return end
        l = length - truncate_string.chars.to_a.size
        (text.chars.to_a.size > length ? text.chars.to_a[0...l].join + truncate_string : text).to_s
      end
    end
  end
end

Have a nice day!

How to downgrade rails version on debian

If you want to downgrade rails (aka install an old version of rails) on debian first of all install rails gems. Execute next command as root:

apt-get install rubygems

Remove rails package of debian if it’s actually installed

apt-get remove rails

Now install rails by gems utility and force the right version. Example:

gem install -v=2.0.2 rails --include-dependencies

Now put gems bin folder on bash PATH. Edit /etc/bash.bashrc

export PATH=$PATH:/var/lib/gems/1.8/bin

Note: version of rubygems may be different, check your right PATH to gems bin folder

If all goes right now you can use your preferred rails version. Note, rails command from gems is little different between the script that debian package installs. Just check params: call rails command without params.

$ rails
Usage: /var/lib/gems/1.8/bin/rails /path/to/your/app [options]
Options:
-r, --ruby=path Path to the Ruby binary of your choice (otherwise scripts use env, dispatchers current path).
Default: /usr/bin/ruby1.8
-d, --database=name Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite2/sqlite3).
Default: mysql
-f, --freeze Freeze Rails in vendor/rails from the gems generating the skeleton
Default: false
Rails Info:
-v, --version Show the Rails version number and quit.
-h, --help Show this help message and quit.
General Options:
-p, --pretend Run but do not make any changes.
--force Overwrite files that already exist.
-s, --skip Skip files that already exist.
-q, --quiet Suppress normal output.
-t, --backtrace Debugging: show backtrace on errors.
-c, --svn Modify files with subversion. (Note: svn must be in path)

That’s all folks! 🙂