Tuesday, August 28, 2007

Coke with Vitamin!!!

Hi friends,
You might find recently about various variation of Coca-Cola.

Some basic example of them are Coke-zero, Vanilla Coke, Diet Coke, Cherry Coke, etc.
But here, in US, I found Diet Coke Plus - diet coke with vitamins and minerals!!!.

Check it out :)






Sunday, August 26, 2007

Writing a service in Linux

As Khem's request, today I will (try to) explain the simple way to write a linux service.
The linux services are nothing but programs running in the background (usually daemon) to provide their service. For example, the httpd (HTTP Daemon) provide HTTP server service which made your system be a web server.

Writing a Linux service is easy, it require only two major steps.
1. Implement your program as Linux daemon
2. Write the service script, usually simple shell script, and place it in "/etc/init.d" directory

Ah, and you should be the root to start/stop or add services.

Briefly, the daemon is a program that run in the background and had practically no parent (literally it had only init process - the pid #1 - be its parent). You may implement Linux daemon program using C by simply calling daemon() function (in unistd.h). After daemon() called, your program will be a daemon :)
Service script is somewhat easy to write, too. Check the code below for example. (Suppose that this code was in the file /etc/init.d/testservice).

Sample service script called "testservice"
----------------------------
 1: #!/bin/bash
 2: . /etc/init.d/function #Include some necessary function
 3: case $1 in
 4:   start)
 5:     echo -n "Starting test service";
 6:     daemon /program/directory/test arg1 arg2;
 7:     echo;
 8:   ;;
 9:   stop)
10:     echo -n "Exiting test service";
11:     killproc test;
12:     echo;
13:   ;;
14:   status)
15:     status test;
16:   ;;
17:   *)
18:     echo " Usage: service testservice {start|stop|status}";
19:   ;;
20: esac
--------------------------------------

The "daemon" in line 6, "killproc" in line 11, and "status" in line 15 are bash functions written in /etc/init.d/functions. We include that file from . command in line 2. Alternatively, "source" command might be used instead of ".", for the code readability. The arguments in line 6 will be passed in the program you write.

Actually, you don't have to write the service script this way. You can make your own style, write your own function, define your command, or what not, since this is only the script being invoked via command "service".

You can even write perl script, or python, and put it in "/etc/init.d". Don't forget to change its permission to be 755 (executable). That's it. 

When root invoke command "service your-service ", the service program will pass argument to "your-service" script.

By the way, as I shown you, Linux (I tested on red-hat based Fedora Core 5 and Cent OS 4) had already provided some convenient function to start/stop or check service status. It would be more convenient to write in the simple style I posted :)

***NOTE***: For some reason (maybe pattern matching problem), the daemon program name should not include "_" (underscore). My service (shell) script didn't work when I had a underscore in a file name.

Hope this might benefit you a bit :)

Fug.U.Man

Wednesday, August 22, 2007

Google Summer of Code DONE!!!

OH MY GOD!!
Finally, my codes were done!!!!

(Actually, almost done, since the installation package still using shell script :(

OK, however I can have some free time to do more things I love to do :D

For your information, my ComSci friends, I wanna tell you that Linux and open source programs are great!!! But it took you some more time to work on, and had a very high (in my opinion) learning curve.

I worked on Fault-Tolerance High-Availability OSCAR, which will work on Linux cluster to enable fault tolerant job queue and job execution on MPI parallel programming (whomever would like to know more, please contact me :)

I didn't want to talk much about my GSoC here, just a few sentence complaint something happening on my project.

HOLY SH*T, many open source software had a great number of issues about dependencies!!!! And you might have to manually resolve those dependencies by yourself!!! (Again, ***MIGHT HAVE TO***, many of them were managed by packaging software like RPM, YUM, etc.) Installation alone might cost you more than one day.

If you use too new Linux distributions, the program might not support it. In consequences, you had to build it yourself from its codes. If some error appears, only you, the installer, would solve it T_T.

Moreover, some program might had a very bad documentation, that would make a lot of confusions instead of illuminations (I guess mine is one of them T_T).

Some programs that you had to depend on to complete your work might produce some unexpected error without any clue!!! Even the Q/A mailing list support might contain some issues similar to your error experience, but it's possible that no one help you out in that Q/A mailing list T_T. ARRRRGHHHHHHH

By the way, there are a lot of program that were written with robustness, efficiency, powerful, beautiful, or whatever good :D

Especially the active open source project like Open Office, Lynx, Inkscape, etc.

They work almost like commercial softwares.

"Linux and Open Source Software" are great!!!
But they're two-edge swards. 

If you understand what to do about them, you'll got a lot of advantages of free software :D

Within this week, I will begin introducing a bunch of free softwares I am using in my MacBook, with some easy installation tips :D for newbies (like me).

So, hope you all also enjoy my free software fever :D

HAIL THE FREE SOFTWARE!!!