Hamid Fadishei's Blog

November 25, 2010

How to revert the “make install” mess?

Filed under: Linux — fadishei @ 10:20 am
Tags: ,

Aesthetically speaking, every Makefile should provide a revert target for any target that changes the file system on the host operating system. For example a make file that provides an “install” target should also provide an “uninstall” one. Unfortunately, things are not always the way they should be. Personally I always hesitate to install applications from their sources and prefer to use the package manager on my Linux as long as it provides the application I need. But what if it does not? what if the binary in the repository is not as up-to-date as you need?

I’m aware of two ways for alleviating this shortcoming. I’d be glad if you comment me about alternate solutions though.

Method 1 – Using checkinstall application

checkinstall is an application that can build binary packages (deb, rpm etc) from your sources. Then you can easily install and of course cleanly uninstall your programs. First you need to install this utility:

$ sudo apt-get install checkinstall

Then you proceed to the normal make process but at last instead of issuing “sudo make install” you will issue “sudo checkinstall”. This will build a package and also install it:

$ cd foo
$ ./configure
$ make
$ sudo checkinstall

Later if you decide to clean your system from the package “foo” you just enter:

sudo dpkg -r foo

Method 2 – Using paco application

paco (package organizer) is another useful utility to be introduced here. It works by monitoring and logging the filesystem modifications during the installation process. Then you can use the logged information to view the installed files or uninstall them

$ sudo apt-get install paco

This time, instead of doing “make install” directly, you should request paco to do the installation:

$ cd foo
$ ./configure
$ make
$ sudo paco -lp foo "make install"

Later if you decide to clean your system from the package “foo” you just enter:

sudo paco -r foo

Remember that there is a graphical interface to paco named gpaco that may be useful to be “sudo apt-get install”ed!


September 12, 2010

Joomla! Error: the XML response that was returned from the server is invalid

Filed under: CMS,Joomla!,PHP — fadishei @ 5:36 pm

Many people get this error while they try to install Joomla! content management system. The interesting fact is that the top-in-Google forum thread about this problem, while not addressing the underlying cause properly, is locked and no further replies is possible there. Thus I will share my personal experience in this regard here.

This problem emerges when Joomla! installer can not process the XML response from the server. Many times this occurs when the response is cluttered with warning and notice messages generated by PHP. Therfore my advice is to first revisit your php.ini if you face this error message and make sure that you have the proper settings there. For me, the problem was gone as soon as I changed this line:

error_reporting = E_ALL

to this:

error_reporting = E_ALL & ~E_NOTICE

June 27, 2010

AGI Gosub Command Support in Asterisk-Java

Filed under: Asterisk,Java — fadishei @ 4:36 am

Today, I had my first experience of contributing to an open-source project. The story is that a few weeks ago when I needed to execute an AGI Gosub command, I found out this command is not implemented in Asterisk-Java yet. Thus I decided to do some coding myself. I sent the result to the project’s JIRA by opening a new feature issue. Kindly, Stefan Reuter (funder of Asterisk-Java) appreciated the work and helped me to improve it. Finally, the new Gosub command added to the SVN and will be available in the 1.0.0 release.

The Gosub Command

This command has been added to Asterisk since 1.6 version. It lets you to call a subroutine in your dialplan from AGI script. You can also pass some optional arguments to the subroutine. Although an AGI developer may find this feature useful in several situations, personally I most benefit from gosub command in indirectly calling applications for whom no dedicated AGI command is available. An example is doing a “Queue” application as exec(“Queue”, …) may not give you all the expected behavior.

As an example of using this command, consider that you have this simple subroutine in your dialplan:

