11/12/08

monitor your filesystem events with inotify-tools

I looking for the way to mirror files on my server to others when something're updated and found that inotify is a good idea in this case.
Thanks for inotify-tools project, c library and set of command line programs for linux provide interface to inotify, that let me avoid from c code.

On ibex, i get it by..

pnix@pnix-a7n:~$ sudo aptitude install inotify-tools
[sudo] password for pnix:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
The following NEW packages will be installed:
inotify-tools libinotifytools0{a}
0 packages upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 39.0kB of archives. After unpacking 201kB will be used.
Do you want to continue? [Y/n/?] y
...
Writing extended state information... Done

pnix@pnix-a7n:~$

Below is example shell script i use to moniter and update file to remote host.
#!/bin/bash
while inotifywait -rq -e close_write /folder_to_moniter; do
rsync -av /folder_to_moniter -e "ssh -l pnix" pnix@remotehost:/home/pnix/tmp
done

for Java api look here

11/1/08

Many sound problems on Intrepid ibex

I upgrade two ibex last night and found few sound problems below

First, on video file(mpg,avi ..), when right click and choose >open with >mplayer. will bring up error " [AO_ALSA] Unable to find simple control 'PCM',0 ".
I'm not sure what it is, maybe the config just is not right but I fix this by right click on movie window-> preference then on audio tab, select 'Enable Software Mixer'. [or you can do this by change 'softvol = "no"' to 'softvol = "yes"' in $HOME/.mplayer/gui.conf]

Another sound issue is flash player on web[like youtube] not play sound. /var/log/message said

pnix@pnix-a7n:_NHDT392$ tail -f /var/log/messages
...
Nov 2 00:33:14 pnix-a7n -- MARK --
Nov 2 00:40:51 pnix-a7n pulseaudio[23941]: sink-input.c: Failed to create sink input: too many inputs per sink.
Nov 2 00:40:51 pnix-a7n last message repeated 31 times
Nov 2 00:40:51 pnix-a7n pulseaudio[23941]: protocol-native.c: Warning! Too many connections (64), dropping incoming connection.
and after run flash, no sound from other application too. I saw bug report for this issue on lunchpad here but no solution for me. I have to kill and restart pulseaudio like this to get sound back.
pnix@pnix-a7n:~$ pulseaudio -k
W: ltdl-bind-now.c: Failed to find original dlopen loader.
pnix@pnix-a7n:~$ ps aux|grep pulseaudio
pnix 2510 0.0 0.0 3236 796 pts/0 S+ 04:14 0:00 grep pulseaudio
pnix@pnix-a7n:~$ pulseaudio -D
W: ltdl-bind-now.c: Failed to find original dlopen loader.
pnix@pnix-a7n:~$ ps aux|grep pulseaudio
pnix 2513 3.0 0.3 28952 3952 ? Ssl 04:14 0:00 pulseaudio -D
pnix 2516 0.0 0.2 7528 2516 ? S 04:14 0:00 /usr/lib/pulseaudio/pulse/gconf-helper
pnix 2518 0.0 0.0 3236 792 pts/0 S+ 04:14 0:00 grep pulseaudio
pnix@pnix-a7n:~$

9/24/08

Fixing shutdown problem in hardy

For a long time my ubuntu box can't shutdown properly(not sure when this start to happen may be since upgrade to gusty). Shutdown progress bar will stop running, harddrive already stop spinning and hang. I guess it because my kernel option "acpi=off nolapic irqpoll" in /boot/grub/menu.lst without these option shutdown script work perfect. So, why i need that??
I just found the way to fix this from ubuntuforums. This is not new, many guy has this problem and it fixed. To solve this problem [for me]

1.add "apm=power_off" to kernel option.
2.add "apm power_off=1" to /etc/modules

Reboot and try shutdown again this time it work perfect.

Bootchart on Ubuntu hardy

Today I'm searching for a way to make my box boot up faster and found this tool. Bootchart can use for analyze and visualization boot process.
To install bootchart.

pnix@pnix-a7n:~$ sudo aptitude install bootchart
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
Building tag database... Done
The following NEW packages will be automatically installed:
librsvg2-bin
The following NEW packages will be installed:
bootchart librsvg2-bin
0 packages upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 121kB of archives. After unpacking 324kB will be used.
Do you want to continue? [Y/n/?] y
Writing extended state information... Done
Get:1 http://mirror1.ku.ac.th hardy/main librsvg2-bin 2.22.2-2 [21.3kB]
Get:2 http://mirror1.ku.ac.th hardy/main bootchart 0.9-0ubuntu7 [99.8kB]
Fetched 121kB in 1s (90.6kB/s)
...
Building tag database... Done
pnix@pnix-a7n:~$

then reboot to see the result[in /var/log/bootchart].

Mine take about 34 seconds to boot. Not too bad for six years old box(Athlon XP 1700+, A7N8X-E deluxe, 1G Memory, SATA), but I want faster.
From graph I found few process i install long time ago, and some default configure to autoboot. e.g. avahi-daemon, cvsd, laptop-mode[powernowd], smokeping, winbind.
So, take it out with rcconf, reboot again and see the result.

30 seconds wow I safe 4 sec.

6/19/08

Setup MySQL with Ofbiz

Download ofbiz weekily build and extract it somewhere you want. From your ofbiz directory, edit file entityengine.xml in framework/entity/config
add new datasources below localmysql datasource part

    <datasource name="custommysql"
helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"
field-type-name="mysql"
check-on-start="true"
add-missing-on-start="true"
check-pks-on-start="false"
use-foreign-keys="true"
join-style="ansi-no-parenthesis"
alias-view-columns="false"
drop-fk-use-foreign-key-keyword="true"
table-type="InnoDB"
character-set="latin1"
collate="latin1_general_cs">
<read-data reader-name="seed"/>
<read-data reader-name="seed-initial"/>
<read-data reader-name="demo"/>
<read-data reader-name="ext"/>
<inline-jdbc
jdbc-driver="com.mysql.jdbc.Driver"
jdbc-uri="jdbc:mysql://localhost/ofbiz"
jdbc-username="ofbizuser"
jdbc-password="mypass"
isolation-level="ReadCommitted"
pool-minsize="2"
pool-maxsize="250"/>
<!-- <jndi-jdbc jndi-server-name="localjndi" jndi-name="java:/MySqlDataSource" isolation-level="Serializable"/> -->
</datasource>
<datasource name="custommysqlolap"
helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"
field-type-name="mysql"
check-on-start="true"
add-missing-on-start="true"
check-pks-on-start="false"
use-foreign-keys="true"
join-style="ansi-no-parenthesis"
alias-view-columns="false"
drop-fk-use-foreign-key-keyword="true"
table-type="InnoDB"
character-set="latin1"
collate="latin1_general_cs">
<read-data reader-name="seed"/>
<read-data reader-name="seed-initial"/>
<read-data reader-name="demo"/>
<read-data reader-name="ext"/>
<inline-jdbc
jdbc-driver="com.mysql.jdbc.Driver"
jdbc-uri="jdbc:mysql://localhost/ofbizolap?autoReconnect=true"
jdbc-username="ofbizuser"
jdbc-password="mypass"
isolation-level="ReadCommitted"
pool-minsize="2"
pool-maxsize="250"/>
<!-- <jndi-jdbc jndi-server-name="localjndi" jndi-name="java:/DerbyDataSource" isolation-level="ReadCommitted"/> -->
</datasource>

change the "default" delegator make it look like this
<delegator name="default" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main" distributed-cache-clea$
<group-map group-name="org.ofbiz" datasource-name="custommysql"/>
<group-map group-name="org.ofbiz.olap" datasource-name="custommysqlolap"/>
</delegator>


put mysql driver under framework/entity/lib/jdbc
[admin@localhost ofbiz]$ ls framework/entity/lib/jdbc
derby-10.4.1.3.jar mysql-connector-java-5.1.6-bin.jar
[admin@localhost ofbiz]$


prepare database <create database ,grant user>
mysql> create database ofbiz;
Query OK, 1 row affected (0.05 sec)

mysql> create database ofbizolap;
Query OK, 1 row affected (0.05 sec)

mysql> grant all on *.* to 'ofbizuser'@'localhost' identified by 'mypass';
Query OK, 0 rows affected (0.03 sec)

mysql>


now we're ready to run ant to load database into mysql. Let's go.
[admin@localhost ofbiz]$ ./ant run-install
...
[java] 2008-06-19 10:59:06,245 (main) [ ContainerLoader.java:114:INFO ] Shutting down containers

BUILD SUCCESSFUL
Total time: 5 minutes 25 seconds
[admin@localhost ofbiz]$

6/18/08

Cannot use SUN rmic, as it is not available.

I download ofbiz weekly build[ofbiz_20080602.zip] from sourceforge and try to build it on eclipse. How to config on eclipse? How to use ofbiz with external database? you can find out from google or may be I'll post here later.:P
This post is about error when I run ant build target 'run-install' to load configured data. Below error'll show on eclipse console.

...
stubs:
[rmic] RMI Compiling 1 class to D:\eclipse_workspace\ofbiz2\framework\service\build\classes

BUILD FAILED
D:\eclipse_workspace\ofbiz2\build.xml:125: The following error occurred while executing this line:
D:\eclipse_workspace\ofbiz2\framework\build.xml:142: The following error occurred while executing this line:
D:\eclipse_workspace\ofbiz2\framework\service\build.xml:101: Cannot use SUN rmic, as it is not available. A common solution is to set the environment variable JAVA_HOME or CLASSPATH.

Total time: 8 seconds

I solve this by browse to Window->Preferences->Ant->Runtime then highlight on 'Global Entries', click 'Add Externals JARs' then select tools.jar from your $JAVA_HOME/lib directory. Try run ant build again then it sould be fine.

6/5/08

Compile subversion on Fedora core 6

I just move to new company. My first job here is setup a svn on FC6 box. This post is about how i built it.
First download, compile and install apache[must be 2.0 version to have same apr version as subversion-deps-1.4.6.tar.bz2]

[root@localhost ~]# wget http://mirrors.issp.co.th/apache/httpd/httpd-2.0.63.tar.bz2
...
[root@localhost ~]# tar xjf httpd-2.0.63.tar.bz2
[root@localhost ~]# cd httpd-2.0.63
[root@localhost httpd-2.0.63]# ./buildconf
[root@localhost httpd-2.0.63]# ./configure --enable-dav --enable-so --enable-maintainer-mode --prefix=/usr/local/apache20
...
[root@localhost httpd-2.0.63]# make && make install
...
[root@localhost httpd-2.0.63]# cd ..
[root@localhost ~]#

then download subversion source code and the subversion dependencies source code, extract both then go to compile and install apr, apr-util, neon and subversion itself.
[root@localhost ~]# wget http://subversion.tigris.org/downloads/subversion-1.4.6.tar.bz2
...
[root@localhost ~]# wget http://subversion.tigris.org/downloads/subversion-deps-1.4.6.tar.bz2
...
[root@localhost ~]# tar xjf subversion-1.4.6.tar.bz2
[root@localhost ~]# tar xjf subversion-deps-1.4.6.tar.bz2
[root@localhost ~]# cd subversion-1.4.6/apr
[root@localhost apr]# ./configure --prefix=/usr/local/apr
...
[root@localhost apr]# make && make install
...
[root@localhost apr]# cd ../apr-util
[root@localhost apr-util]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
...
[root@localhost apr-util]# make && make install
...
[root@localhost apr-util]# cd ../neon
[root@localhost neon]# ./configure --prefix=/usr/local/neon
...
[root@localhost neon]# make && make install
...
[root@localhost neon]# cd ..
[root@localhost subversion-1.4.6]# ./configure --prefix=/usr/local/subversion --with-apxs=/usr/local/apache20/bin/apxs --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-neon=/usr/local/neon/ --with-ssl
...
[root@localhost subversion-1.4.6]# make && make install
...
[root@localhost subversion-1.4.6]#

