May 29 2008

My Experince in Open Solaris

Category: SolarisBipin Balakrishnan @ 11:17 pm

opensolarisphoto.png

Recently we had a plan to switch our servers from linux to Solaris. Hence i have a try on Solaris which was a new experience.As in my laptop i had both windows and Linux (Ubuntu).I was thinking how to install the third one with out losing the others.On that time i heard about VMware .The name “VMware” comes from the acronym “VM“, meaning “virtual machine“, while ware comes from second part of “software“.

With VMware we can install any other operating System in Virtualization.Suppose we have linux OS in our system only after installing VM ware we can install Windows and Solaris on it.One of the major benefit is that we can easily switch from one OS to other with out any reboot.Nice one right!!!

Installing VMware in ubuntu OS is as follows.

sudo apt-get install vmware-server

After installing Vmware we can install any other os on it.In my case i installed OpenSolaris using the boot CD.

OpenSolaris is an open source project created by Sun Microsystems to build a developer community around Solaris Operating System technology. It is aimed at developers, system administrators and users who want to develop and improve operating systems.OpenSolaris is derived from the Unix System V Release 4 codebase, and has significant modifications made by Sun since it bought the rights to the codebase in 1994.

After it got finished we can log into the new OS as we does as normally with out any reboot.Solaris booting in my ubuntu OS is shown below.

sola.jpeg

We had full screen option in the VMware to work as if we are working on the solaris OS booted and loaded.The look and feel is similar to that of the same UbuntuOS. The next issue was installing the the packages.In Ubuntu we had apt-get option. Here we had similar option called pkg-get install.

But but default installation it will no be avilable hence we have to install it first.

Step 1 – Install pkg-get

# pkgadd -d http://www.blastwave.org/pkg_get.pkg

Step 2 – Install the complete wget package

We will now use pkg-get to install the complete wget package along with all its dependencies.

Simply type the following :

# /opt/csw/bin/pkg-get -i wget

Another example for installing mozilla
#/opt/csw/bin/pkg-get -i install mozilla
For searching a package like apt-cache in Ubuntu

#pfexec /opt/csw/bin/pkg-get -a | grep apache2

will search the package Apache2

Like sudo in ubuntu we have pfexec to execute the root command in solaris.

The next thing was checking the ip address of my machine when it is in solaris.The command is similar to linux but a slight variation

pfexec ifconfig -a

Will show the ip address

To get ip address via dhclinet

$ pfexec ifconfig pcn0 dhcp drop

$pfexec ifconfig pcn0 dhcp start

For those who dont like command like installation can use the package manager in graphical mode to install packages.

Also try to use full paths for running or restarting a service.For example

for starting apache use

pfexec /usr/apache2/2.2/bin/apachectl restart

This much for now will be continued in my coming posts…;)

Tags: ,


May 20 2008

Monitoring a daemon

Category: LinuxBipin Balakrishnan @ 10:42 pm

monit-logo.gif

Well we have created a PHP daemon.One major issue with all daemon is that some time it got killed with out any reason.Here we have a solution for monitoring the daemon with a utility called monit.monit is a utility for managing and monitoring, processes, files, directories and devices on a Unix system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations. E.g. monit can start a process if it does not run, restart a process if it does not respond and stop a process if it uses to much resources. You may use monit to monitor files, directories and devices for changes, such as timestamp changes, checksum changes or size changes.
For doing it install the utility first

sudo apt-get install monit

We have to edit some configuration file to make the monit work.
Edit sudo vim /etc/default/monit

Set startup=1 from 0

Edit sudo vim /etc/monit/monitrc
This is the file where we specify what to monit
Uncomment

set daemon  60 #will check the daemon every 1 minute
set httpd port 2812 and
 use address localhost  # only accept connection from localhost
 allow localhost        # allow localhost to connect to the server and
#specifying the program for monitor
check process php with pidfile "/var/run/process.pid"
start = "/usr/bin/php /var/www/voicealerts/process.php"
stop = "/usr/bin/php /var/www/voicealerts/process.php"

Line 1 starts a process service entry. It contains the keyword check and a descriptive name for he process to monitor, in this case php. Monit also require the process pidfile to be stated.
If you want monit to start, stop or restart the process you must submit a start and stop program.
Line 2-3 defines those programs for this process
Write and quite the file and check the syntax is ok with command

sudo monit -t

start monit deamon by

sudo /etc/init.d/monit start

