Tuesday, December 28, 2010

[Exception_notification For RAILS3 ] git://github.com/rails/exception_notification.git (at master) is not checked out. Please run `bundle install` (Bundler::GitError) [RESOLVED]

[Exception_notification For RAILS3 ] git://github.com/rails/exception_notification.git (at master) is not checked out. Please run `bundle install` (Bundler::GitError) [RESOLVED]

# Add to Gemfile

gem 'exception_notification', :git => "http://github.com/rails/exception_notification.git", :require => 'exception_notifier'

# Add following to config/application.rb or  config/initializers/exception_notification.rb
bash-3.2# cat config/initializers/exception_notification.rb
puts "======Excpetion Notification LOADED"
application3::Application.config.middleware.use ExceptionNotifier,
  :email_prefix => "Staging Capture ERROR: ",
  :sender_address => '"Notifier" ',
  :exception_recipients => ['shrikant.lokhande@gmail.com']

After "git pull" run "bundle install"

if got this Error do:
"bundle install vendor/bundler"

It will Fetch all the gems to bundler, error will go.

Fixed.

Monday, December 27, 2010

[Sinatra] `union': can't convert Array into String (TypeError) [Resolved]

For The Issue Please Do Following Stapes.

First uninstall gem Rack with all version.

# gem uninstall rack
Select gem to uninstall:
 1. rack-1.0.0
 2. rack-1.0.1
 3. rack-1.2.1
 4. All versions
> 4
Successfully uninstalled rack-1.0.0
Successfully uninstalled rack-1.0.1

You have requested to uninstall the gem:
        rack-1.2.1
thin-1.2.7 depends on [rack (>= 1.0.0)]
sinatra-1.1.2 depends on [rack (~> 1.1)]
oauth-0.3.5 depends on [rack (>= 0)]
If you remove this gems, one or more dependencies will not be met.
Continue with Uninstall? [Yn]  y
Successfully uninstalled rack-1.2.1

root@li107-124:/mnt/ntracker/ntrack# gem list rack
*** LOCAL GEMS ***

# gem install rack --version '1.2.0'
Successfully installed rack-1.2.0
1 gem installed
Installing ri documentation for rack-1.2.0...
Building YARD (yri) index for rack-1.2.0...
Installing RDoc documentation for rack-1.2.0...

Now check your application and config.ru with following content.
--------------------------
require 'sinatra'

Sinatra::Application.default_options.merge!(
  :run => false,
  :env => :production
)

require 'App'
run Sinatra.application
----------------------------

Then Start Application with web proxy thin or anything else.
(development environment)
# thin start -p 4500
>> Using rack adapter
>> Thin web server (v1.2.7 codename No Hup)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:4500, CTRL+C to stop
>> Stopping ...

#Use -e for Env. Like this:

# thin start -p 4500 -e staging
or

To start:
# thin -C config/config.yml -R config.ru -e staging start
to stop:
# thin -C config/config.yml -R config.ru -e staging stop

As well as for production.

Thanks-

Tuesday, October 26, 2010

Phusion Passenger Optimization.

If you faceing same as following issue.
Exception NameError in PhusionPassenger::Rack::ApplicationSpawner (uninitialized constant MongoMapper)

Please do the settings. It will really help you.
Also, check your Database Query and cusumption of Memroy on server.
---------------------------------------------
http {
     ..
     PassengerMaxPoolSize 3
     keepalive_timeout  120;
---------------------------------------------

Please let me know, if still you have an issue.

Monday, October 25, 2010

[RSOLVED] [Rails Crontab Not Running]`bin_path': can 't find executable rake for Cronjob not running

Hey Guys,

I have issue with some ruby script and rails, rake script not running as cronjob,
so you can use the following solution.

=============================================
[root@localhost  ] vi /usr/bin/railscron
#! /bin/bash

cd /app/production/current/

PATH=$PATH:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin/

/usr/local/bin/rake  user:details RAILS_ENV=production >> /tmp/test
echo "its running"
==============================================

* Set as Cronjob now:

* 10 * * *  /usr/bin/railscron


Fixed.
If any query, Please let me know. I am here to solve your issue.
Yo.!

Tuesday, October 19, 2010

ActionController::RoutingError No route matches .html

Added extra .html to URL in rails.

If you have added following rewiterules in apache configuration Or added in your .htaccess in your public. Basically its required for the FastCGI. if you run fastCGI server then its need, but if you running Passenger
should be remove
---------------------------------------
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
----------------------------------------

So solution is please remove that from apache config Or remove .htaccess for the passenger only. njoy.!