now subversion is already installed, add apache user
[root@localhost subversion-1.4.6]# groupadd apache
[root@localhost subversion-1.4.6]# useradd -g apache -d /usr/local/apache20
[root@localhost subversion-1.4.6]# chown -Rv apache.apache /usr/local/apache20

edit /usr/local/apache2/conf/httpd.conf change..
User nobody
Group #-1

to
User apache
Group apache

and add this code to end of file.
<Location /subversion>
DAV svn
SVNPath /usr/local/subversion/repository/
AuthType Basic
AuthName "Subversion repository"
AuthUserFile /usr/local/subversion/repository/conf/svn-auth-file
Require valid-user
</Location>

create password with this command
/usr/local/apache20/bin/htpasswd -cmd /usr/local/subversion/repository/conf/svn-auth-file {user-name}

create a repository
[root@localhost ~]# mkdir -v /usr/local/subversion/repository
[root@localhost ~]# svnadmin create --fs-type fsfs /usr/local/subversion/repository
[root@localhost ~]#

Last to test I will try import some file to repos.
[root@localhost src]# touch source1
[root@localhost src]# touch source2
[root@localhost src]# ls
source1 source2
[root@localhost src]# svn -m "initial import to svn" import . http://127.0.0.1/subversion/
Authentication realm: Subversion repository
Password for 'root':
Authentication realm: Subversion repository
Username: swd
Password for 'swd':
svn: Can't create directory '/usr/local/subversion/repository/db/transactions/0-1.txn': Permission denied

uhh.. you need to make apache user can access all the files in the repository.
[root@localhost src]# chown -R apache.apache /usr/local/subversion/repository
[root@localhost src]# chmod g+s /usr/local/subversion/repository/db
[root@localhost src]# svn -m "initial import to svn" import . http://127.0.0.1/subversion/
Authentication realm: Subversion repository
Password for 'root':
Authentication realm: Subversion repository
Username: swd
Password for 'swd':
Adding source1
Adding source2

Committed revision 1.
[root@localhost src]#

That's all. You can browse repos. via url 'http://127.0.0.1/subversion/'.

5/15/08

Try Asterisk on Ubuntu Hardy

I try install asterisk server on ubuntu hardy from repos. The 'asterisk-sounds-extra' is for testing sound[locate in /usr/share/asterisk/sounds/].

pnix@v400ast:~$ sudo aptitude install asterisk  asterisk-sounds-extra
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
Building tag database... Done
The following NEW packages will be automatically installed:
asterisk-config asterisk-sounds-main build-essential debhelper dpkg-dev g++ g++-4.2
gettext html2text intltool-debian libc-client2007 libc6-dev libcompress-raw-zlib-perl
libcompress-zlib-perl libct3 libdigest-hmac-perl libdigest-sha1-perl libfile-remove-perl
libgsm1 libiksemel3 libio-compress-base-perl libio-compress-zlib-perl libio-stringy-perl
libmail-box-perl libmail-sendmail-perl libmailtools-perl libmime-types-perl
libobject-realize-later-perl libpq5 libpri1.0 libradiusclient-ng2 libstdc++6-4.2-dev
libtimedate-perl libtonezone1 libuser-identity-perl libvpb0 linux-libc-dev mlock
module-assistant odbcinst1debian1 patch po-debconf unixodbc vpb-driver-source
The following NEW packages will be installed:
asterisk asterisk-config asterisk-sounds-extra asterisk-sounds-main build-essential
debhelper dpkg-dev g++ g++-4.2 gettext html2text intltool-debian libc-client2007
libc6-dev libcompress-raw-zlib-perl libcompress-zlib-perl libct3 libdigest-hmac-perl
libdigest-sha1-perl libfile-remove-perl libgsm1 libiksemel3 libio-compress-base-perl
libio-compress-zlib-perl libio-stringy-perl libmail-box-perl libmail-sendmail-perl
libmailtools-perl libmime-types-perl libobject-realize-later-perl libpq5 libpri1.0
libradiusclient-ng2 libstdc++6-4.2-dev libtimedate-perl libtonezone1
libuser-identity-perl libvpb0 linux-libc-dev mlock module-assistant odbcinst1debian1
patch po-debconf unixodbc vpb-driver-source
0 packages upgraded, 46 newly installed, 0 to remove and 0 not upgraded.
Need to get 23.5MB of archives. After unpacking 73.8MB will be used.
Do you want to continue? [Y/n/?] y
...
Building tag database... Done
pnix@v400ast:~$

After finish, try to connect to asterisk
pnix@v400ast:~$ sudo asterisk -rvvv
Asterisk 1.4.17~dfsg-2ubuntu1, Copyright (C) 1999 - 2007 Digium, Inc. and others.
Created by Mark Spencer
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
This package has been modified for the Debian GNU/Linux distribution
Please report all bugs to http://bugs.debian.org/asterisk
=========================================================================
== Parsing '/etc/asterisk/asterisk.conf': Found
== Parsing '/etc/asterisk/extconfig.conf': Found
Connected to Asterisk 1.4.17~dfsg-2ubuntu1 currently running on v400ast (pid = 5041)
Verbosity is at least 3
v400ast*CLI>

