A Shell Script to keep the Datanodes on MySQL NDB Clusters live and stable

January 7th, 2010

When i installed an ndb clusters, i found sometimes one of the datanodes, fails for some reason and they never start again untill it is manually done. So i wrote a shell script for the datanodes to check itself. The script checks in the ndbd process is running, if not its starts the process and writes a log. I added this shell script to the cron job to run the script every 10 minutes. Now the ndb clusters is perfectly stable for some months.

You may ask, 10 mins is too long. Does it mean, the database server will be down for 10 mins. Not beacuse there are more than 1 data node in the cluster, during this 10 mins other nodes will serve.

#!/bin/sh

logfile=/usr/local/mysql-cluster/restart.log

PID=`ps -eo ‘tty pid args’ | grep ‘ndbd’ | grep -v grep | tr -s ” | cut -f2 -d ”`

if [ -z "$PID" ]

then

message=`service ndbd start`

echo “`date` – NDBD started”>>$logfile

fi

Cron job that I added, (edit the file /etc/crontab and add the following line at the end)

*/10 * * * * root /path/to/the/script

This would keep the ndbclusters live for ever.

Rosario Linux, MySql NDB Clusters , ,

Password Protected Wordpress blog

January 6th, 2010

A simple way to have a password protected wordpress.org blog. You may ask, if a blog is to be password protected, what is the need for it. Sometimes we may need a small office or company internal blog which may have confidential information of the company. Here you go

Add the following code to the beginning of the index.php file of the Theme you are using.

<?php
if (!is_user_logged_in()) {
auth_redirect();
}
?>

And thats it…

Rosario Web , , ,

Ubuntu 9.10 Wireless Issue Dell 1330 or BCM4312

January 1st, 2010

To solve this issue you should make sure you have installed the right driver and also you should make sure you removed all the conflicting drivers. Because if there is any conflicting drivers installed it will not allow the kernel to load the right driver.

Packages to be intalled

bcmwl-kernel-source

bcmwl-modaliases

Packages that should not be installed or removed

b43-fwcutter

linux-backports-modules-karmic

linux-backports-modules-karmic-generic

actually no backports-modules need not be installed.

Problems solved

  • detecting wireless connections, but not able to connect.
  • Wireless not working
  • wireless is enabled but doesnt work.

Rosario Linux, Ubuntu , ,

M-Commerce Mobile App – My First J2ME Experience

December 27th, 2009

I am trying to create secure mobile application that would be used for m-commerce. From day one of the development i faced several challenges. I made the application more like a web browser, and the connection using http, (ofcourse finally after development it would be https) for the request and response. I created a cool graphical user interface with Kuix Library.  The J2ME application would interact with a PHP server application and all transactions will be in xml. I made the transactions light weight. Making the application look like it is loading the data from the local. I took care of all the security flaws, hiding most of the implementation from the user.

But still I am not satisfied of the security.

I wanted to create a seperate protocol, to ensure high security. Features

  1. The application should be bound to the mobile number, the user should be able to access the m-commerce service only through the mobile number he/she has registered.
  2. The application should be bound to the SIM card and the mobile itself. More to the SIM card.

Methods

  1. Try to push an sms from the server, on each login with a encrypted session key. After that use that key for every transaction you make in that particular session.
  2. Try to push an SMS with a generated permanent private key, on your first login with the application. Take the signature of the SIM card and save this private key and simcard signature in phone memory. From next login check if the saved signature and SIM signature matches. If so procees with the http login sending the username, password, and the private key.

Challenges in implementation,

  1. Its is very hard to know the mobile number from the J2ME application. There are some methods available, but they are not perfect and differs from each model.
  2. Still wondering if i could read the signature of the simcard, so that i could deactivate the Java application on sim card change.
  3. Waiting for the SMS would incur much time.

Any suggestions are most welcomed. Awaiting your comments

Rosario Applications, Mobile App , ,

Connecting Zantel’s Z-Connect modem to Internet in Linux(Ubuntu)

December 27th, 2009

Z-Connect is one of the fastest wireless modem in Tanzania. Connecting it in Linux was a challenge. Here is the configuration file to connect to the Internet in Linux. I am using Ubuntu.

  • In your terminal give the command

#wvdialconf

  • Edit the file /etc/wvdial.conf with your favorite text editor and overwrite the entire contents with the following

Init2 = AT+CRM=1
Dial Command = ATM1L3DT
Modem Type = Analog Modem
Phone = #777
ISDN = 0
Username = “@zantel.com”
Init1 = ATZ
Password = ” ”
Modem = /dev/ttyUSB0
Baud = 519600

  • Now come to the terminal and type the command

#wvdial

Enjoy Browsing.

Rosario Bash, Internet, Linux, Ubuntu ,

Firebug a gift for WebDevelopers

August 25th, 2009

Firebug is a firefox plugin, which converts a simple browsers into a powerful debugging tool. When I was learning how to develop a Drupal module i came across the term Firebug. Now it has become part of my life. The day i found firebug, I was just thinking why it didn’t come to my sight all these days when i was surfing the net.