start the files specified in the monitrc by

sudo monit start all

check the status of our daemon

sudo monit status

This is a sample configuration monitors the PHP daemon process mentioned in the above post.

Tags: ,


May 20 2008

Making PHP program as Daemon

Category: PHPBipin Balakrishnan @ 10:05 pm

It is some time necessary to make a PHP progam as a daemon .Here it explains how it is possible. Process Control support in PHP implements the Unix style of process creation, program execution, signal handling and process termination. Process Control should not be enabled within a web server environment and unexpected results may happen if any Process Control functions are used within a web server environment.

The process control functions come along with the php-cli in linux.So we don’t need to install extra libraries for this to work.If php-cli is not there in your machine intall it with yum or apt-get.As i am using the ubuntu os im explaining with its command Ubuntu users can follow this.

bipin@bipin-laptop:~$ sudo apt-get install php5-cli

Copy and paste the code for background process

<?php
include_once('createdb.php');
declare(ticks=1);
$pid = pcntl_fork();
if ($pid == -1) {
die("could not fork");
} else if ($pid) {
exit(); // we are the parent
} else {
// we are the child
}
// detatch from the controlling terminal
if (posix_setsid() == -1) {
die("could not detach from terminal");
}
$posid=posix_getpid();
$fp = fopen("/var/run/process.pid", "w");
fwrite($fp, $posid);
fclose($fp);
// setup signal handlers
 pcntl_signal(SIGTERM, "sig_handler");
 pcntl_signal(SIGHUP, "sig_handler");
// loop forever performing tasks
 $dbobject = new DB();
 $dbobject->getCon();
 while (1) {
// do something interesting here, here i have called a function from other flile called "createdb.php"
$dbobject->CopyCallFiles();
}
 fclose($fp);
 function sig_handler($signo)
 {
switch ($signo) {
 case SIGTERM:
 // handle shutdown tasks
 exit;
 break;
 case SIGHUP:
 // handle restart tasks
 break;
 default:
 // handle all other signals
 }
}
?>

Run the program and the function $dbobject->CopyCallFiles(); will work as a deamon here we can include a file instead of the function also here.

Tags: , ,


May 14 2008

Asterisk with Google Talk

Category: AsteriskBipin Balakrishnan @ 4:04 pm

googletalk_logo.gif

Asterisk now speaks with Google Talk using the jingle protocol.(Jingle is an extension to the Jabber/XMPP protocol, to allow for peer-to-peer (p2p) signalling for multimedia interactions such as voice or video. It was designed by Google and the XMPP Standards Foundation.).We can make calls can route to and from google talk to soft phones as well as the hard phones.

Asterisk does not have in build support for this we have to install an addon for this to happen.

 svn checkout http://svn.uludag.org.tr/projeler/iksemel iksemel  

To run autogen.sh you must have several packages, it will prompt you for the packages except for libgnutls-dev if you don’t
have this it will generate an error message in configure.

Install the following depending packeges and run autogen.sh script.

sudo apt-get install libiksemel-dev
sudo apt-get install libiksemel3
sudo apt-get install libiksemel-utils
sudo apt-get install libgnutls13

Compile asterisk again after installing these packages if asterisk is installed already.

Now edit the jabber.conf file in /etc/asterisk/

[general]
 debug=yes
 autoprune=no
 autoregister=no
[gtalk_account]
 type=client
 serverhost=talk.google.com
 username=itzbipin@gmail.com/Talk
 secret=XXXXXXXX // put your gmail password here
port=5222
usetls=yes ; TLS is required by talk.google.com, you'll get a 'socket read error' without
usesasl=yes
;buddy=abc@gmail.com
statusmessage="This is my Asterisk server"
timeout=100

Now edit gtalk.conf in /etc/asterisk/

[general]
 context=google-in
 allowguest=yes
 [guest]
 disallow=all
 allow=ulaw
 context=google-in
[buddy]
 ;username=abc@gmail.com
 disallow=all
 allow=ulaw
 context=google-in
connection=gtalk_account

Now edit extension.conf for routing our calls.

[google-in] // Routing in coming calls
exten => s,1,NoOp( Call from Gtalk )
exten => s,n,Set(CALLERID(name)="From Google Talk")
exten => s,n,Dial(SIP/201) // will call a Softphone with extension 200
[google-out] // Routing outgoing calls
exten => 200,1,Dial(gtalk/gtalk_account/abc@gmail.com)

Tags: , ,