Well.. basic installation is very smooth. I try adding sip account and test dialplan to play 'welcome' sound and it working fine too. May be i will use this to be my production server instead of trixbox if I succeed on compiling rhino driver on ubuntu.

Fixing sendmail take a long time to start

I notice that my database box[FC6+Oracle10.2] take along time to startup. Sendmail and sm-client very very slow to start[ about 5 minutes ]. There's something wrong in /etc/hosts file. 'newalises' command take long time to update and finish with error below.

[root@ora10g ~]# newaliases
WARNING: local host name (ora10g) is not qualified; see cf/README: WHO AM I?
/etc/aliases: 76 aliases, longest 10 bytes, 765 bytes total
[root@ora10g ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
192.168.1.55 ora10g
[root@ora10g ~]#

To fix this, custom hostname[ora10g] need to append to localhost line in /etc/hosts.
[root@ora10g ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost ora10g
192.168.1.55 ora10g
[root@ora10g ~]# newaliases
/etc/aliases: 76 aliases, longest 10 bytes, 765 bytes total
[root@ora10g ~]#

5/9/08

Using Datapump on oracle 10g to export/import

This will be update version of this post if you are using oracle 10g or 11g.

Last month I post about export/import data in oracle using exp,imp utility. Actually oracle has something newer and better performance if you're using 10g or 11g.

Assume that we want to export one table from one oracle db and import it into another oracle db. So create the folder /home/oracle/dbbackup on two oracle db server to store <.dmp> file[that will be created when exporting and importing].

Next, we need to tell oracle to know this folder, create directory on both db by run command below in sqlplus
SQL> create directory dmpdir as '/home/oracle/dbbackup';

Directory created.

SQL>

Now on source database export table with command below.
[oracle@k8n ~]$ expdp username/password DIRECTORY=dmpdir DUMPFILE=filename.dmp TABLES=tablename

Export: Release 10.1.0.3.0 - Production on Friday, 09 May, 2008 10:54
...
[oracle@k8n ~]$

after finish you will have filename.dmp in /home/oracle/dbbackup, ftp it to the target box make sure you are using binary mode.
Then on target database import the table like this.
[oracle@dbp4 ~]$ impdp username/password DIRECTORY=dmpdir DUMPFILE==filename.dmp TABLES=tablename

Import: Release 10.2.0.1.0 - Production on Friday, 09 May, 2008 11:02:27
...
[oracle@dbp4 ~]$

That's it. Note that up there exporting from 10.1.0.3.0 and importing into 10.2.0.1.0 is ok but down version import[e.g. expdp with higher version and impdp with lower version]is not, you will get error like this
ORA-39001: invalid argument value
ORA-39000: bad dump file specification
ORA-31619: invalid dump file "/home/oracle/dbbackup/filename.dmp"

To fix this error, expdp command must append with 'version=10.target.version'.

more detail about expdp/impdp tool
expdp help=yes
impdp help=yes

5/6/08

Single user mode in fedora core

Again that electricity in area of Sukhumvit road, Bangkok down yesterday night. This time one database refuse to boot it freeze at "Starting system logger:". Look like there's no way to get a shell from any normal run level startup.

Not like ubuntu that has recovery mode in grub menu. This box is fedora core, I know there's a way to get in to single user mode by pass kernel parameter at grub boot menu [but can not remember how to at that time:(].

After some googling I found the way. To get single user mode in FC, at grub menu press a [to append kernel parameter]. Now add s to tell fedora kernel that you want single user mode. After finish, enter to continue booting.

Now you will get root shell and can figure out what wrong with your system then fix it. In my case now I just want Oracle to come up so i need atleast two service 'network' and 'oracle'. Try to bring it up by run these two command and pray.

sh-3.00# service network start
sh-3.00# service oracle start

Not too bad that this time network and oracle are come up successfully:). But why syslogd startup caused system freeze is still no idea:(.

4/29/08

Toggle btw compiz&metacity with fusion-icon in Ubuntu Hardy


Since gusty, compiz-fusion will start by default. I love eye candy but for resource shortage reason on my old box, sometime i need to switch to metacity. with alt-f2 and run 'metacity replace' is just work but not convenion. Thank for Tom that point me . Fusion-icon is use to switch between compiz and metacity window manager. For hardy, fusion-icon is in repos. installation is easy like

pnix@pnix-a7n:~$ sudo aptitude install fusion-icon
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
Building tag database... Done
The following NEW packages will be installed:
fusion-icon
0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 29.8kB of archives. After unpacking 270kB will be used.
...
Building tag database... Done
pnix@pnix-a7n:~$

Running:
alt-F2 and type 'fusion-icon -n' or if you want this everytime logging in add 'fusion-icon -n' to 'Sessions preference' in System->Preferences->Sessions.

4/28/08

sudo: timestamp too far in the future

I just finish build the new hardy box at my office. then I go to open the file '/etc/network/interfaces' to add internal ip address and forget something. When I try to open it again, I got this.

pnix@hardy-dev:~$ sudo nano /etc/network/interfaces
sudo: timestamp too far in the future: Apr 29 01:41:32 2008
pnix@hardy-dev:~$ date
Mon Apr 28 18:48:21 ICT 2008
pnix@hardy-dev:~$
I'm not sure why this happen may be some parts of the system using UTC, other parts using timezone-adjusted time. To fix this try code below to clear timestamp.
pnix@hardy-dev:~$ sudo -k
pnix@hardy-dev:~$ sudo nano /etc/network/interfaces
[sudo] password for pnix:

4/26/08

Are you Hardy??

Ubuntu 8.04 LTS code name Hardy Heron just released yesterday. Until now the server still busy, network upgrade[for me] need about 9xx MB download and will take about 1 days and something to do that[on 1mb ADSL from Thailand can you believe? :P].

So I try go for alternative CD. This is pretty much help, download time[for CD] reduce to 2 hours for 700MB. After burning, pop it into CD Drive, it will ask about "Do I want latest pakage from internet?". "Yes" will need more 300MB to download. Anyway it'not a day, estimate time are about 2-3 hours for upgrading.

Hope that tomorow I will see hardy desktop on my box.

4/22/08

R4FXO channel did not hang up

Last time, configure r4fxo on trixbox using genzaptelconf command will generate zapata-channels like this.


;;; line="4 FXO/1/3 FXSKS (In use)"
signalling=fxs_ks
callerid=asreceived
group=0
context=from-pstn
channel => 4
context=default

This look ok except context is set to 'from-pstn', I can make outbound and inbound call with out any problem except the call will never hang up!!!. To fix this problem[from this post], change 'context=from-pstn'[bold above] to 'context=from-zaptel'.

4/16/08

Running Oracle DBCA(Database Confguration Assistance) remotely

There are two ways to create a new database on existing oracle db server. One is using 'CREATE DATABASE' sql statement[this is too long,hard for me]. Another is using DBCA(Database Confguration Assistance), GUI Base Program. This way is more easy and I choose this way:). One note here is DBCA need X to run and I want to remote login to db server and run dbca from ssh, so ssh need '-X' for X11 forward[assume that DISPLAY variable on server is set, if not try 'export DISPLAY=localhost:0.0' on the server].

[poj@fedev ~]$ ssh -X -l oracle 192.168.1.59
oracle@192.168.1.59's password:
Last login: Wed Apr 16 15:11:14 2008 from 192.168.1.122
/usr/X11R6/bin/xauth: creating new authority file /home/oracle/.Xauthority
[oracle@k8n ~]$ cd /u01/app/oracle/product/10.1.0/db_1/bin
[oracle@k8n bin]$ dbca

4/7/08

export,import data in oracle with exp/imp command

One of database box hang today. It doesn't let me ssh to see what happen, so I just shut it down and try to reboot again. But during boot process, I got "Kernel panic: VFS: Unable to mount root fs on...". err.. look like the disk is gone.
Anyway, after few time of cold boot it give me a chance to backup my data:). I don't need all data in database[too many outdate data], so I decide to move some importance table to another database. Oracle has exp and imp utility to do this job. To export table test123 to file test123.dmp type follwing command.