Tuesday, September 28, 2010

Background Jobs In Rails.

Well, We all know the Rails Deployment  if, not please read my some older post it will really help you
for that.
  Here what i am discussing it is also part of Administration/Deployment. Yes, I am Talking about Background Process. For the Rails application there is way, to run the background task with different ways i.e. as follows.  

BackgroundDrb
Delayed Job
Background Job{aka BJ}
SpawWorkling
BackgroundFu
Rufus Scheduler

You can check RailsCast for the configure and installation, and i will share with you what my experience with Background Jobs, How its works, How to manage, all things.

Monday, August 23, 2010

[PHP+FPM+NGINX] Installtion/Compilation/Confiuration.

Its  Installtion/Compilation/Confiuration of PHP+FPM+NGINX.

Please Follow The Steps One By One, Its Working Configration Tested By Me :0). IF The Any Issue Please Contact Me.

wget http://museum.php.net/php5/php-5.2.8.tar.gz
tar -xvf php-5.2.8.tar.gz
cd php-5.2.8
=========================================
./configure  --enable-fastcgi --enable-fpm --with-mcrypt --with-zlib --enable-mbstring  --with-pgsql --with-curl --disable-debug --enable-pic  --disable-rpath --enable-inline-optimization --with-bz2 --with-xml --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --enable-xslt --enable-memcache --enable-zip --with-pcre-regex --with-curl  --with-curlwrappers --with-ncurses --with-openssl --with-openssl-dir=/usr --with-pdo-mysql=/usr --cache-file=./config.cache' '--with-pcre-regex=/usr --with-mysql-sock=/var/run/mysqld/mysqld.sock --with-gdbm --with-gettext --without-gmp --without-kerberos --enable-mbstring --with-mcrypt --with-mhash --enable-sockets --with-openssl --with-openssl-dir=/usr --with-gd=/usr --with-db4
=========================================
vi /etc/init.d/php-fastcgi

#!/bin/bash
BIND=127.0.0.1:9000
USER=root
PHP_FCGI_CHILDREN=8
PHP_FCGI_MAX_REQUESTS=1000

#PHP_CGI=/usr/bin/php-cgi
PHP_CGI=/usr/local/bin/php-cgi

PHP_CGI_NAME=`basename $PHP_CGI`
PHP_CGI_ARGS="- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND"
RETVAL=0

start() {
      echo -n "Starting PHP FastCGI: "
      start-stop-daemon --quiet --start --background --chuid "$USER" --exec /usr/bin/env -- $PHP_CGI_ARGS
      RETVAL=$?
      echo "$PHP_CGI_NAME."
}
stop() {
      echo -n "Stopping PHP FastCGI: "
      killall -q -w -u $USER $PHP_CGI
      RETVAL=$?
      echo "$PHP_CGI_NAME."
}

case "$1" in
    start)
      start
  ;;
    stop)
      stop
  ;;
    restart)
      stop
      start
  ;;
    *)
      echo "Usage: php-fastcgi {start|stop|restart}"
      exit 1
  ;;
esac
exit $RETVAL

=============================================
vi /etc/nginx/servers/magento.conf

server {
    listen 80;
    server_name domain.com;

        root /home/magento/;

    location / {
        index index.html index.php; ## Allow a static html file to be shown first
      #  try_files $uri $uri/    @handler; ## If missing pass the URI to Magento's front handler
        expires                                 max; ## Assume all files are cachable
        error_page                              404 = @handler;
                log_not_found                   off;
    }

    location ~ /(.*)/index\.php$ { ## strip index.php from product urls
        if (!-e $request_filename) { rewrite ^(.*)/index\.php$ $1/ permanent; }
        }

    location /minify/ { ## Needed for Fooman Speedster
        rewrite ^/minify/([0-9]+)(/.*\.(js|css))$
/lib/minify/m.php?f=$2&d=$1 last;
    }

    ## These locations would be hidden by .htaccess normally
    location /app/                { deny all; }
    location /includes/           { deny all; }
    location /lib/                { deny all; }
    location /lib/minify/         { allow all; }  ## Deny is applied after rewrites so must specifically allow minify
    location /media/downloadable/ { deny all; }
    location /pkginfo/            { deny all; }
    location /report/config.xml   { deny all; }
    location /var/                { deny all; }

    location /var/export/ { ## Allow admins only to view export folder
        auth_basic           "Restricted"; ## Message shown in login window
        auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
    }

    location  /. { ## Disable .htaccess and other hidden files
        return 404;
    }

    location @handler { ## Magento uses a common front handler
        rewrite / /index.php;
    }

    location ~ \.php/ { ## Forward paths like /js/index.php/x.js to relevant handler
        rewrite ^(.*\.php)/ $1 last;
    }

    location ~ \.php$ { ## Execute PHP scripts
        expires                 off; ## Do not cache dynamic content
      #   fastcgi_param   HTTPS $fastcgi_http;
        fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param   PATH_INFO $fastcgi_script_name;
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        fastcgi_param  MAGE_RUN_CODE  base;
        fastcgi_param  MAGE_RUN_TYPE  website;
        include                 fastcgi_params; ## See /etc/nginx/fastcgi_params
    }

}