Firebug, gives so many reasons for a web developer to use it. May be let me list in what all ways Firebug helped me

  1. It was very hard to find the bugs in Java Script. Most of the time if there is a syntax error, the code would not respond, Firebug often helps me in tracking the bug in the Java script.
  2. Tracing through the HTML code. When you keep your mouse on each HTML, tag below Firebug will highlight the content at the top of the screen. It would be so helpful to trace, which part of the HTML creates a particular segment.
  3. Then it can also trace CSS. Most commonly when you are trying to edit a template to create you website. Firebug when play a greater role in it.
  4. I don’t think its over, but I am using Firebug for all these, still very often it gets updated with new features added.

Firefox is the Browser that i really love and the two plugins Delicious and Firebug have become my intimate these days, helping me every moment.

Rosario Internet, Web , ,

Deploying Django in Apache using mod_wsgi

June 27th, 2009

Deploying Django in Apache using mod_wsgi is the most recommended one when compared to using mod_python. Deploying Django in apache is not very difficult, its simple with quite simple steps. Here i have created a helloworld project and explained how to deploy it in apache. You must install mod_wsgi apache module before trying this.

Step 1: Create an directory named apache in your project directory. And add two files one for conf and another a wsgi application in it.

$mkdir apache

$cd apache

$touch apache_django_wsgi.conf

$touch dj_hello.wsgi

Step 2: Open the apache_django_wsgi.conf file with a text editor(gedit)and add the following contents

WSGIScriptAlias /dj “/path/to/us/project/folder/helloworld/apache/dj_hello.wsgi”

<Directory “/path/to/ur/project/folder/helloworld/apache”>

Allow from all

</Directory>

Here, helloworld is the name of the project

Step 3: Open the dj_hello.wsgi with a text editor(gedit) and add the following contents

import os, sys

#Calculate the path based on the location of the WSGI script.

apache_configuration= os.path.dirname(__file__)

project = os.path.dirname(apache_configuration)

workspace = os.path.dirname(project)

sys.path.append(workspace)

#Add the path to 3rd party django application and to django itself.

sys.path.append(‘/usr/lib/python2.5/site-packages/django/’)

os.environ['DJANGO_SETTINGS_MODULE'] = ‘helloworld.settings’

# project settings file

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()


Step 4: Put an entry in your apache configuration fine (httpd.conf or apache2.conf depending upon the destro you are using)

Include “/path/to/ur/project/folder/helloworld/apache/apache_django_wsgi.conf”

helloworld, is the name of the django project that i am deploying in django. After doing all the steps don’t forget to restart the apache service for the changes to take effect.

Rosario Linux, Python, django , , , ,

IP Bonding or Teaming in Linux – RHEL 5

June 24th, 2009

IP Bonding or Teaming is a method of combining all the network interfaces togather into one with one of the types like Network Fault Tolerance, Round Robin, Back up, Loadbalancing etc. So it looks virtually as a single interface to the outside world providing high availability, based on the type you have set. Means, in a Network fault tolerant type one will take over if other fails and in a Load Balancing type trafic is shared when one busy to the other.

I got a chance of doing IP bonding in a HP Proliant Servers running RHEL 5. Everthing went well with no issues. Let me share my experience with my blog readers. In linux IP bonding is quite simple and is done with some kernel modules and no extra package is to be installed. In Windows, bonging or teaming is done with some software. With HP server, it can easily be done with some HP Network Configuration Uitlities.
Two establish IP bonding you need a minimum of two nework interfaces

Step 1:Check your network interfaces