[oracle@Oracle-1 oracle]$ exp username/password TABLES=test123 FILE=test123.dmp

Export: Release 8.1.7.0.1 - Production on Mon Apr 7 13:22:01 2008

(c) Copyright 2000 Oracle Corporation. All rights reserved.


Connected to: Oracle8i Enterprise Edition Release 8.1.7.0.1 - Production
With the Partitioning option
JServer Release 8.1.7.0.1 - Production
Export done in US7ASCII character set and US7ASCII NCHAR character set

About to export specified tables via Conventional Path ...
. . exporting table TEST123 1 rows exported
Export terminated successfully without warnings.
[oracle@Oracle-1 oracle]$

then ftp dump file[test123.dmp] to new database[make sure that using binary on transfer]. To import dump file into new database see below.
[oracle@ora10g ~]$ imp username/password FILE=test123.dmp fromuser=username touser=username

Import: Release 10.1.0.3.0 - Production on Mon Apr 7 13:29:40 2008

Copyright (c) 1982, 2004, Oracle. All rights reserved.


Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options

Export file created by EXPORT:V08.01.07 via conventional path
import done in WE8ISO8859P1 character set and AL16UTF16 NCHAR character set
export client uses US7ASCII character set (possible charset conversion)
export server uses US7ASCII NCHAR character set (possible ncharset conversion)
. . importing table "TEST123" 1 rows imported
Import terminated successfully without warnings.
[oracle@ora10g ~]$


note: when move data DOWN a version(s). you may need to export using that lower versions EXP tool and IMP using that lower versions tool.[more detail]

3/27/08

Talk to asterisk with Asterisk-java

I just found the java way to talk to my trixbox. With Asterisk-java you can handle call from asterisk server via the FastAGI protocal, use the Manager api to connect to Asterisk server, send action and handle event. Last the Live api instead of using actions and events like the Manager api it use active domain objects (live objects) that represent Asterisk concepts like a channel or an extension.

more example on tutorial page.

3/26/08

Adding ip address on trixbox[without X]

On Ubuntu, to manage ip address of the box in console, we need to edit /etc/network/interfaces. By default ubuntu is set to using dhcp as you will see.

auto eth0
iface eth0 inet dhcp

changing "dhcp" to "static" and add network information
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1

will change the box to use static ip address. Adding more ip address on this interface can be done by add script below to the same "interfaces" file.[note that we have :1 after eth0]
auto eth0:1
iface eth0:1 inet static
address 192.168.1.109
netmask 255.255.255.0
broadcast 192.168.1.255

Trixbox use centos. Like other redhat family, it has system-config-network utility or if you want to play with the configuration file, adding ip address is done by create new file in /etc/sysconfig/network-scripts like in mycase. I have external static ip address define in ifcfg-eth0.
[trixbox1.localdomain ~]# cd /etc/sysconfig/network-scripts
[trixbox1.localdomain network-scripts]# ls ifcfg-eth0
ifcfg-eth0
[trixbox1.localdomain network-scripts]#

Now, I want to add new internal ip to this interface so I create a new file call "ifcfg-eth0:1" by copy from "ifcfg-eth0".
[trixbox1.localdomain network-scripts]# cp ifcfg-eth0 ifcfg-eth0:1
[trixbox1.localdomain network-scripts]#