====================================

Wednesday, July 21, 2010

How to password protect PHP/Wordpress with htpasswd.

First Create .htpasswd file.

htpasswd -c  /opt/app/.htpasswd admin
New password:
Re-type new password:

After that you can add .htaccess in  your application.

vi /opt/app/.htaccess

AuthUserFile /opt/app/.htpasswd
AuthGroupFile /dev/null
AuthName admin
AuthType Basic
require valid-user

# Enable only if you want authentication less access for some specific host.
Allow from 192.168.10.160
Satisfy Any

Wednesday, June 30, 2010

Server Monitoring with ServerSTAT server.STATS (Clook Internet Ltd)

This is Popular and real time monitoring tool. mostly it used for webhosting server. It is alarming system too.
Server.STATS is develop by clook.net
and its very useful tool where you can add multiple servers and monitoring custom ports and server load.
Please check with this image. I have configure monitoring for some major services. e.g. Httpd-MySql-Ftp etc. you can add any ports and whatever you wants no limit. So when its stoped or some services down it showing you red signal immediately with  sound alarm/alerts.
      Also it gives you Server Load if its cross load 5.00 its become red and sound alarm. So no need to always check the page refresh, it send you sound alarm, if you attached spekers to your system.
    Its free tool, which is in php code, if someone need  i can provide you, help you for configuration.


Yo Guys,  lets monitor your server with serverstat. :)

Thursday, June 24, 2010

Check Mysql Master-Slave Replication Script.

This is Mysql Master-Slave Replication Script which is checking position of log. you can set as cron and run.

vi /usr/bin/scriptname

#! /bin/bash
#
# Will Run on LOCAL LAN ON EC2 CLUSTER

SLAVE_HOST=1.2.2.1
SLAVE_PASS=passwd
SLAVE_USER=root

MASTER_PASS=passwd
MASTER_USER=root
MASTER_HOST=1.2.4.2

master_pos=`/usr/local/mysql/bin/mysql -u$SLAVE_USER -p$SLAVE_PASS -h$SLAVE_HOST -e 'show slave status \G;' |grep -r 'Read_Master_Log_Pos' |awk '{ printf " %s ", $2 }' |xargs`


slave_pos=`/usr/local/mysql/bin/mysql -u$MASTER_USER -p$MASTER_PASS -h$MASTER_HOST -e 'show master status;' | grep mysql-bin |awk '{ printf " %s ", $2 }' |xargs`

echo $master_pos
echo $slave_pos

expr $master_pos - $slave_pos

echo $master_pos
echo $slave_pos

Tuesday, June 8, 2010

/usr/libexec/mysqld: Can't change dir to '/data/mysql/' (Errcode: 13) [Resolved]

If you want's to change mysql default data directory or apart of /var/lib/mysql and for this setting you are facing this type of issue:
========================================================================
/usr/libexec/mysqld: Can't change dir to '/data/mysql/' (Errcode: 13)
100607 16:57:44 [ERROR] Aborting

100607 16:57:44 [Note] /usr/libexec/mysqld: Shutdown complete

100607 16:57:44 mysqld ended
========================================================================
Solution.
Just Do.

mysql_install_db --user=mysql --ldata=/data/mysql
mysqld_safe --datadir=/data/mysql --user=mysql &

[root@321 mysql]# /etc/init.d/mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
[root@dh119sj mysql]#

Yo.!

Thursday, May 13, 2010

PHP+FPM Compilation on Centos 5

Requirement:
yum install libmcrypt
yum install libmcrypt-devel

./configure --enable-fastcgi --enable-fpm --with-mcrypt --with-zlib --enable-mbstring --disable-pdo --with-curl --disable-debug --enable-pic --disable-rpath --enable-inline-optimization --with-bz2 --with-xml --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --enable-xslt --enable-memcache --enable-zip --with-pcre-regex

make all install

Friday, April 30, 2010

