Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Monday, November 17, 2008

Can't access my VPS via ssh ??

This was the errors message:

PTY allocation request failed on channel 0

Searching around on the internet I found that there is a device ptmx that might be missing with this error message. SO I did the following:

[root]# ls -l /dev/ptmx
ls: /dev/ptmx: No such file or directory


So is that the problem? hmm, I recreated the device:

[root]# /sbin/MAKEDEV -d /dev ptmx


and restarted sshd and Now everything works again!!

Friday, August 15, 2008

mysql gem and mysql NOT from RPM

Have you ever seen this:

>> require 'mysql'
LoadError: libmysqlclient.so.15: cannot open shared object file: No such file or directory - /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.so
from /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.so
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:in `new_constants_in'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require'
from (irb):2


I found this happens when your environment for mysql is not setup correctly. The fix is easy. All you need is to add a file in the /etc/profile.d directory called mysql.sh with the correct exports and re-login...

[root@heimdull log]# cat /etc/profile.d/mysql.sh
export LD_LIBRARY_PATH=/usr/local/mysql/lib:$LD_LIBRARY_PATH
export PATH=/usr/local/mysql/bin:${PATH}


That fixes the binary and library paths... MAKE SURE THERE ARE NO MYSQL RPMS INSTALLED...

rpm -qa | grep mysql should give no mysql-[version] or mysql-server-[version] or mysql-devel-[version]


log-in and out...

install the gem
[root@heimdull ~]# gem install mysql -- --with-mysql-config=`which mysql_config`
Building native extensions. This could take a while...
Successfully installed mysql-2.7
1 gem installed



test the new gem:
[root@heimdull current]# RAILS_ENV=production ruby script/console
Loading production environment (Rails 2.1.0)
>> require 'mysql.so'
=> []
>> puts Mysql::VERSION
20700
=> nil
>> exit

Friday, March 14, 2008

Using awk to sum all entries in one column

Had to search this one for a while... here is the source file:

360109368 15004557 java.lang.String
310090432 7692644 char[]
179389488 7474562 java.util.HashMap$Entry
71350968 70689 java.util.HashMap$Entry[]
14298360 109019 * ConstMethodKlass
7853616 109019 * MethodKlass
7409816 119136 java.lang.Object[]
7302080 17556 int[]
7094864 11288 byte[]

I wanted the sum of all the numbers in the first column and heres the awk line I used:

cat sourcefile | awk '{print $1}' | awk 'BEGIN{sum=0}{sum+=$1}END{print "Total: " sum}'

Monday, January 21, 2008

Mysql driver for rails



When installing the mysql gem you might get this:

Building native extensions.  This could take a while... ERROR:  Error installing mysql: ERROR: Failed to build gem native extension.

the fix is easy but you are going to need the mysql-devel package if you are on redhat then do this:

yum install mysql-devel

Now you can install the mysql driver like this:

gem install mysql -- --with-mysql-config=`which mysql_config`

To test the driver us the rails console:

# ruby script/console
>> require ‘mysql’
>> puts Mysql::VERSION

This should give you the 20700 version. (As of Jan 2007 thats the latest version.)Now enjoy the speed.

Monday, November 19, 2007

Working with Linux LVM

Growing your lvm partition.

  • Find free space:
  • lvm vgs (VFree is amount of free space)
  • Find the the logical volum:
  • lvdisplay (LV Name is what you want)
  • Extend the drive (Add 50GB to current size) : 
  • lvextend –size +50G /dev/drive
  • unmount the drive (If drive is busy use lsof | grep /mountpoint to find the process that is using the mountpoint)
  • e2fsck -f /dev/drive
  • resize2fs /dev/drivemount
  • done

Its best if the drive is umounted before the lvextend command runs. (I have never had issues with this but you never know. ) 

Thursday, September 27, 2007

Deploying with capistrano to servers behind a firewall



First lets install the rsync_with_remote_cache gem:

Check-out from source
svn co http://svn.extendviget.com/lab/trunk/gems/capistrano_rsync_with_remote_cache

Add patch so we will deploy to all roles not just the :app role(this will ensure that migration will work)
vi lib/capistrano/recipes/deploy/strategy/rsync_with_remote_cache.rb

change this:

# Step 2: Update the remote cache.
logger.trace “copying local cache to remote”
find_servers(:roles => :app, :except => { :no_release => true }).each do |server|
system(”rsync -az –delete #{local_cache}/ #{user}@#{server.host}:#{repository_cache}/”)
# TODO: an alternate version that excludes SVN, if we wanted to use an export-like strategy,
# from Andrew Kreiling - however, if we do an svn export locally and then sync it up, it wouldn’t
# include .svn anyway so this may be moot
# system(”rsync -az –delete –exclude=.svn –delete-excluded #{local_cache}/ #{user}@#{server.host}:#{repository_cache}/”)
end

to this:

# Step 2: Update the remote cache.
logger.trace “copying local cache to remote”
find_servers(:except => { :no_release => true }).each do |server|
system(”rsync -az –delete #{local_cache}/ #{user}@#{server.host}:#{repository_cache}/”)
# TODO: an alternate version that excludes SVN, if we wanted to use an export-like strategy,
# from Andrew Kreiling - however, if we do an svn export locally and then sync it up, it wouldn’t
# include .svn anyway so this may be moot
# system(”rsync -az –delete –exclude=.svn –delete-excluded #{local_cache}/ #{user}@#{server.host}:#{repository_cache}/”)
end

Create the gem
rake package

Install the gem
gem install pkg/capistrano_rsync_with_remote_cache-2.1.gem

Verify
gem list capistrano_rsync_with_remote_cache

Now inside of the capistranos deploy.rb file add this
set :deploy_via, :rsync_with_remote_cache

This strategy maintains two cache directories:

    * The local cache directory is a checkout from the Subversion repository. The local cache directory is specified with the local_cache variable in the configuration. If not specified, it will default to “.rsync_cache” in the same directory as the Capfile.

    * The remote cache directory is an rsync copy of the local cache directory. The remote cache directory is specified with the repository_cache variable in the configuration (this name comes from the remote_cache strategy that ships with Capistrano, and has been maintained for compatibility.) If not specified, it will default to “shared/cached-copy” (again, for compatibility with remote_cache.)

Deployment happens in three major steps. First, the local cache directory is processed. If it does not exist, it is created with a checkout of the revision to be deployed. If it exists, but is not a checkout from the repository specified in the configuration, the cache directory is removed, then recreated as if it did not exist. If it exists, and is a checkout from the repository specified, it is updated to the revision to be deployed.

Second, rsync runs on the local side to sync the remote cache to the local cache. When the rsync is complete, the remote cache should be an exact replica of the local cache.

Finally, a copy of the remote cache is made in the appropriate release directory. The end result is the same as if the code had been checked out directly on the remote server, as in the default strategy.

Thursday, July 26, 2007

How to change the timestamp of a file



I ran in to this problem when moving log files around that the timestamp on some of the files changed. And just for consistence I wanted to change the timestamp of these files..

I found that you can specify the data using the touch command, like this:

[heimdull@hostname ~]# touch -t 200709280930 httpd.conf
[heimdull@hostname ~]# ll httpd.conf
-rw-r–r– 1 root root 1558 Sep 28 2007 httpd.conf
[heimdull@hostname ~]#

If you don’t want to change all the timestamps of the file use these options:
-a change only the access time
-m change only the modification time

View the access timestamp(last time the file was accessed)

ls -ul httpd.conf

View the modification time(Last time the files was changed)

ls -tl httpd.conf