then modify "ifcfg-eth0:1" made it look like this.
[trixbox1.localdomain network-scripts]# cat ifcfg-eth0:1
DEVICE=eth0:1
BOOTPROTO=none
IPADDR=192.168.1.123
NETMASK=255.255.255.0
TYPE=Ethernet
[trixbox1.localdomain network-scripts]#

last restart network service and check the result.
[trixbox1.localdomain network-scripts]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
[trixbox1.localdomain network-scripts]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:E0:4C:84:26:BB
.....

eth0:1 Link encap:Ethernet HWaddr 00:E0:4C:84:26:BB
inet addr:192.168.1.123 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:11 Base address:0xe000

lo Link encap:Local Loopback
.....

[trixbox1.localdomain network-scripts]#

3/21/08

R4FXO card Installation note

Last year I have played with trixbox for two week and leave it sit under my desk for a long time. Last week I just got a new card to play with. It's Rhino R4FXO[4 FXO ports]. My goal now is make trixbox know the card and config it properly. I start with reinstall trixbox with the almost latest version[trixbox ce 2.4.2]. Upgrade all packages[Include zaptel driver 1.4.9.2-4]

note: this zaptel driver is not work with current rhino driver in repos[for now 21/03/08]. It need to manual download the driver and install from console[more detail]

After base system is ready. Install R4FXO card.
1. Shutdown the box.
2. Put R4FXO card to the pci slot.

Boot trixbox again and run command 'genzaptelconf' to generate configuration files automatically. The config file is '/etc/zaptel.conf' and '/etc/asterisk/zapata-chanels.conf'. mine is look like this.

[trixbox1.localdomain ~]# cat /etc/asterisk/zapata-channels.conf
; Autogenerated by /usr/sbin/genzaptelconf -- do not hand edit
; Zaptel Channels Configurations (zapata.conf)
;
; This is not intended to be a complete zapata.conf. Rather, it is intended
; to be #include-d by /etc/zapata.conf that will include the global settings
;

; Span 1: Rhino RCB4FXO/1 "Rhino RCB4FXO/1" (MASTER)
;;; line="1 FXO/1/0 FXSKS (In use)"
signalling=fxs_ks
callerid=asreceived
group=0
context=from-pstn
channel => 1
context=default

;;; line="2 FXO/1/1 FXSKS (In use)"
signalling=fxs_ks
callerid=asreceived
group=0
context=from-pstn
channel => 2
context=default

;;; line="3 FXO/1/2 FXSKS (In use)"
signalling=fxs_ks
callerid=asreceived
group=0
context=from-pstn
channel => 3
context=default

;;; line="4 FXO/1/3 FXSKS (In use)"
signalling=fxs_ks
callerid=asreceived
group=0
context=from-pstn
channel => 4
context=default

[trixbox1.localdomain ~]# cat /etc/zaptel.conf
# Autogenerated by /usr/sbin/genzaptelconf -- do not hand edit
# Zaptel Configuration File
#
# This file is parsed by the Zaptel Configurator, ztcfg
#

# It must be in the module loading order


# Span 1: Rhino RCB4FXO/1 "Rhino RCB4FXO/1" (MASTER)
fxsks=1
fxsks=2
fxsks=3
fxsks=4

# Global data

loadzone = us
defaultzone = us
[trixbox1.localdomain ~]#
note that from zapata-channels.conf I have 1 group call group0 compose of channel "1","2","3" and "4". [These channels and group are used when creat trunk]

reload new configuration and see the result by 'ztcfg -vvv'.
[trixbox1.localdomain ~]# ztcfg -vvv

Zaptel Version: 1.4.9.2-
Echo Canceller: Oslec
Configuration
======================


Channel map:

Channel 01: FXS Kewlstart (Default) (Slaves: 01)
Channel 02: FXS Kewlstart (Default) (Slaves: 02)
Channel 03: FXS Kewlstart (Default) (Slaves: 03)
Channel 04: FXS Kewlstart (Default) (Slaves: 04)

4 channels to configure.

[trixbox1.localdomain ~]#
From above message all 4 channels are configured as FXS_KS signaling, that means they will act as FXO ports.

Use 'zttool' command to check status of R4FXO.

Adding these two properties in the /etc/asterisk/zapata.conf file under the [channels] section will enable busy detect on the system.
busydetect=yes
busycount=5

and that's it. next thing to do is create a zap trunk to connect outside world.

3/18/08

Shadow Text Effect on JLabel

I found the trick to create shawdow text on JLabel from java forum. Instead of use JLabel.setText() set string to JLabel, he create Image and get Graphics2D by Image.createGraphics(). Then use TextLayout draw overlapping string on that Graphics2D.
example code

        int w = 500;
int h = 120;
Font font = new Font("Lucida Bright", Font.ITALIC, 72);
String text = "Shadow Text";

BufferedImage image = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
adjustGraphics(g);

//start off all white:
g.setPaint(Color.WHITE);
g.fillRect(0, 0, w, h);

//draw "shadow" text: to be blurred next
TextLayout textLayout = new TextLayout(text, font, g.getFontRenderContext());
g.setPaint(new Color(128,128,255));
textLayout.draw(g, 15, 105);
g.dispose();

//blur the shadow: result is sorted in image2
float ninth = 1.0f / 9.0f;
float[] kernel = {ninth, ninth, ninth, ninth, ninth, ninth, ninth, ninth, ninth};
ConvolveOp op = new ConvolveOp(new Kernel(3, 3, kernel), ConvolveOp.EDGE_NO_OP, null);
BufferedImage image2 = op.filter(image,null);

//write "original" text on top of shadow
Graphics2D g2 = image2.createGraphics();
adjustGraphics(g2);
g2.setPaint(Color.BLACK);
textLayout.draw(g2, 10, 100);
....
private void adjustGraphics(Graphics2D g) {
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
}


Last use JLabel.setIcon(new ImageIcon(image2)) to display text with a shadow. Lower label is created by method show here, the result is look very good to me.

