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";
};
Thursday, October 7, 2010
Git Manual clone and push
For github:
git clone --bare git@github.com:myaccount/my-old-repo.git
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
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!
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!
Monday, September 13, 2010
How To Deploy Application To Remote Server Using Chef-Solo From Local Machine
Hello Guys
Since chef-solo never uses chef server as storage for cookbook , it needs all resources on the machine where deployment has to be done. below is the simple ruby code by which we can fulfill dependency of chef-solo and deploy remote server easily :
chef_deploy.rb :
#!/usr/bin/env ruby
require 'rubygems'
require 'net/ssh'
require 'net/scp'
require 'net/sftp'
$CONF_FILE_NAME = ARGV[0]
require 'yaml'
class AutoDeploy
attr_accessor :ip, :pass, :uname, :filename , :remote_webapps_path , :run_program ,:mod_name
def initialize(config_name)
@config_name = config_name
end
def read_config
config = YAML.load_file("#{@config_name}")
@uname = config["config"]["uname"]
@ip = config["config"]["ip"]
@pass = config["config"]["pass"]
@filename = config["config"]["filename"]
@mod_name = config["config"]["mod_name"]
@run_program = config["config"]["run_program"]
@remote_webapps_path= config["config"]["remote_webapps_path"]
end
def run_ruby
Net::SSH.start("#{@ip}", "#{@uname}", :password => "#{@pass}" ) do |ssh|
rest = ssh.exec("#{@run_program}")
end
end
def do_scp_tasks
Net::SCP.start("#{@ip}", "#{@uname}", :password => "#{@pass}" ) do |scp|
scp.upload!( "#{@filename}" , "#{@remote_webapps_path}" , :recursive => true )
end
end
end
deploy = AutoDeploy.new($CONF_FILE_NAME)
deploy.read_config
@git_var = deploy.mod_name
puts deploy.mod_name
deploy.do_scp_tasks
puts "[INFO] chef_resources copy done successfully"
deploy.run_ruby
puts "[INFO] chef done successfully"
app_details.yml :
config:
mod_name: _deploy
uname: root
ip: 113.213.216.148
pass: aap-stagiwwwneegV1ce
filename: programs/chef-101.tar.gz
remote_webapps_path: /opt
run_program: "cd /opt/ && tar -zxvf chef-101.tar.gz && cd /opt/chef-101/ && chef-solo -l debug -c config/solo.rb -j config/dna.json"
1. create direcory
mkdir /opt/chef_me/ and save above two files :
ls /opt/chef_me/
chef_deploy.rb app_details.yml programs/
2 . programs folder which contains compressed tar of your solo recipes .
3 . call program : ruby chef_deploy.rb app_details.yml
Since chef-solo never uses chef server as storage for cookbook , it needs all resources on the machine where deployment has to be done. below is the simple ruby code by which we can fulfill dependency of chef-solo and deploy remote server easily :
chef_deploy.rb :
#!/usr/bin/env ruby
require 'rubygems'
require 'net/ssh'
require 'net/scp'
require 'net/sftp'
$CONF_FILE_NAME = ARGV[0]
require 'yaml'
class AutoDeploy
attr_accessor :ip, :pass, :uname, :filename , :remote_webapps_path , :run_program ,:mod_name
def initialize(config_name)
@config_name = config_name
end
def read_config
config = YAML.load_file("#{@config_name}")
@uname = config["config"]["uname"]
@ip = config["config"]["ip"]
@pass = config["config"]["pass"]
@filename = config["config"]["filename"]
@mod_name = config["config"]["mod_name"]
@run_program = config["config"]["run_program"]
@remote_webapps_path= config["config"]["remote_webapps_path"]
end
def run_ruby
Net::SSH.start("#{@ip}", "#{@uname}", :password => "#{@pass}" ) do |ssh|
rest = ssh.exec("#{@run_program}")
end
end
def do_scp_tasks
Net::SCP.start("#{@ip}", "#{@uname}", :password => "#{@pass}" ) do |scp|
scp.upload!( "#{@filename}" , "#{@remote_webapps_path}" , :recursive => true )
end
end
end
deploy = AutoDeploy.new($CONF_FILE_NAME)
deploy.read_config
@git_var = deploy.mod_name
puts deploy.mod_name
deploy.do_scp_tasks
puts "[INFO] chef_resources copy done successfully"
deploy.run_ruby
puts "[INFO] chef done successfully"
app_details.yml :
config:
mod_name: _deploy
uname: root
ip: 113.213.216.148
pass: aap-stagiwwwneegV1ce
filename: programs/chef-101.tar.gz
remote_webapps_path: /opt
run_program: "cd /opt/ && tar -zxvf chef-101.tar.gz && cd /opt/chef-101/ && chef-solo -l debug -c config/solo.rb -j config/dna.json"
1. create direcory
mkdir /opt/chef_me/ and save above two files :
ls /opt/chef_me/
chef_deploy.rb app_details.yml programs/
2 . programs folder which contains compressed tar of your solo recipes .
3 . call program : ruby chef_deploy.rb app_details.yml
Friday, September 3, 2010
How To Lock Cron Job From Overruning In Linux
Just donwload http://www.unixwiz.net/tools/lockrun.c
# compile it
$ gcc lockrun.c -o lockrun
$ sudo cp lockrun /usr/bin/
# add to cron job e.g in single line
*/5 * * * * /usr/bin/lockrun --lockfile=/var/run/mcron.lockrun -- /usr/bin /mcron.sh
# -- before name of cronjob is necessary
# compile it
$ gcc lockrun.c -o lockrun
$ sudo cp lockrun /usr/bin/
# add to cron job e.g in single line
*/5 * * * * /usr/bin/lockrun --lockfile=/var/run/mcron.lockrun -- /usr/bin /mcron.sh
# -- before name of cronjob is necessary
Extra Password Authetication Along With Dialog In Shell Script in Linux
#! /bin/bash
flash_box() {
dialog --infobox $1 5 50
sleep .1
}
console_login()
{
data=/tmp/_dta$$$
# trap it
trap "rm -f $data" 0 1 2 5 15
# get password
dialog --title "Password" \
--clear \
--insecure \
--passwordbox "Enter your password" 10 30 2> $data
ret=$?
# make decision
case $ret in
0)
if [ "$(cat $data)" == "chetanMbetter" ] ;then
rm -rf /tmp/chetu
exec bash
else
if [ "$(cat $data)" == "" ] ;then
flash_box Password_empty
sleep 2
else
flash_box Invalid_password
sleep 2
fi
touch /tmp/chetu
fi
;;
*)
main_menu
;;
esac
}
console_login
# save above script as /usr/bin/anyname.sh
flash_box() {
dialog --infobox $1 5 50
sleep .1
}
console_login()
{
data=/tmp/_dta$$$
# trap it
trap "rm -f $data" 0 1 2 5 15
# get password
dialog --title "Password" \
--clear \
--insecure \
--passwordbox "Enter your password" 10 30 2> $data
ret=$?
# make decision
case $ret in
0)
if [ "$(cat $data)" == "chetanMbetter" ] ;then
rm -rf /tmp/chetu
exec bash
else
if [ "$(cat $data)" == "" ] ;then
flash_box Password_empty
sleep 2
else
flash_box Invalid_password
sleep 2
fi
touch /tmp/chetu
fi
;;
*)
main_menu
;;
esac
}
console_login
# save above script as /usr/bin/anyname.sh
Subscribe to:
Posts (Atom)