Monday, November 1, 2010

Anaconda Installer With Custom Brand/Product name

Mount stage2.img from iso .

edit mount_root/usr/lib/anaconda/product.py

comment the line as below save rebuild stage2.img

[root@localhost anaconda]# cat product.py
#
# product.py: product identification string
#

import os

#if os.access("/tmp/product/.buildstamp", os.R_OK):
#    path = "/tmp/product/.buildstamp"
#elif os.access("/.buildstamp", os.R_OK):
#    path = "/.buildstamp"
#elif os.environ.has_key("PRODBUILDPATH") and \
#         os.access(os.environ["PRODBUILDPATH"], os.R_OK):
#    path = os.environ["PRODBUILDPATH"]
#else:
#    path = None
   
productStamp = ""
productName = "SimpleWall"
productVersion = "bluesky"
productPath = "CentOS"
bugUrl = "Cnetos bugy."

#if path is not None:
#    f = open(path, "r")
#    lines = f.readlines()
#    if len(lines) >= 3:
#        productStamp = lines[0][:-1]
#        productName = lines[1][:-1]
#        productVersion = lines[2][:-1]
#    if len(lines) >= 4:
#    productPath = lines[3][:-1]
#    if len(lines) >= 5:
#        bugUrl = lines[4][:-1]

#if os.environ.has_key("ANACONDA_PRODUCTNAME"):
#    productName = os.environ["ANACONDA_PRODUCTNAME"]
#if os.environ.has_key("ANACONDA_PRODUCTVERSION"):
#    productVersion = os.environ["ANACONDA_PRODUCTVERSION"]
#if os.environ.has_key("ANACONDA_PRODUCTPATH"):
#    productPath = os.environ["ANACONDA_PRODUCTPATH"]
#if os.environ.has_key("ANACONDA_BUGURL"):
#    bugUrl = os.environ["ANACONDA_BUGURL"]

Thats it in short .

How To Connect To Mysql With SSH tunnel

Remote connection of mysql is always pain for security concern ssh tunnel is best option  .


#! /bin/bash
# Copy This script to /usr/bin/

Tunnel_check="`sudo netstat -tulnp 3307 |grep 127.0.0.1:3307`"

if [ "$Tunnel_check" == "" ] ;then
        echo "Tunnel is really Running ?"
        /usr/bin/ssh -2 -f -C -N deploy@ec2-23.45.124.compute-1.amazonaws.com -L 3307/127.0.0.1/3306
else
        echo "Tunnel is Running"
fi

Wednesday, October 20, 2010

Schedule Scripts With Interval of One Second

Cron jobs with default setting has default scheduling time Of 1MIN.
Below is the trick to operate in seconds.
#! /bin/bash
PROCNAME=’/usr/bin/xyz.rb’
PIDS=`ps -efa | grep $PROCNAME | grep -v grep | awk ‘{ print $2 }’`
for ff in $PIDS
do
echo “$ff” > /tmp/w
done
if [ -f "/tmp/w" ] ; then
pid=$(cat /tmp/w)
if [ "$pid" == "" ] ;then
/usr/local/bin/ruby /usr/bin/xyz.rb
else
echo “Already running $pid”
fi
rm -rf /tmp/w
else
/usr/local/bin/ruby /usr/bin/xyz.rb &
fi
Where xyz.rb is simple rb program in loop
require ‘rubygems’
require ‘daemons’
loop do
system(‘/usr/bin/Server_get |xargs >/var/www/html/text.txt’)
system(‘/usr/bin/get_app_stats |xargs >/var/www/html/app_stat.txt’)
sleep (25)
end
At the last  add it to crontab
* * * * * /usr/bin/fast_cron
cheers  its much useful in fast messaging,emailing campaigns .

Thursday, October 7, 2010

Caching and Forward name server on linux

acl trusted {
192.168.0.0/24;
localhost;
};

options {

directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";

forwarders {8.8.8.8;8.8.4.4};
listen-on port 53 { any; };
allow-query { trusted; };
allow-query-cache { trusted; };
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
view localhost_resolver {
match-clients { trusted; };
match-destinations { trusted; };
recursion yes;
include "/etc/named.rfc1912.zones";
};

Git Manual clone and push

For github:

git clone --bare git@github.com:myaccount/my-old-repo.git
cd my-old-repo
git push --mirror git@github.com:mycompany/our-new-repo.git
cd ..
rm -rf my-old-repo

Same can be applicable to private git using gitosis.



Monday, October 4, 2010

Use Memcache As Seesion Store in Rails

Install memcache :

yum install memcached .

chkconfig memcached on

/etc/init.d/memcached restart

Install gem :
gem install memcache-client

Add in environment.rb :

require 'memcache'
CACHE = MemCache.new(:namespace => "myapp)
CACHE.servers = '127.0.0.1:11211'
config.action_controller.session_store = :mem_cache_store

config.action_controller.session = {
:session_key => '_my_session',
:secret => '9abfc85851505e1a08sdfgsdfgsfdsfdgdsfgbb389be2acd0356ae0d4ea383f59cde7140ec7b04df473c31e1d4a4b9b78d55175d0c37bb29852c025d491c5cda9194ae',
:cache => CACHE,
:expires=>900 }

Note :
secret => do rake secret and paste the key .
port => default port is 11211

Clear Session From Database In Ruby On Rails

Create: app/models/session.rb

Session = CGI::Session::ActiveRecordStore::Session
Session.class_eval do
def self.sweep!
delete_all ['updated_at < ?', 15.minutes.ago.utc]
end

Add One cron jobs and swap scheduled :


1 4 * * * /usr/local/bin/ruby /app/apps/current/script/runner -e production Session.sweep!