UDP Protocol Used For Digital Signage.!

I have tested both protocol, both are UDP based and faster download.
Available in interactive mode.

http://tsunami-udp.sourceforge.net/

http://fsp.sourceforge.net/

Thursday, April 15, 2010

Configure staging environment for Phusion Passenger.!

Please follow step-by-step success is your's : LOL

Copy production.rb to staging.rb in config/environments
cd /app/config/environments/
cp production.rb staging.rb

Add a staging entry to your config/database.yml
Your database.yml is should like this :

staging:
adapter: mysql
reconnect: false
database: databae_staging
username: root
password: password
host: localhost
socket: /var/lib/mysql/mysql.sock

Add log file for staging env.
cd log/
touch staging.log
chmod 0666 log/staging.log

For just check. if the env is working for staging.
ruby script/server -e staging

For The Phusion Passenger (mod_rails) You have to put "RailsEnv staging" in your Apache Virtual Host.

Like this:

< virtualhost XX.XX.XX.XX:80 >

RailsEnv staging
< /VirtualHost >

restart apache
and check website.

Sunday, April 11, 2010

shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

Hey Guys,

If you facing issue " shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory " for restarting service whaterver mysql,httpd,etc,

just do "cd or cd / " on console

it will resolved.

[root@domU-taging]# /etc/init.d/mysqld restart
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]

[root@domU-taging]# cd

[root@domU- ~]# /etc/init.d/mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]

cool.;)

Tuesday, January 12, 2010

Ruby on Rails Deployment With Open Source Technology.

What We Need ? and What We Recommended. Ingredient For Deployment Recipes.

Linux: CentOs 5x (Recommended).
Kernel 2.6.x Flavor of any linux, Ubuntu, Gentoo , Or OpenSolaris.

WebServer: Apache(Httpd) Or Nginx (Recommended Stable)

Database : Mysql (Recommended Stable)

ImageMagick: 6.5.8-10 (Recommended Use Latest Version)

Ruby : 1.9.1 (Recommended Latest and Stable)

RubyGems : 1.3.5 (Recommended Latest and Stable)

Rails: 2.3.x (Recommended Latest and Stable)

Web Proxy: Mod_rails, Phusion Passenger. (Recommended Stable)

Let Start on Box.

[root@localhost ~]#yum install httpd httpd-devel mysql-server mysql mysql-devel phpmyadmin php

[root@localhost home]# wget ftp://ftp.fifi.org/pub/ImageMagick/ImageMagick-6.5.6-10.tar.gz

[root@localhost home]# wget ftp://ftp.fifi.org/pub/ImageMagick/ImageMagick-6.5.6-10.tar.gz
--2010-01-12 14:06:16-- ftp://ftp.fifi.org/pub/ImageMagick/ImageMagick-6.5.6-10.tar.gz
=> `ImageMagick-6.5.6-10.tar.gz'
Resolving ftp.fifi.org... 64.81.30.201
Connecting to ftp.fifi.org|64.81.30.201|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD /pub/ImageMagick ... done.
==> SIZE ImageMagick-6.5.6-10.tar.gz ... 11097065
==> PASV ... done. ==> RETR ImageMagick-6.5.6-10.tar.gz ... done.
Length: 11097065 (11M)

100%[==================================================================================================================>] 11,097,065 110K/s in 1m 42s

2010-01-12 14:08:07 (107 KB/s) - `ImageMagick-6.5.6-10.tar.gz' saved [11097065]

tar -xzvf ImageMagick-6.5.6-10.tar.gz

[root@localhost home]# cd ImageMagick-6.5.6-10

[root@localhost ImageMagick-6.5.6-10]# ./configure

[root@localhost ImageMagick-6.5.6-10]# make && make install

Downlaod Ruby and Install.

[root@localhost ~]# wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p376.tar.gz
--2010-01-12 13:28:00-- ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p376.tar.gz
=> `ruby-1.9.1-p376.tar.gz.1'
Resolving ftp.ruby-lang.org... 221.186.184.68
Connecting to ftp.ruby-lang.org|221.186.184.68|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD /pub/ruby/1.9 ... done.
==> SIZE ruby-1.9.1-p376.tar.gz ... 9073007
==> PASV ... done. ==> RETR ruby-1.9.1-p376.tar.gz ... done.
Length: 9073007 (8.7M)

100%[==================================================================================================================>] 9,073,007 217K/s in 54s

2010-01-12 13:28:58 (163 KB/s) - `ruby-1.9.1-p376.tar.gz' saved [9073007]