3/14/08

using Class.getResource() load resource file in Eclipse

There are many ways to load resource file in java app. What sun recommended is using Class.getResource("resource_name") or Class.getResourceAsStream("resource_name") then you will get URL and InputStream respectively. If resource_name is specified without "/", it will be prepend with Class package. So resource file must be in same place[folder structure] as the Class. What I love to do is call getResource() with "/" and put resource file at the root of package. This way i can have separate resource folder. below is in Eclipse,

1. From Package explorer right click src folder->click import
2. In import dialog, Choose General->File System ->next
3. from directory:->Browse to your resource folder.
4. to folder:-> I add "resource" as a folder name under src folder. then click "Finish".

In the code, load resource with

this.getClass().getResource("/resource/buttons1.png")
or
this.getClass().getResourceAsStream("/resource/TX_Jello2.ttf")

3/9/08

tinymce_imce.patch fixing browse button not showing up

Few week ago, I get tinymce module work on my new site. When I create new content and want to add the picture. Tinymce allow me only add url for an image. Anyway I found another module called IMCE. It work together with tinymce and allow me to upload image from my computer.

After installation, I can't see browse button when click add image??? my environments is (Drupal5.7+TinyMCE5.x-1.9+TinyMCE3.0+IMCE5.x-1.0). Many post tell me to add

<?php print $closure;?>
to page.tpl.php file, that not work for me. mine already have it.

Today I found the patch from here. It work well for my case. To apply patch[I do this on my local box then upload tinymce.module and imce_set_tinymce.js to host]
pnix@pnix-a7n:drupal$ ls
imce tinymce tinymce-5.x-1.9.tar.gz
imce-5.x-1.0.tar.gz tinymce_3_0_1.zip tinymce_imce.patch
pnix@pnix-a7n:drupal_modules$ patch -p0<tinymce_imce.patch
patching file tinymce/tinymce.module
patching file imce/imce_set_tinymce.js
pnix@pnix-a7n:drupal_modules$

here is my 'insert image popup' after patch.

3/4/08

Changing partition label on Ubuntu

I found this howto from community docs while searching for rename my usb drive. Not many times you need to do this but if you want, here is the summary.

You need few programs depends on the your partition type.
mtools for fat32
ntfsprogs for ntfs
e2label for ext2 or ext3
reiserfstune for reiserfs(v3)
Install which you need by 'sudo aptitude install [program name]'

note : check your partition type by 'mount' or 'df -T'.
For me, my usb is fat32 changing label is done by

pnix@pnix-a7n:~$ sudo mlabel -i /dev/sdb ::myusbdrive
pnix@pnix-a7n:~$
upper command, I just change label to 'myusbdrive'. for other partition types, below are some examples.
sudo ntfslabel /dev/sda1 newlabel
sudo e2label /dev/sda1 newlabel
sudo reiserfstune -l newlabel /dev/sda1



update [many thanks for comment]: for ext2/ext3 you also can use tune2fs like this
sudo tune2fs -L newlabel /dev/sda1

note : may be it's need to umount device before try changing label to get it work.
To get effect for internal drive it's need reboot, for usbdrive I need just unplug/plug.

Change /dev/xxx to match your drive.

2/28/08

Embeded Flash in Java Desktop App

Most of examples about playing Flash animation on desktop application I found on the internet to are done by VB. But today I found java version. Flash SWT Plugin[ many thanks to Don Park ], it work very well on my latest project :).

To use Flash SWT Plugin, download com.docuverse.swt.flash-0.4.zip and extract it somewhere on local disk. Now our eclipse flash project need to add atleast two external jars e.g. flash.jar[from where we just extract the zip] and swt.jar and now we are ready to code.

THE SOURCE
To play swf file, all we need is FlashPlayer object and activate it that all. it'll look like this.

import com.docuverse.swt.flash.FlashPlayer;

