Skip to main content

Ralsina.Me — Roberto Alsina's website

Posts about sysadmin (old posts, page 3)

Small software released: RA-WebPass

I just re­leased a wee piece of soft­ware, called RA-Web­Pass which is sim­ply a web­page that you can use to change lin­ux sys­tem pass­word­s.

Ba­si­cal­ly, I wrote it to­day out of my frus­tra­tion with cus­tomers ask­ing me "how can I change the pass­word for the FTP server". Ok, this is how you can.

It's sim­ple and does­n't have too many de­pen­den­cies, so it should be rather se­cure, but don't trust me on that, and you need to run it as root, so be very very care­ful.

RA-Web­Pass home page

On a re­lat­ed note: it's quite sat­is­fy­ing to write some­thing in two hours and just re­lease it :-)

A KDE hack: Faster mail searches in kmail, using mairix

Kmail search­es slow­ly.

I have been a kmail us­er for a cou­ple of years, since I set­tled in my own home of­fice with my own com­put­er.

I like the thing.

How­ev­er, it an­noys me that it takes sooooo long to find a mes­sage in my mail­store. Hey, it's on­ly 13000 mes­sages!

So, while I wait for KDE4 to bring all its search­ing good­ness, I de­cid­ed to see if I could hack some­thing quick­ly.

En­ter mair­ix: a mail in­dex­er/search thing.

Con­vinc­ing mair­ix to in­dex all my mail was rather sim­ple (here is my ~/.­mair­ixr­c):