exten => 190,1,AGI(agi://localhost/gosub.agi)

exten => s,1,NoOp(arg1: ${ARG1})
exten => s,n,NoOp(arg2: ${ARG2})
exten => s,n,Playback(hello-world)
exten => s,n,Return()

Then you can call this subroutine like this:

public class TestGosub extends BaseAgiScript
        public void service(AgiRequest request, AgiChannel channel) throws AgiException
                gosub("sub-hello", "s", "1", "a", "b");

As it can be seen in the code, the first three arguments to the gosub method are the context, extension, and priority you want to call. The rest of parameters are optional arguments that will be available in the subroutine as variables ${ARG1}, ${ARG2}, etc.

Some Introductory Information

For people who are not familiar with Asterisk, I would like to add the following paragraphs.

Aboute Asterisk

Asterisk is an open-source software-based PBX system that lets you do telecommunications works on a Linux box. You can build auto-attendants, call centers, help desks, IVRs, VoIP providers etc with Asterisk.

About AGI

As a programmer, you can command at your will to an Asterisk box what to do. This feature is available through a standard language for talking between Asterisk and your program known as Asterisk Gateway Interface (AGI). This feature, along with another similar functionality known as Asterisk Manager Interface (AMI) makes a software developer capable of implementing almost any imaginable telecommunications application. An example application is one that reads out your new emails to you when you call it. Another application can be an IVR that dynamically adjusts its menu items based on user requirements.

About Asterisk-Java

Asterisk-Java is a library for doing AGI from Java programs. Personally, I think Asterisk-Java turns telecommunications application development into fun!

April 26, 2010

Linux chroot: do it perfectly!

Filed under: Linux — fadishei @ 8:26 am

Today, like many other days since I know Linux, I needed to re-install Grub on a system. The problem was that I could not boot into it. The even greater problem was that I wanted to use exactly the grub-install of the same system that I could not boot into. The solution I use in the situations like this is to boot into the system using a live-cd or anything that can drop me in a simple Linux shell (even without providing the grub-install command in that shell) and then chroot into the Linux installation I want to install grub and use its grub-install.

But simply issuing a chroot command to the mounted root is not a really perfect changing of root! You should make the special filesystems available to the target root system at first. Otherwise, you may encounter an empty /dev, and empty /proc, etc after chroot. Thus the grub-install will complain that it can not find your hard disk device nodes.

So, what you should do is to make the special filesystems available to the new root after mounting it:

# mount the target root:
mount /dev/sda2 /mnt

# mount the special filesystems:
mount -o bind /proc /mnt/proc
mount -o bind /dev /mnt/dev
mount -o bind /sys /mnt/sys

# now chroot!
chroot /mnt

# mount extra partitions if you have them separate
mount /dev/sda1 /boot
mount /dev/sda5 /var

# now you shall have no problems after issuing a grub-install
grub-install /dev/sda

March 18, 2010

صعود به قله بزد

Filed under: Memoir,Persian — fadishei @ 11:04 pm

صعود به کوه بزد در حومه شهرستان تربت جام که جمعه وسط اسفند رخ داد برایم خاطره انگیز بود. چرا که باعث شد دوباره در خیابان های شهری قدم بزنم که ده سال کودکی و نوجوانی ام را آن جا بودم. باجه روزنامه ای که همیشه در اوایل دهه هفتاد به امید خریدن مجله الکترونیک با دوچرخه تا آن جا رکاب می زدم هنوز سر جایش بود. البته مثل همان زمان که همیشه تعطیل بود و مرا کنف می کرد و باید فقط جلد مجله را با حسرت از پشت شیشه اش می دیدم این دفعه هم تعطیل بود.

تعمیرگاه مهندس فخرآبادی هم که طرح کاد سال اول دبیرستان آن جا می رفتم تعطیل بود و نتوانستم این فرد نابغه را یک بار دیگر ببینم. این مهندس در دهه 60 که نفس کشیدن هم کار سختی بود چه برسد به تفریحات، شخصا در تربت جام یک ایستگاه پخش تلویزیونی دایر کرده بود که البته دولتمردان تعطیلش کردند و بدیهی است که چرا تعطیلش کردند.

دیدن آقای اباذری معلم تاریخم در کوه هم که فقط از خوش شانسی من بود. کلی خاطره از کلاس این معلم دارم. معلمی که خیلی از خطوط قرمز رایج را قبول نداشت و می گذاشت در مباحث کلاس راحت از رویشان ویراژ رد شویم و به جای آن خطوط قرمز انسانیت را به ما می آموخت.

از تربت جام به سمت بزد نرسیده به روستا در سمت راست یک فرعی هست که تو را تا پای کوه می برد. انتهای راه و شروع کوه را این عکس نشان می دهد:

بعد از اندکی صعود، تنوع رنگ مسحور کننده ای در پوشش گیاهی به چشم می خورد:

و با ادامه صعود کم کم برف ها نمایان می شوند:

و اندکی بالاتر فقط برف است و برف:

در مسیر این صعود 3000 متری دو جانپناه وجود دارد. اولی در حدود 15 سال قبل ساخته شده و جان پناه دومی که با امکانات پیشرفته و عایق کاری ساخته شده و دارای امکانات اولیه زندگی و برق بادی است در قله قرار دارد. البته باد دکل ژنراتورش را شکسته بود و برق نداشت. این تصویر جان پناه دوم در قله است و همان طور که می بینید آن بالا اوضاع جوی با پایین خیلی متفاوت است و به طور خلاصه توصیفش این طور است که دانه های برف به صورت آدم سیلی می زنند:

جانپناه اول را من افتخار دارم که در مراحل تکمیلش یک آجرش را تا آن بالا بردم. البته کار سختی بود در سن کودکی ولی الان که می بینم خیرش هر هفته به ده ها آدم می رسد خیلی خرسندم. به قول خدا «و هر کس به اندازه مثقال ذره ای کار خوب کند اثرش را می بیند».

January 5, 2010

Spring Load-time Weaving on Tomcat: Does It Really Work?

Filed under: Java,Spring,Tomcat — fadishei @ 5:44 am

Are you frustrated in making the Spring load-time weaving (LTW) work on Tomcat application server? Then keep reading as the process is explained below.

Inversion of Control

Spring is an “Inversion of Control” (IoC) container. IoC lets the developers of a class (bean) relax from thinking how to satisfy the dependencies for the class. Dependencies will be “injected” into the bean by the container.  For example, a bean may need to be a client of a web service. Then the developer does not have to think about how to get the stub for the web service. The only thing he has to do is to provide a means to get the dependency from the container, for example by providing the container with a property setter for the stub, and take it for granted. More information about IoC and DI can be found here.

Load-Time Weaving

Sometimes, your beans are created outside of the container. Then, the framework can not simply inject their dependencies. One solution is to get the dependencies yourself by making your bean “application-context-aware”. However, this will result in foregoing the IoC. Another solution is to make your bean @Configurable and use weaving to inject the dependencies at load-time, or at compile-time. More information on LTW in Spring can be found here.

The Environment

Spring framework has recently released the stable 3.0 version. I use this version in this tutorial, along with Tomcat 6.0 as the applications server. The source code as an Eclipse project can be found here. This is a very simple web application which will say hello to a name that is specified as a bean property in the spring context. The property will be injected using load-time weaving.

Step 1- Project Dependencies

The needed libraries for running the example:


Step 2- Make the Bean Configurable

This code shows how I made my ultra-simple Person bean configurable:

package ir.fadishei.test.ltw;

import org.springframework.beans.factory.annotation.Configurable;

public class Person
	private String name;

	public String getName()
		return name;

	public void setName(String name)
		this.name = name;

	public String toString()
		return name;

Step 3- The Spring Context

Here is the simplistic configuration:


	<context:spring-configured />
	<context:load-time-weaver aspectj-weaving="autodetect"/>

	<bean class="ir.fadishei.test.ltw.Person" scope="prototype">
		<property name="name" value="Timon"/>


Step 4- Change the Tomcat Class Loader

Somtimes people fail to make LTW work on Tomcat by missing this step. The default Tomcat class loader does not support class transformation. You’ll need to use the one provided by Spring. First you should copy the spring.instrument.tomcat-3.0.0.jar to the lib folder of your tomcat installation. then use this context.xml to tell the web application server to use the new class loader:

<Context path="/ltwdemo">
    <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>

Step 5- Run

Run the web server and browse the following page. You should see the Hello <name>! message, in which name should be what provided in the bean definition.


The source code of this tutorial as an Eclipse project

January 4, 2010

Hello world!

Filed under: Uncategorized — fadishei @ 4:06 pm
public class Hello
	public static void main(String args[])
« Previous Page

Blog at WordPress.com.