Tuesday, January 31, 2012

How to debug a Service? | Hello Android

How to debug a Service? | Hello Android
SDK Version:
M3


debugIntroduction

When you start a project with a service in it in debug mode, and you placed a breakpoint in a method of the service, the debugger will not stop.

Solution

The solution that works in almost all situation is to wait declaratively in the code for the debugger to attach. To do this, you have to make a call to:

  1. android.os.Debug.waitForDebugger();

The breakpoint can be inserted at any line after this call.

As a complete example, the SoftKeyboard tutorial is enhanced with the call above:

  1. public class SoftKeyboard extends InputMethodService
  2. implements KeyboardView.OnKeyboardActionListener {
  3. @Override
  4. public void onConfigurationChanged(Configuration newConfig) {
  5. Log.d("SoftKeyboard", "onConfigurationChanged()");
  6. /* now let's wait until the debugger attaches */
  7. android.os.Debug.waitForDebugger();
  8. super.onConfigurationChanged(newConfig);
  9. /* do something useful... */
  10. }

As you can see in the code, the first call in the method is a call to the logger, with which we can see in the Log output when our method was called. This can be an other way of tracking our method calls, without the need to stop at a breakpoint. But usually this is not enough for detailed debugging.
Then the second statement waits for the debugger to attach, as it is also noted in the comment. After this line the breakpoint can be inserted anywhere in the method.

Debugging a Service in case an Activity is also part of the application is even easier. In that case the activity has to be started first, then the debugger is able to stop at the breakpoint in the service as well, without the need of an explicit waitForDebugger() call.

Saturday, January 28, 2012

decio: il blog: How to recover files from a damaged CD/DVD

decio: il blog: How to recover files from a damaged CD/DVD

9 commenti:

Thomas ha detto...

Is there an easier, faster command than dd (I already know about dd_rescue)

I read about and used (to recover a DVD) another command similar to dd, but it ignored errors with no difficulty. It had the name dm or ddm or something like that. Have you ever heard of such a command?

I worked like a charm, and did not take nearly as long as dd is taking on my computer.

Decio Biavati ha detto...

Thanks for your useful comment and for stopping by.

Do you refer to sdd command? I never used it (I don't know dm or ddm either), although dd is very time expensive when deling with errors.

I will update the post if I will find some news.

Anonimo ha detto...

You should see dd_rescue at http://www.garloff.de/kurt/linux/ddrescue/.

Cheers!
emdmarques@gmail.com

Decio Biavati ha detto...

@emdmarques: thank you for the hint! I will try dd_rescue any time soon.

Thanks for stopping by.

Ralph ha detto...

I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.


Ruth

http://systemmemory.info

Kiran R ha detto...

I am using cygwin on windows xp to try and recover my DVD that is not being recognized in Windows

Unfortunately when I try:
ddrescue -n -b 2048 /cygdrive/c /dvd/a.iso /dvd/a.log
It shows up as
"Medium not found"

is there any way to make this work

Decio Biavati ha detto...

@Kiran: I never tried on cygwin, I don't know if there are issues regarding ddrescue...
I will try and be back with results in few days.

Thanks for asking.

SanskritFritz ha detto...

Thanks for the useful tip. I just recovered a CD with a movie on it, so I could watch it with my son, as I promised him earlier. He sends his thanks ;-)
I reckon you are using GoboLinux?

Makis ha detto...

Thank you for this! I have had exactly the same problem with some disks, with your help it seems like I can also rip them.

decio: il blog: How to recover files from a damaged CD/DVD

decio: il blog: How to recover files from a damaged CD/DVD

How to recover files from a damaged CD/DVD



If you, just like me, have had enough of I/O errors reading your optical media, this post is for you.
This method allows for recovering files from damaged CD/DVD by copying them byte to byte, using the Unix command dd.

WARNING: dd is a very powerful program, and if misused, can literally erase everything on your hard drives. And worst, dd is a no-warning, no-second-think, advanced-users only, Unix-style mean and lean program. See dd entry on Wikipedia for details.

This is the command you should run:
dd if=/Volumes/MY_DYD/File_to_retrieve.ext of=/Users/myuser/myfolder/File_retrieved.ext bs=512 conv=noerror, sync

dd: the command
if: input file
of: output file
bs: bytes size [512 bytes]
conv: conversion options [noerror, don't halt on errors; sync, pad with blanks the block containing the error]

If you specify a bs so small (512), in case of a large bad chunk on the medium you will obtain a lot of error logs. Let it go until you have the prompt again.

This method is expecially useful to recover damaged movies, because unless you have the file 50% corrupted (not very likely even in worst cases), you probably will strip a couple of frames from the movie, and the result will be perfect.
Of course if you are recovering file working as a whole, as a compressed archive or a RDBMS datafile, maybe padding the error with spaces may render useless the resulting file. As usual, YMMV.

dd is available under OSX and Linux (any). If you are running Windows, well, probably you are not an advanced user anyway, so why bother (and no, neither Robocopy nor NtBackup have the same functions of dd). Just in case, you can run dd under Windows viaCygwin. And if you don't know Cygwin, aka Unix shell for Windows, you better read the tutorial on Lifehacker.

dd MAN Page

Tuesday, January 17, 2012

FreeSwitch Bluebox High Availability (HA) Cluster using Heartbeat and DRBD | Change the World

FreeSwitch Bluebox High Availability (HA) Cluster using Heartbeat and DRBD | Change the World
JAN
7

FreeSwitch + Bluebox High Availability (HA) Cluster using Heartbeat and DRBD

I need to test FreeSwitch first in a virtual environment before going into production, the objective is to come up with a highly available FreeSwitch cluster using Heartbeat 2.1 and DRBD 8.2. I'm using CentOS 5.5 for this demonstration, the real production servers will be using RHEL5 and has the following hardware specifications as stated in the systems requirement:
  • IBM X3650 M2
  • Intel® Xeon® Processor 2.5 Ghz
  • 12GB DDR3 RAM
  • 8 - 146GB SFF SCSI HDD RAID10
  • 2 Integrated Gigabit Ethernet

Installing FreeSwitch

I'm going to install FreeSwitch using the latest stable version 1.0.6 which you can download from http://files.freeswitch.org, it would be nice if I could have used git unfortunately something is blocking it here in the office hence I couldn't get the files using git.

Off to the races, update the OS first.


# yum -y update

Next, make sure you installed the necessary tools to compile FreeSwitch.

# yum install autoconf automake gcc-c++ git-core libjpeg-devel libtool make ncurses-devel openssl-devel perl cpio expat-devel gettext-devel curl-devel curl

Keep things tidy, cd to /usr/src.

# cd /usr/src

Fetch file using wget

# wget http://files.freeswitch.org/freeswitch-1.0.6.tar.gz

Untar file.

# tar xzvf freeswitch-1.0.6.tar.gz

Change directory name to freeswitch (optional)

# mv freeswitch-1.0.6 freeswitch

Go to freeswitch directory and compile. This will take a while so go ahead, take a break, drink a soda or something, I prefer lemon iced tea :D

# cd freeswitch
# ./configure
# make

+---------- FreeSWITCH Build Complete ----------+
+ FreeSWITCH has been successfully built. +
+ Install by running: +
+ +
+ make install +
+-----------------------------------------------+

# make install

+---------- FreeSWITCH install Complete ----------+
+ FreeSWITCH has been successfully installed. +
+ +
+ Install sounds: +
+ (uhd-sounds includes hd-sounds, sounds) +
+ (hd-sounds includes sounds) +
+ ------------------------------------ +
+ make cd-sounds-install +
+ make cd-moh-install +
+ +
+ make uhd-sounds-install +
+ make uhd-moh-install +
+ +
+ make hd-sounds-install +
+ make hd-moh-install +
+ +
+ make sounds-install +
+ make moh-install +
+ +
+ Install non english sounds: +
+ replace XX with language +
+ (ru : Russian) +
+ ------------------------------------ +
+ make cd-sounds-XX-install +
+ make uhd-sounds-XX-install +
+ make hd-sounds-XX-install +
+ make sounds-XX-install +
+ +
+ Upgrade to latest: +
+ ---------------------------------- +
+ make current +
+ +
+ Rebuild all: +
+ ---------------------------------- +
+ make sure +
+ +
+ Install/Re-install default config: +
+ ---------------------------------- +
+ make samples +
+ +
+ +
+ Additional resources: +
+ ---------------------------------- +
+ http://www.freeswitch.org +
+ http://wiki.freeswitch.org +
+ http://jira.freeswitch.org +
+ http://lists.freeswitch.org +
+ +
+ irc.freenode.net / #freeswitch +
+ +
+ Register For ClueCon: +
+ ---------------------------------- +
+ http://www.cluecon.com +
+ +
+-------------------------------------------------+
# make cd-sounds-install && make cd-moh-install
# make samples

Once done, test to make sure that FreeSwitch is working! The compilation process including fetching sound files took almost an hour to complete, told you to take a break, didn't I? :D

# cd /usr/local/freeswitch/bin
# ./freeswitch

_____ ______ _____ _____ ____ _ _
| ___| __ ___ ___/ ___\ \ / /_ _|_ _/ ___| | | |
| |_ | '__/ _ \/ _ \___ \\ \ /\ / / | | | || | | |_| |
| _|| | | __/ __/___) |\ V V / | | | || |___| _ |
|_| |_| \___|\___|____/ \_/\_/ |___| |_| \____|_| |_|

************************************************************
* Anthony Minessale II, Michael Jerris, Brian West, Others *
* FreeSWITCH (http://www.freeswitch.org) *
* Paypal Donations Appreciated: paypal@freeswitch.org *
* Brought to you by ClueCon http://www.cluecon.com/ *
************************************************************

2010-12-29 00:36:26.546866 [CONSOLE] switch_core.c:1578
FreeSWITCH Version 1.0.6 (svn-exported) Started.
Max Sessions[1000]
Session Rate[30]
SQL [Enabled]
freeswitch@pbx1.cluster.local> sofia status

Name Type Data State
=================================================================================================
internal profile sip:mod_sofia@192.168.136.136:5060 RUNNING (0)
external profile sip:mod_sofia@192.168.136.136:5080 RUNNING (0)
external::example.com gateway sip:joeuser@example.com NOREG
internal-ipv6 profile sip:mod_sofia@[::1]:5060 RUNNING (0)
192.168.136.136 alias internal ALIASED
=================================================================================================
3 profiles 1 alias

To shutdown FreeSwitch type "shutdown" or "..." inside the FreeSwitch shell to turn off FreeSwtich. Afterwards, edit PATH to include path to Freeswitch binaries. Create /etc/profile.d/freeswitch.sh, and add the line "export PATH=$PATH:/usr/local/freeswitch/bin".

# vim /etc/profile.d/freeswitch.sh

Add this line --> export PATH=$PATH:/usr/local/freeswitch/bin

Save and exit.

Make /etc/profile.d/freeswitch.sh executable by:

# chmod 755 /etc/profile.d/freeswitch.sh

Be sure to log off and log on back to see changes in effect.

# echo $PATH

Add FreeSwitch user:

# useradd freeswitch

Change freeswitch user passwd setting:

# vim /etc/passwd

freeswitch:x:500:500:Freeswitch:/home/freeswitch:/sbin/nologin

Change ownership of /usr/local/freeswitch.

# chown -R freeswitch:freeswitch /usr/local/freeswitch

To automatically start FreeSwitch at boot, copy /usr/src/freeswitch/build/freeswitch.init.redhat to /etc/init.d/ and make the following changes to PID_FILE, FS_FILE, and FS_HOME parameters:

# vim /etc/init.d/freeswitch

PID_FILE=${PID_FILE-/usr/local/freeswitch/log/freeswitch.pid}
FS_FILE=${FS_FILE-/usr/local/freeswitch/bin/freeswitch}
FS_HOME=${FS_HOME-/usr/local/freeswitch}

Save and exit.

Next, do the following:

# chmod 755 /etc/init.d/freeswitch
# chkconfig freeswitch on
# chkconfig --list freeswitch

Start FreeSwitch using the rc.d script:

# /etc/init.d/freeswitch start

Wait about 30 seconds for Freeswitch to be up and running, and connect to the server through the console:

# fs_cli

Check SIP status:

freeswitch@internal> sofia status

Check a specific SIP profile:

freeswitch@internal>sofia status profile internal

To exit the console, type "/exit" or "..."; To stop the Freeswitch server and exit the console, type "fsctl shutdown elegant".

Next step would be to clone this machine's current state, this is in order for me to have the second node in a jiffy, I'm using VMWare Workstation by the way.

Configuring DRBD

Make sure you have extra partition for DRBD, mine is on /dev/sda3 on both nodes, it's recommended that they're both have the same disk size.

Install DRBD on both nodes:

# yum install drbd82 kmod-drbd82

Configure DRBD.

# vim /etc/drbd.conf

resource "r0" {
protocol C;
disk { on-io-error pass_on; }
startup { wfc-timeout 30; degr-wfc-timeout 20; }
syncer { rate 10M; }
on pbx1.cluster.local {
device /dev/drbd0;
disk /dev/sda3;
address 192.168.136.136:7789;
meta-disk internal;
}
on pbx2.cluster.local {
device /dev/drbd0;
disk /dev/sda3;
address 192.168.136.137:7789;
meta-disk internal;
}
}

Save file and exit.

Copy /etc/drbd.conf to node2.

# scp /etc/drbd.conf root@node2:/etc/

Bringing up DRBD.

With DRBD off on both nodes, reboot node1 and watch DRDB during start up, type 'yes' when prompted.

Login back to node1 and do the following to:

# drbdadm create-md r0

Node1 is now in secondary inconsistent state. Next, reboot node2 to bring up DRBD, once startup is complete login back to node2.

# drbdadm create-md r0

We now have to secondaries in incosistent state, it's time to synchronize them, login back to node1 and promote it to primary.

# drbdadm -- --overwrite-data-of-peer primary r0

Watch DRBD sync.

# watch cat /proc/drbd


Once syncing is done, login to node1 and create filesystem on /dev/drbd0 and test DRBD.


# mkfs.ext3 -L r0 /dev/drbd0


We don't have to repeat this on node2, everything we do on node1 is replicated on node2, that's DRBD at work.

Create /replication partition on both nodes, it will be used as mount point.


Installing and Configuring Heartbeat

Install Heartbeat on both nodes.

# yum install heartbeat

This will install heartbeat together with heartbeat-stonith and heartbeat-pils.

Create the following files under /etc/ha.d/ directory:
  1. authkeys
  2. ha.cf
  3. haresources
Next, you can copy sample configuration files from the /usr/share/doc/heartbeat-version.no. directory, or create one from scratch, we'll do the latter.

# cd /etc/ha.d/
# vim authkeys

auth 1
1 sha1 secretkey!

Save and exit.

Change authkeys permission to 600 or else it will not work.

# chmod 600 authkeys

Next, create ha.cf file.

# vim ha.cf

debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport 694
bcast eth0
auto_failback off
node pbx1.cluster.local
node pbx2.cluster.local

Third, create haresources file.

# vim haresources

pbx1.cluster.local IPaddr::192.168.136.138/24/eth1/192.168.136.255
pbx1.cluster.local drbddisk::r0 Filesystem::/dev/drbd0::/replication::ext3 freeswitch

Save and exit.

Read sample configuration file which explains each parameter for more details. While in the/etc/ha.d/ directory, copy ha.cf, authkeys, and haresources to node2.

# scp authkeys ha.cf haresources root@pbx:/etc/ha.d/

Hold your horses for now, don't start Heartbeat yet, we still have to configure FreeSwitch to use the DRBD, go to primary node and cd to mounted drbd partition i.e. /replication

# cd /replication

1. Backup FreeSwitch installation first! or use VMWare snapshot functionality in case we messed things up.

# tar czvf usr-local-freeswitch.tar.gz /usr/local/freeswitch

2. Untar usr-local-freeswitch.tar.gz in current drbd directory /replication

# tar xzvf usr-local-freeswitch.tar.gz

3. Remove /usr/local/freeswitch.

# rm -rf /usr/local/freeswitch

4. Create symbolic link for freeswitch to /usr/local/freeswitch from drbd directory.

# ln -s /replication/usr/local/freeswitch /usr/local/freeswitch

Repeat steps 1 to 4 on node2.

Now for the finale, it's time to start heartbeat on both nodes, I'll show my heartbeat logs to prove that failover is working.

Check if our FreeSwitch HA cluster is working.

We need to have multiple terminal open to properly monitor the failover i.e. 2 terminals for each node. Monitor ha-debug logs in real time on both nodes by:

# tail -f /var/log/ha-debug

Go to node1, stop heartbeat and see what happens on terminal 2's ha-debug log.

[root@pbx1 ~]# /etc/init.d/heartbeat stop
Stopping High-Availability services:
[ OK ]

[root@pbx2 ~]# tail -f /var/log/ha-debug

heartbeat[9455]: 2011/01/04_11:36:45 info: Received shutdown notice from 'pbx1.cluster.local'.
heartbeat[9455]: 2011/01/04_11:36:45 info: Resources being acquired from pbx1.cluster.local.
heartbeat[9455]: 2011/01/04_11:36:45 debug: StartNextRemoteRscReq(): child count 1
heartbeat[9726]: 2011/01/04_11:36:45 info: acquire all HA resources (standby).
heartbeat[9727]: 2011/01/04_11:36:46 info: No local resources [/usr/share/heartbeat/ResourceManager listkeys pbx2.cluster.local] to acquire.
heartbeat[9455]: 2011/01/04_11:36:46 debug: StartNextRemoteRscReq(): child count 1
ResourceManager[9752]: 2011/01/04_11:36:46 info: Acquiring resource group: pbx1.cluster.local IPaddr::192.168.136.138/24/eth1/192.168.136.255
IPaddr[9779]: 2011/01/04_11:36:46 INFO: Resource is stopped
ResourceManager[9752]: 2011/01/04_11:36:46 info: Running /etc/ha.d/resource.d/IPaddr 192.168.136.138/24/eth1/192.168.136.255 start
ResourceManager[9752]: 2011/01/04_11:36:46 debug: Starting /etc/ha.d/resource.d/IPaddr 192.168.136.138/24/eth1/192.168.136.255 start
IPaddr[9877]: 2011/01/04_11:36:46 INFO: Using calculated netmask for 192.168.136.138: 255.255.255.0
IPaddr[9877]: 2011/01/04_11:36:46 INFO: eval ifconfig eth1:0 192.168.136.138 netmask 255.255.255.0 broadcast 192.168.136.255
IPaddr[9877]: 2011/01/04_11:36:46 DEBUG: Sending Gratuitous Arp for 192.168.136.138 on eth1:0 [eth1]
IPaddr[9848]: 2011/01/04_11:36:46 INFO: Success
INFO: Success
ResourceManager[9752]: 2011/01/04_11:36:46 debug: /etc/ha.d/resource.d/IPaddr 192.168.136.138/24/eth1/192.168.136.255 start done. RC=0
ResourceManager[9970]: 2011/01/04_11:36:46 info: Acquiring resource group: pbx1.cluster.local drbddisk::r0 Filesystem::/dev/drbd0::/replication::ext3 freeswitch
ResourceManager[9970]: 2011/01/04_11:36:46 info: Running /etc/ha.d/resource.d/drbddisk r0 start
ResourceManager[9970]: 2011/01/04_11:36:46 debug: Starting /etc/ha.d/resource.d/drbddisk r0 start
ResourceManager[9970]: 2011/01/04_11:36:46 debug: /etc/ha.d/resource.d/drbddisk r0 start done. RC=0
Filesystem[10038]: 2011/01/04_11:36:46 INFO: Resource is stopped
ResourceManager[9970]: 2011/01/04_11:36:46 info: Running /etc/ha.d/resource.d/Filesystem /dev/drbd0 /replication ext3 start
ResourceManager[9970]: 2011/01/04_11:36:46 debug: Starting /etc/ha.d/resource.d/Filesystem /dev/drbd0 /replication ext3 start
Filesystem[10119]: 2011/01/04_11:36:46 INFO: Running start for /dev/drbd0 on /replication
Filesystem[10108]: 2011/01/04_11:36:46 INFO: Success
INFO: Success
ResourceManager[9970]: 2011/01/04_11:36:46 debug: /etc/ha.d/resource.d/Filesystem /dev/drbd0 /replication ext3 start done. RC=0
ResourceManager[9970]: 2011/01/04_11:36:46 info: Running /etc/init.d/freeswitch start
ResourceManager[9970]: 2011/01/04_11:36:46 debug: Starting /etc/init.d/freeswitch start
Starting freeswitch: [ OK ]

ResourceManager[9970]: 2011/01/04_11:36:47 debug: /etc/init.d/freeswitch start done. RC=0
heartbeat[9726]: 2011/01/04_11:36:47 info: all HA resource acquisition completed (standby).
heartbeat[9455]: 2011/01/04_11:36:47 info: Standby resource acquisition done [all].
heartbeat[10243]: 2011/01/04_11:36:47 debug: notify_world: setting SIGCHLD Handler to SIG_DFL
harc[10243]: 2011/01/04_11:36:47 info: Running /etc/ha.d/rc.d/status status
mach_down[10261]: 2011/01/04_11:36:47 info: Taking over resource group IPaddr::192.168.136.138/24/eth1/192.168.136.255
ResourceManager[10287]: 2011/01/04_11:36:47 info: Acquiring resource group: pbx1.cluster.local IPaddr::192.168.136.138/24/eth1/192.168.136.255
IPaddr[10314]: 2011/01/04_11:36:47 INFO: Running OK
mach_down[10261]: 2011/01/04_11:36:47 info: Taking over resource group drbddisk::r0
ResourceManager[10373]: 2011/01/04_11:36:47 info: Acquiring resource group: pbx1.cluster.local drbddisk::r0 Filesystem::/dev/drbd0::/replication::ext3 freeswitch
Filesystem[10415]: 2011/01/04_11:36:47 INFO: Running OK
mach_down[10261]: 2011/01/04_11:36:47 info: /usr/share/heartbeat/mach_down: nice_failback: foreign resources acquired
mach_down[10261]: 2011/01/04_11:36:47 info: mach_down takeover complete for node pbx1.cluster.local.
heartbeat[9455]: 2011/01/04_11:36:47 info: mach_down takeover complete.

As you can see node2 took over from node1 and is now primary, FreeSwitch is now running on node2.

Double check!

[root@pbx2 ~]# mount
/dev/sda1 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/drbd0 on /replication type ext3 (rw)

[root@pbx2 ~]# /etc/init.d/freeswitch status
freeswitch (pid 10253) is running...

As you can see /dev/drbd0 is mounted and FreeSwitch is running.

Start Heartbeat again on node1 and perform the same test, stop Heartbeat on node2 and see what happens on ha-debug log on node1.

[root@pbx2 ~]# /etc/init.d/heartbeat stop
Stopping High-Availability services:
[ OK ]

[root@pbx1 ~]# tail -f /var/log/ha-debug
heartbeat[10484]: 2011/01/04_11:50:17 info: Received shutdown notice from 'pbx2.cluster.local'.
heartbeat[10484]: 2011/01/04_11:50:17 info: Resources being acquired from pbx2.cluster.local.
heartbeat[10484]: 2011/01/04_11:50:17 debug: StartNextRemoteRscReq(): child count 1
heartbeat[10527]: 2011/01/04_11:50:17 info: acquire all HA resources (standby).
ResourceManager[10551]: 2011/01/04_11:50:18 info: Acquiring resource group: pbx1.cluster.local IPaddr::192.168.136.138/24/eth1/192.168.136.255
IPaddr[10590]: 2011/01/04_11:50:19 INFO: Resource is stopped
IPaddr[10615]: 2011/01/04_11:50:19 INFO: Resource is stopped
heartbeat[10528]: 2011/01/04_11:50:19 info: Local Resource acquisition completed.
heartbeat[10484]: 2011/01/04_11:50:19 debug: StartNextRemoteRscReq(): child count 2
heartbeat[10484]: 2011/01/04_11:50:19 debug: StartNextRemoteRscReq(): child count 2
heartbeat[10484]: 2011/01/04_11:50:19 debug: StartNextRemoteRscReq(): child count 1
ResourceManager[10551]: 2011/01/04_11:50:19 info: Running /etc/ha.d/resource.d/IPaddr 192.168.136.138/24/eth1/192.168.136.255 start
ResourceManager[10551]: 2011/01/04_11:50:19 debug: Starting /etc/ha.d/resource.d/IPaddr 192.168.136.138/24/eth1/192.168.136.255 start
IPaddr[10781]: 2011/01/04_11:50:19 INFO: Using calculated netmask for 192.168.136.138: 255.255.255.0
IPaddr[10781]: 2011/01/04_11:50:19 INFO: eval ifconfig eth1:0 192.168.136.138 netmask 255.255.255.0 broadcast 192.168.136.255
IPaddr[10781]: 2011/01/04_11:50:19 DEBUG: Sending Gratuitous Arp for 192.168.136.138 on eth1:0 [eth1]
IPaddr[10752]: 2011/01/04_11:50:20 INFO: Success
INFO: Success
ResourceManager[10551]: 2011/01/04_11:50:20 debug: /etc/ha.d/resource.d/IPaddr 192.168.136.138/24/eth1/192.168.136.255 start done. RC=0
ResourceManager[10874]: 2011/01/04_11:50:20 info: Acquiring resource group: pbx1.cluster.local drbddisk::r0 Filesystem::/dev/drbd0::/replication::ext3 freeswitch
ResourceManager[10874]: 2011/01/04_11:50:20 info: Running /etc/ha.d/resource.d/drbddisk r0 start
ResourceManager[10874]: 2011/01/04_11:50:20 debug: Starting /etc/ha.d/resource.d/drbddisk r0 start
ResourceManager[10874]: 2011/01/04_11:50:20 debug: /etc/ha.d/resource.d/drbddisk r0 start done. RC=0
Filesystem[10942]: 2011/01/04_11:50:20 INFO: Resource is stopped
ResourceManager[10874]: 2011/01/04_11:50:20 info: Running /etc/ha.d/resource.d/Filesystem /dev/drbd0 /replication ext3 start
ResourceManager[10874]: 2011/01/04_11:50:20 debug: Starting /etc/ha.d/resource.d/Filesystem /dev/drbd0 /replication ext3 start
Filesystem[11023]: 2011/01/04_11:50:20 INFO: Running start for /dev/drbd0 on /replication
Filesystem[11012]: 2011/01/04_11:50:20 INFO: Success
INFO: Success
ResourceManager[10874]: 2011/01/04_11:50:20 debug: /etc/ha.d/resource.d/Filesystem /dev/drbd0 /replication ext3 start done. RC=0
ResourceManager[10874]: 2011/01/04_11:50:20 info: Running /etc/init.d/freeswitch start
ResourceManager[10874]: 2011/01/04_11:50:20 debug: Starting /etc/init.d/freeswitch start
Starting freeswitch: [ OK ]

ResourceManager[10874]: 2011/01/04_11:50:21 debug: /etc/init.d/freeswitch start done. RC=0
heartbeat[10527]: 2011/01/04_11:50:21 info: all HA resource acquisition completed (standby).
heartbeat[10484]: 2011/01/04_11:50:21 info: Standby resource acquisition done [all].
heartbeat[11149]: 2011/01/04_11:50:21 debug: notify_world: setting SIGCHLD Handler to SIG_DFL
harc[11149]: 2011/01/04_11:50:21 info: Running /etc/ha.d/rc.d/status status
mach_down[11165]: 2011/01/04_11:50:21 info: /usr/share/heartbeat/mach_down: nice_failback: foreign resources acquired
mach_down[11165]: 2011/01/04_11:50:21 info: mach_down takeover complete for node pbx2.cluster.local.
heartbeat[10484]: 2011/01/04_11:50:21 info: mach_down takeover complete.
heartbeat[11200]: 2011/01/04_11:50:21 debug: notify_world: setting SIGCHLD Handler to SIG_DFL
harc[11200]: 2011/01/04_11:50:21 info: Running /etc/ha.d/rc.d/ip-request-resp ip-request-resp
ip-request-resp[11200]: 2011/01/04_11:50:21 received ip-request-resp IPaddr::192.168.136.138/24/eth1/192.168.136.255 OK yes
ResourceManager[11221]: 2011/01/04_11:50:21 info: Acquiring resource group: pbx1.cluster.local IPaddr::192.168.136.138/24/eth1/192.168.136.255
IPaddr[11248]: 2011/01/04_11:50:23 INFO: Running OK
heartbeat[11306]: 2011/01/04_11:50:23 debug: notify_world: setting SIGCHLD Handler to SIG_DFL
harc[11306]: 2011/01/04_11:50:23 info: Running /etc/ha.d/rc.d/ip-request-resp ip-request-resp
ip-request-resp[11306]: 2011/01/04_11:50:23 received ip-request-resp drbddisk::r0 OK yes
ResourceManager[11327]: 2011/01/04_11:50:23 info: Acquiring resource group: pbx1.cluster.local drbddisk::r0 Filesystem::/dev/drbd0::/replication::ext3 freeswitch
Filesystem[11368]: 2011/01/04_11:50:24 INFO: Running OK

Check!

[root@pbx1 ~]# mount
/dev/sda1 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/drbd0 on /replication type ext3 (rw)

[root@pbx1 ~]# /etc/init.d/freeswitch status
freeswitch (pid 11145) is running...



Installing Bluebox aka FreePBX3


Since our HA Cluster is already working, installing Bluebox aka FreePBX3 would be a breeze. Bluebox requires MySQL, Apache, and PHP >=5.2. CentOS 5.5 comes with PHP 5.1.6 hence we need to install the EPEL and REMI repository on both nodes.


# rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
# rpm -Uvh http://rpms.famillecollet.com/enterprise/5/remi/i386/remi-release-5-7.el5.remi.noarch.rpm


Install MySQL, Apache, and PHP on both nodes.


# yum install mysql-server php php-mysql php-gd php-xml php-mbstring php-pdo php-soap php-common httpd


Once your done installing on both nodes, it's now time to configure MySQL to use DRBD.


1. Go to node1 (primary node) and cd to mounted drbd directory and backup MySQL.


# cd /replication
# tar czvf var-lib-mysql.tar.gz /var/lib/mysql


2. Untar var-lib-mysql.tar.gz in current drbd directory /replication


# tar xzvf var-lib-mysql.tar.gz


3. Remove /var/lib/mysql


# rm -rf /var/lib/mysql


4. Create symbolic link for MySQL to /var/lib/mysql from drbd directory.


# ln -s /replication/var/lib/mysql /var/lib/mysql


Repeat steps 1 to 4 on node2.


Configuring Apache.


Create /replication/web directory on both nodes, this directory will be used by Apache.


Next, login to node1 and edit /etc/httpd/conf/httpd.conf and make the following changes.


# vim /etc/httpd/conf/httpd.conf


Replace all instances of "/var/www/html" with "/replication/web".


Save and exit.


Copy to node2.


# scp /etc/httpd/conf/httpd.conf root@pbx2:/etc/httpd/conf/


It's now time to update /etc/ha.d/haresources on both nodes and add MySQL and Apache to the mix, login to node1 and edit haresources.


# vim /etc/ha.d/haresources


pbx1.cluster.local IPaddr::192.168.136.138/24/eth1/192.168.136.255
pbx1.cluster.local drbddisk::r0 Filesystem::/dev/drbd0::/replication::ext3 freeswitch mysqld httpd


Save and exit, and copy to node2.


# scp /etc/ha.d/haresources root@pbx2:/etc/ha.d/


Start Apache and MySQL on the primary node and test!


Finally, install Bluebox on primary node.


# cd /replication/web
# git clone git://source.2600hz.org/bluebox.git
# cd bluebox
# ./preinstall.sh


While on primary node, add bluebox database then login to mysql prompt and do the following:


mysql> CREATE USER 'bluebox'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL ON bluebox.* TO 'bluebox'@'localhost';
mysql> FLUSH PRIVILEGES;


Open web browser and go to http://server_ip/bluebox and follow on-screen instructions to install Bluebox.


We now have a highly available FreeSwitch Cluster with Bluebox using DRDB and Heartbeat.


Cheers!


Many thanks to Vener who provided his valuable insights.


References:



http://www.voipkb.com/wiki/index.php/NEW_Install:Linux#CentOS2