base=/home/ralsina/
maildir=Mail/*...
maildir=.kde/share/apps/kmail/dimap...
omit=Mail/mairix
database=~/.mairix_db

What does it do?

  • It in­­dex­es mail stored at ~/­­Mail and ev­ery­where in my kmail imap fold­er­s.

  • It stores search re­­sults in ~/­­Mail/­­mair­ix and ig­nores its con­­tents when search­ing. The re­­sults are stored as links, so they waste no disk space.

Af­ter run­ning mair­ix so it builds its DB (took about a min­ute, which is less than most kmail search­es) , you can search for things like this:

[ralsina@monty ~]$ time mairix b:bartleblog
Matched 6 messages

real    0m0.232s
user    0m0.012s
sys     0m0.204s

And the re­sult can be seen in kmail, in the mair­ix fold­er:

mairix1.png

How­ev­er, there is a prob­lem. It will work for the first search, but not for the sec­ond one. On the sec­ond search, you get the same con­tent list­ing, but all mes­sages ap­pear emp­ty.

That's be­cause kmail saves an in­dex file of each fold­er. To work around that, I wrote a lit­tle shell wrap­per, kmair­ix:

#!/bin/sh
rm ~/Mail/.mairix* -f
mairix $*

And you use that in­stead of call­ing mair­ix di­rect­ly.

But there are still im­prove­ments to be done. If your kmail is cur­rent­ly dis­play­ing the mair­ix fold­er, search­ing does­n't up­date the mes­sage list.

DCOP to the res­cue! We can switch to the in­box, then back to mair­ix (ad­just as need­ed for your­self):

dcop kmail KMailIface selectFolder /Local/inbox
dcop kmail KMailIface selectFolder /Local/mairix

Miss­ing pieces:

  • How about switch­ing to the kmail win­­dow? Sad­­ly, the kwin DCOP in­­ter­­face seems in­­­com­­plete. Maybe as­sign­ing kmail a hotkey and work from there? Let me know if you have any ideas.

    UP­­­DATE as sug­­gest­ed by An­no He­im­burg: just call kmail.

  • A GUI (of course!) prob­a­bly with a tray icon...

  • A way to au­­to-up­­date the Mair­ix DB when new mail ar­rives. I am think­ing about do­ing it with in­­cron but have not done it yet.

So, here is the fi­nal ver­sion, put it some­where in your path, and use AL­T+F2 to search your mails :-)

#!/bin/sh
rm ~/Mail/.mairix* -f
mairix $*
dcop kmail KMailIface selectFolder /Local/inbox
dcop kmail KMailIface selectFolder /Local/mairix
kmail

Sometimes I am stupid. Then again, it doesn't matter, because I am lucky!

I am work­ing on chang­ing Bartle­Blog so it can be used from scratch. That may sound odd but be­cause I have been us­ing it since day 2 to post this blog, it has grown very or­gan­i­cal­ly, mean­ing there are things that on­ly work be­cause of the way I used it while de­vel­op­ing it.

So, I cre­at­ed a test user, and cre­at­ed a test blog there, and I am work­ing, and de­cide to do an­oth­er from-scratch test, and...

I delet­ed my pro­duc­tion copy.

Yes. The one that gen­er­ates this blog. So this blog dis­ap­peared. Be­cause I used the wrong ter­mi­nal win­dow.

And I had one-week old back­up­s.

So I felt very very stupid.

Be­cause un­delet­ing in Lin­ux is a joke.

So I was think­ing how to spend a few hours recre­at­ing the last week of post­s, and what­ev­er, when I no­ticed on the taskbar... bartle­blog was still run­ning.

Which means that the DB was still open by a process. Which mean­s...

[ralsina@monty bartleblog]$ ps ax | grep python
17063 pts/1    S     24:33 python bartleblog.py
17161 ?        S      0:04 konqueror [kdeinit] -mimetype text/html http://www.google.com/search?q=python+copy+file&ie=UTF-8&oe=UTF-8
17454 pts/1    D+     0:00 grep python
[ralsina@monty bartleblog]$ su
Password:
[root@monty bartleblog]# cd /proc/17063/fd
[root@monty fd]# ls
0  1  10  11  12  2  3  4  5  6  7  8  9
[root@monty fd]# ls -l
total 0
lrwx------ 1 ralsina users 64 2007-05-13 21:07 0 -> /dev/pts/1
lrwx------ 1 ralsina users 64 2007-05-13 21:07 1 -> /dev/pts/1
lrwx------ 1 ralsina users 64 2007-05-13 21:07 10 -> socket:[159486]
lrwx------ 1 ralsina users 64 2007-05-13 21:07 11 -> socket:[159488]
lrwx------ 1 ralsina users 64 2007-05-13 21:07 12 -> /mnt/centos/home/ralsina/.bartleblog/blog.db (deleted)
lrwx------ 1 ralsina users 64 2007-05-13 21:07 2 -> /dev/pts/1
lr-x------ 1 ralsina users 64 2007-05-13 21:07 3 -> /mnt/centos/home/ralsina/Desktop/proyectos/bartleblog/bartleblog/BartleBlog/ui/bartleblog.py
lr-x------ 1 ralsina users 64 2007-05-13 21:07 4 -> pipe:[159481]
l-wx------ 1 ralsina users 64 2007-05-13 21:07 5 -> pipe:[159481]
lr-x------ 1 ralsina users 64 2007-05-13 21:07 6 -> pipe:[159482]
l-wx------ 1 ralsina users 64 2007-05-13 21:07 7 -> pipe:[159482]
lr-x------ 1 ralsina users 64 2007-05-13 21:07 8 -> pipe:[159485]
l-wx------ 1 ralsina users 64 2007-05-13 21:07 9 -> pipe:[159485]
[root@monty fd]# cp 12 /root/db
[root@monty fd]# ls -l ~/db
-rw-r--r-- 1 root root 3582976 2007-05-13 21:07 /root/db
[root@monty fd]# sqlitebrowser ~/db
[root@monty fd]# cp ~/db /home/ralsina/.bartleblog/blog.db

And I got the data­base back.

If you don't un­der­stand how that worked.... here's the ex­pla­na­tion:

  • On unix, files are re­al­­ly un­linked (re­­moved from di­rec­­to­ries) when no process has them open. Even then, the da­­ta is not delet­ed, but find­­ing it is much hard­er.

  • On /proc/PID you can see the file de­scrip­­tors each process has open.

  • You can ac­­tu­al­­ly copy a file de­scrip­­tor.

So I went and copied the open file. And got it back. And this blog did­n't go away.

So I am luck­y! Stupid. But luck­y!

Veanme en CafeConf 2006! / See me at CafeConf 2006!

Co­mo to­dos los años, voy a dar una char­la en Cafe­Conf 2006, el tema de este año es "Boote­an­do más rápi­do y mejor us­an­do runit".

Si bus­can runit en este blog se van a en­ter­ar mas o menos de las mis­mas cosas, pero la char­la de­bería ser más pro­li­ja :-)

La primera per­sona que men­cione el nom­bre de este blog en la parte de pre­gun­tas y re­spues­tas se gana un re­ga­lo sor­pre­sa!


Like ev­ery year, I will be speak­ing at Cafe­Con­f, Sat. Nov 11. This year's top­ic is "Bot­ting faster and bet­ter us­ing runit".

If you look for runit in this blog, you will find out more or less the same things, but this should be more or­ga­nized.

The first guy to men­tion the blog in the Q&A ses­sion gets a sur­prise gift.

Using runit is even simpler

I have post­ed in the past about runit.

One of the prob­lems peo­ple mi­grat­ing to runit have is that all your ser­vices are SysV script­s.

The runit au­thor has a col­lec­tion of scripts you can use, but usu­al­ly they re­quire some ad­just­ment to work on a spe­cif­ic ver­sion of Lin­ux.

So, I wrote a lame python script that takes the SysV scripts you are cur­rent­ly us­ing and turns them in­to runit ser­vices, in­clud­ing de­pen­den­cies.

Sup­pose you usu­al­ly start on run­lev­el 3. Then you save this script and run it like this:

mkdir services
python importinit.py 3

And you should end with a bunch of runit ser­vices in­side ser­vices/

Those ser­vices will start in rough­ly the same or­der as if you were us­ing SysV init. That's prob­a­bly way too much de­pen­den­cies.

The main dif­fer­ence is that kdm will start ear­li­er and the ttys will start way ear­li­er than you are used to.

I have found that my note­book boots faster us­ing this, but I can't pro­vide a bootchart be­cause it sim­ply does­n't seem to work in my com­put­er.

If any­one is will­ing and able to run the tests and quan­ti­fy the dif­fer­ence, I am all ears.

For some rea­son kudzu, ipt­a­bles and arpt­a­bles_jf don't work with this ap­proach, so just stick them at the bot­tom of /etc/runit/1

Al­so, please un­der­stand that these are not cor­rect runit ser­vices. They are not man­aged, so if your ser­vice crash­es it stays crashed.

So, you should still even­tu­al­ly mi­grate to cor­rect script­s. This is just a way to make that sim­pler.


Contents © 2000-2020 Roberto Alsina