[root@localhost ~]#tar -xzvf ruby-1.9.1-p376.tar.gz
[root@localhost ~]#cd ruby-1.9.1-p376
[root@localhost ruby-1.9.1-p376]# ./configure
[root@localhost ruby-1.9.1-p376]# make && make install
[root@localhost ruby-1.9.1-p376]# which ruby
/usr/local/bin/ruby
[root@localhost ruby-1.9.1-p376]# /usr/local/bin/ruby -v
ruby 1.9.1p376 (2009-12-07 revision 26041) [i686-linux]

Download and Install RubyGems

[root@localhost home]# wget http://rubyforge.org/frs/download.php/60719/rubygems-1.3.5.zip
--2010-01-12 14:21:38-- http://rubyforge.org/frs/download.php/60719/rubygems-1.3.5.zip
Resolving rubyforge.org... 205.234.109.19
Connecting to rubyforge.org|205.234.109.19|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://files.rubyforge.vm.bytemark.co.uk/rubygems/rubygems-1.3.5.zip [following]
--2010-01-12 14:21:43-- http://files.rubyforge.vm.bytemark.co.uk/rubygems/rubygems-1.3.5.zip
Resolving files.rubyforge.vm.bytemark.co.uk... 80.68.94.54
Connecting to files.rubyforge.vm.bytemark.co.uk|80.68.94.54|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 362863 (354K) [application/zip]
Saving to: `rubygems-1.3.5.zip'

100%[==================================================================================================================>] 362,863 34.6K/s in 15s

2010-01-12 14:22:02 (23.0 KB/s) - `rubygems-1.3.5.zip' saved [362863/362863]

[root@localhost home]# unzip rubygems-1.3.5.zip

[root@localhost home]# cd rubygems-1.3.5

[root@localhost rubygems-1.3.5]# /usr/local/bin/ruby setup.rb
RubyGems 1.3.5 installed

[root@localhost rubygems-1.3.5]# gem -v
1.3.5

[root@localhost rubygems-1.3.5]# gem -v
1.3.5
You have new mail in /var/spool/mail/root
[root@localhost rubygems-1.3.5]# gem install rails
Successfully installed rake-0.8.7
Successfully installed activesupport-2.3.5
Successfully installed activerecord-2.3.5
Successfully installed rack-1.0.1
Successfully installed actionpack-2.3.5
Successfully installed actionmailer-2.3.5
Successfully installed activeresource-2.3.5
Successfully installed rails-2.3.5
8 gems installed
Installing ri documentation for rake-0.8.7...
Installing ri documentation for activesupport-2.3.5...
Installing ri documentation for activerecord-2.3.5...
Installing ri documentation for rack-1.0.1...
Installing ri documentation for actionpack-2.3.5...
Installing ri documentation for actionmailer-2.3.5...
Installing ri documentation for activeresource-2.3.5...
Installing ri documentation for rails-2.3.5...
Updating class cache with 1513 classes...
Installing RDoc documentation for rake-0.8.7...
Installing RDoc documentation for activesupport-2.3.5...
Installing RDoc documentation for activerecord-2.3.5...
Installing RDoc documentation for rack-1.0.1...
Installing RDoc documentation for actionpack-2.3.5...
Installing RDoc documentation for actionmailer-2.3.5...
Installing RDoc documentation for activeresource-2.3.5...
Installing RDoc documentation for rails-2.3.5...
You have new mail in /var/spool/mail/root
[root@localhost rubygems-1.3.5]# gem list rails

*** LOCAL GEMS ***

rails (2.3.5)

Download and Install Passenger

[root@localhost home]#gem install passenger
Building native extensions. This could take a while...
Building native extensions. This could take a while...
Successfully installed fastthread-1.0.7
Successfully installed passenger-2.2.9
2 gems installed
Installing ri documentation for fastthread-1.0.7...
Installing ri documentation for passenger-2.2.9...
Updating class cache with 2543 classes...
Installing RDoc documentation for fastthread-1.0.7...
Installing RDoc documentation for passenger-2.2.9...

[root@localhost rubygems-1.3.5]# passenger-install-apache2-module

-------------------------------------------

Please edit your Apache configuration file, and add these lines:

LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-2.2.9/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-2.2.9
PassengerRuby /usr/local/bin/ruby

After you restart Apache, you are ready to deploy any number of Ruby on Rails
applications on Apache, without any further Ruby on Rails-specific
configuration!
----------------------------------------------

Edit Your httpd.conf and module.
Now Configure your Host in Apache Virtual Host and restart Apache.
/etc/init.d/httpd restart.