public class SWTPlayer {
....
private void run() {
// TODO Auto-generated method stub
Display display = new Display();
Shell shell = new Shell(display);
FlashPlayer player = new FlashPlayer(shell);
player.loadMovie(0, "yourflashfile.swf");
player.setSize(550, 400);
player.activate();
shell.setSize(550, 400);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}


here is what it look like when running.


Note : SWT Flash only support on Windows.

2/26/08

Install TinyMCE module on Drupal

I'm just choose Drupal to be CMS for my new site. Nothing more than google tell me that it win 2007 Open Source CMS Award :) so just try it.

Creating content with drupal is easy but if you want to add image, WYSIWYG editor, you need to install third party module. This post is about how i get this feature for my site.

1. Download TinyMCE WYSIWYG Editor[this will enable the TinyMCE editor to be used with Drupal]
you will get file name tinymce-5.x-1.9.tar.gz. Extract it into Drupal modules folder you will get modules/tinymce.
2. Download TinyMCE engine and you will get tinymce_3_0_1.zip. Again extract into tinymce folder from step one. Now you have modules/tinymce/tinymce.
3. Enable TinyMCE module by go to Administer->Site building->Modules TinyMCE should be at the bottom of the page. Enable it.
4. Grant permission to user role by go to Administer->User management->Access control[I'm check only authenticated user]
5. Create new profile by goto Administer->Site Configutation->TinyMCE and click create new profile.
Under basic setup, enter profile name, check Roles allowed to use this profile and set Default State to enable.
Under Buttons and plugins, check it all.
That's it. now when create content you will see TinyMCE toolbar below body textarea.


Note: I can't get enable/disable rich-text toggle link to work that why I set default state to enable. My System info is Drupal 5.7, tinymce-5.x-1.9 and Firefox 2.0.0.12.

2/7/08

Make your eclipse look better on ubuntu

When using eclipse on ubuntu, extra space between items and fonts size make it look awkward. I try to adjust fonts by go to [Window->Preferences->General->Appearance->Colors and Fonts]. This will not much help, reduce fonts size does not change space between item. Here is Eclipse Europa before tweak.
Anyway, at last I found the way to make eclipse look more compact from googling. Thank for Wesley and Vladimir Buell for this trick. Create ".gtkrc-2.0" in your home directory enable you to customize gtk object style[more about gtkrc-2.0]. Here is my ".gtkrc-2.0".

pnix@pnix-a7n:~$ cat .gtkrc-2.0
style "gtkcompact" {
font_name="Sans 8"
GtkButton::default_border={0,0,0,0}
GtkButton::default_outside_border={0,0,0,0}
GtkButtonBox::child_min_width=0
GtkButtonBox::child_min_heigth=0
GtkButtonBox::child_internal_pad_x=0
GtkButtonBox::child_internal_pad_y=0
GtkMenu::vertical-padding=1
GtkMenuBar::internal_padding=0
GtkMenuItem::horizontal_padding=4
GtkToolbar::internal-padding=0
GtkToolbar::space-size=0
GtkOptionMenu::indicator_size=0
GtkOptionMenu::indicator_spacing=0
GtkPaned::handle_size=4
GtkRange::trough_border=0
GtkRange::stepper_spacing=0
GtkScale::value_spacing=0
GtkScrolledWindow::scrollbar_spacing=0
GtkExpander::expander_size=10
GtkExpander::expander_spacing=0
GtkTreeView::vertical-separator=0
GtkTreeView::horizontal-separator=0
GtkTreeView::expander-size=8
GtkTreeView::fixed-height-mode=TRUE
GtkWidget::focus_padding=0
}
class "GtkWidget" style "gtkcompact"

style "gtkcompactextra" {
xthickness=0
ythickness=0
}
class "GtkButton" style "gtkcompactextra"
class "GtkToolbar" style "gtkcompactextra"
class "GtkPaned" style "gtkcompactextra"
pnix@pnix-a7n:~$

and here is the result. No more extra space, I also change fonts for text editor and Dialog to "DejaVu San size 8".

1/25/08

cvs server on ubuntu gutsy

Note for my first time setting up cvs server on ubuntu gutsy. CVS, a version control system, allow you to work on sourcecode with your team. To install it on ubuntu, we need two packages from repos, cvs and the wrapper.

pnix@pnix-a7n:~$ sudo aptitude install cvs cvsd
[sudo] password for pnix:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
Building tag database... Done
The following NEW packages will be installed:
cvs cvsd
0 packages upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 1756kB of archives. After unpacking 3973kB will be used.
Writing extended state information... Done
Get:1 http://th.archive.ubuntu.com gutsy/main cvs 1:1.12.13-8 [1669kB]
Get:2 http://th.archive.ubuntu.com gutsy/universe cvsd 1.0.13 [87.4kB]
...
Building tag database... Done
pnix@pnix-a7n:~$

during installation it will ask for repository. I just say '/myrepos'.
next, create repos folder under /var/lib/cvsd and initialize it.
pnix@pnix-a7n:~$ cd /var/lib/cvsd
pnix@pnix-a7n:cvsd$ sudo mkdir myrepos
pnix@pnix-a7n:cvsd$ sudo cvs -d /var/lib/cvsd/myrepos init
pnix@pnix-a7n:cvsd$ sudo chown -R cvsd:cvsd myrepos
pnix@pnix-a7n:cvsd$

now add new user [change username to what you want]
pnix@pnix-a7n:cvsd$ sudo cvsd-passwd /var/lib/cvsd/myrepos pnix
/usr/sbin/cvsd-passwd: adding user 'pnix' to '/var/lib/cvsd/myrepos/CVSROOT/passwd'
Enter new password:
Retype new password:
pnix@pnix-a7n:cvsd$


login and checkout test

pnix@pnix-a7n:cvsd$ cd ~/tmp
pnix@pnix-a7n:tmp$ cvs -d :pserver:pnix@localhost:/myrepos login
Logging in to :pserver:pnix@localhost:2401/myrepos
CVS password:
cvs login: CVS password file /home/pnix/.cvspass does not exist - creating a new file
pnix@pnix-a7n:cvsd$ cvs -d :pserver:pnix@localhost:/myrepos checkout .
cvs checkout: Updating .
cvs checkout: Updating CVSROOT
U CVSROOT/checkoutlist
U CVSROOT/commitinfo
U CVSROOT/config
U CVSROOT/cvswrappers
U CVSROOT/loginfo
U CVSROOT/modules
U CVSROOT/notify
U CVSROOT/postadmin
U CVSROOT/postproxy
U CVSROOT/posttag
U CVSROOT/postwatch
U CVSROOT/preproxy
U CVSROOT/rcsinfo
U CVSROOT/taginfo
U CVSROOT/verifymsg
pnix@pnix-a7n:tmp$

Eclipse test
Eclipse come with CVS support build-in. To use CVS, change the perspective to CVS Repos Exploring. Right click in "CVS Repositories" view choose "New > Repository Location". Enter information for our new CVS server then click "Finish".
That's it. If nothing wrong we just create new repos location and ready for any project to share.

1/10/08

include external jar into your own exported jar

One problem that almost java guys have is create jar with external jar include. In eclipse it has export function to export project but there's no way to add external jar with this method. Today I found one solution, the project Fat Jar Eclipse Plug-In can take care this problem.
Installation is just unzip it to eclipse folder then restart eclipse in shell or command line with this command "eclipse -clean". Now your eclipse already have fatjar plugin. To use it export the project, from your package explorer, right click on your project and select "Export...". You will get "Export Dialog"[see pic], choose Other->Fat Jar Exporter. From here you will know what to do next.:)