#ethtool eth0
Settings for eth0:
Supported ports: [ TP MII ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Advertised auto-negotiation: Yes
Speed: 100Mb/s
Duplex: Full
Port: MII
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: g
Wake-on: g
Current message level: 0×00000007 (7)
Link detected: yes

#ethtool eth1
Settings for eth1:
Supported ports: [ TP MII ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Advertised auto-negotiation: Yes
Speed: 100Mb/s
Duplex: Full
Port: MII
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: g
Wake-on: g
Current message level: 0×00000007 (7)
Link detected: yes

Step 2: Check all the requiured kernel modules are available(bonding and mii)

#modprobe –list | grep bonding

/lib/modules/2.6.18-92.el5/kernel/drivers/net/bonding/bonding.ko

# modprobe –list | grep mii

/lib/modules/2.6.18-92.el5/kernel/drivers/net/mii.ko

Step 3: Editing the modprobe.conf file

#vim /etc/modprobe.conf

and add the following lines at the end

alias bond0 bonding

options bond0 mode=1 arp_ip_target=192.168.52.1 arp_interval=200 primary=eth0

To know more about the parameters to be used here use the command

#modinfo bonding

filename: /lib/modules/2.6.18-92.el5/kernel/drivers/net/bonding/bonding.ko

author: Thomas Davis, tadavis@lbl.gov and many others

description: Ethernet Channel Bonding Driver, v3.2.4

version: 3.2.4

license: GPL

srcversion: DB2ABCD47A83F8567EBE92B

depends:

vermagic: 2.6.18-92.el5 SMP mod_unload gcc-4.1

parm: max_bonds:Max number of bonded devices (int)

parm: miimon:Link check interval in milliseconds (int)

parm: updelay:Delay before considering link up, in milliseconds (int)

parm: downdelay:Delay before considering link down, in milliseconds (int)

parm: use_carrier:Use netif_carrier_ok (vs MII ioctls) in miimon; 0 for off, 1 for on (default) (int)

parm: mode:Mode of operation : 0 for balance-rr, 1 for active-backup, 2 for balance-xor, 3 for broadcast, 4 for 802.3ad, 5 for balance-tlb, 6 for balance-alb (charp)

parm: primary:Primary network device to use (charp)

parm: lacp_rate:LACPDU tx rate to request from 802.3ad partner (slow/fast) (charp)

parm: xmit_hash_policy:XOR hashing method: 0 for layer 2 (default), 1 for layer 3+4 (charp)

parm: arp_interval:arp interval in milliseconds (int)

parm: arp_ip_target:arp targets in n.n.n.n form (array of charp)

parm: arp_validate:validate src/dst of ARP probes: none (default), active, backup or all (charp)

parm: fail_over_mac:For active-backup, do not set all slaves to the same MAC. 0 of off (default), 1 for on. (int)

module_sig: 883f35048175a9e6e24e25c96667c37112449509f5739ebf283efa5295d315b73cee5e956f6e25709cbcf2826571c5ffc20f2d87672bb921d610d7

Step 3: Now load the modules

<!– @page { size: 8.27in 11.69in; margin: 0.79in } P { margin-bottom: 0.08in } –>

#modprobe bonding

#modprobe mii

This will create a bond0 config file in the networks-scripts directory

Step 4: Editting the three configuration files for eth0,eth1,bond0

|# vim /etc/sysconfig/network-scripts/ifcfg-bond0

DEVICE=bond0

BOOTPROTO=none

ONBOOT=yes

NETMASK=255.255.255.0

IPADDR=192.168.52.4

USERCTL=no

GATEWAY=192.168.52.1

TYPE=Ethernet

IPV6INIT=no

PEERDNS=yes

#vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

BOOTPROTO=none

ONBOOT=yes

MASTER=bond0

SLAVE=yes

USERCTL=no

TYPE=Ethernet

#vim /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1

BOOTPROTO=none

ONBOOT=yes

MASTER=bond0

SLAVE=yes

USERCTL=no

TYPE=Ethernet

Step5: Restart your networks service

#/etc/init.d/network restart

#ifconfig

Now use ifconfig command to check the, you will look a new interface called bond0 has been created.  The ip you set for it is going to be your ip address of the system. Enjoy bonding

Rosario Bash, Linux, Linux Networking , , ,

Fun with Forkbombs

May 25th, 2009

Try this small shell script in your terminal. To have more fun remote login to others desktops and try this command in the terminal.

:( ){ :| :& };:

This is a strange command in linux which crashes the system. Let me explain what exactly happens when this command is executed.

  • :( ) – Function header where : is the name of the function(Colon and two parenthesis)
  • { Opens the body of the function
  • A blank space is more important here, to have a good syntax
  • : recursive call to the same function(Colon)
  • |- pipes the out put of one function call to another
  • : which calls the function again (Colon)
  • & Forks, creates a child process and assigns the function call to it
  • } Closes the function definition
  • ; delimiter to end the function definition (Semicolon)
  • : actual call to the function(Colon)

So the above script calls recursively itself twice and forks it to a child process indefinitly. At a point the memory gets full and the system crashes. You can gaurd yourself from forkbombs by restricting the number of process that can be executed at a time. Have fun with fork bombs…

Rosario Bash, Linux ,

Some Frequently used Linux Commands

May 24th, 2009

Here are some of the frequently and very useful linux commands

Command Description
top A dynamic task list
ps -e To view the current snapshot of proccess at a time
kill <process-id> Kill a process by specifying its id. Process id can be found from the previous command
killall <process-name> Kill a process with its process name. The process name can be found using ps -e command
fdisk -l Displays the partion table and list of all the memory devices connected to the system
mount /dev/<device-name> /path/to/mountpoint Used to mount a external or internal memory device to the system. The device name can be found from the previous command.
mount -t ntfs-3g /dev/<device-name> /path/to/mountpoint -o force To force mount a memory device which uses ntfs file system
sudo nautilus To open the file browser in root mode. Normally when u open the file browser in ubuntu it will not be in root mode. Provided the currnet user is a sudoer
locate <file-name-pattern> Used to search or find files by their names. Normally the search is done based on a index database. It is good to update the database before searching to get recently created files.
updatedb Used to update the file index database
cat <filename> Display the contents of a file
cat <filename> | grep <pattern> The output of the first command is given as input to the next command using a pipe. Grep command display the lines that has pattern text

Use,   man<command-name> to get more details about all the above commands

Rosario Bash, Linux ,