пятница, 21 декабря 2012 г.

rails 3 rvm console: cannot load such file -- readline

After installing rvm on Ubuntu sometime I have error when I try to go app console:


current$ bundle exec rails c staging
/home/ubuntu/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/irb/completion.rb:9:in `require': cannot load such file -- readline (LoadError)
from /home/ubuntu/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/irb/completion.rb:9:in `'
from /var/www/apps/staging/newage/shared/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:3:in `require'
from /var/www/apps/staging/newage/shared/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:3:in `'
from /var/www/apps/staging/newage/shared/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:38:in `require'
from /var/www/apps/staging/newage/shared/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:38:in `'
from script/rails:6:in `require'
from script/rails:6:in `
'


Solution:

1. rvm requirements

Requirements for Linux "Ubuntu 12.10"

NOTE: 'ruby' represents Matz's Ruby Interpreter (MRI) (1.8.X, 1.9.X)
             This is the *original* / standard Ruby Language Interpreter
      'ree'  represents Ruby Enterprise Edition
      'rbx'  represents Rubinius

bash >= 4.1 required
curl is required
git is required (>= 1.7 for ruby-head)
patch is required (for 1.8 rubies and some ruby-head's).

To install rbx and/or Ruby 1.9 head (MRI) (eg. 1.9.2-head),
then you must install and use rvm 1.8.7 first.

Additional Dependencies:
# For Ruby / Ruby HEAD (MRI, Rubinius, & REE), install the following:
  ruby: /usr/bin/apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config

# For JRuby, install the following:
  jruby: /usr/bin/apt-get install curl g++ openjdk-6-jre-headless
  jruby-head: /usr/bin/apt-get install ant openjdk-6-jdk

# For IronRuby, install the following:
  ironruby: /usr/bin/apt-get install curl mono-2.0-devel

# For Opal, install the following:
  opal: /usr/bin/apt-get install nodejs npm


2.  sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config

3.  Install readline:

cd  .rvm/src/ruby-1.9.3-p327/ext/readline

ruby extconf.rb
make
sudo make install


The solution from there: http://stackoverflow.com/questions/4922700/ruby-1-9-2-and-rails-3-cannot-open-rails-console

Good luck!

пятница, 13 июля 2012 г.

Moving Mysql database folder to mounted disk

Use the instructions bellow: http://article.my-addr.com/?show=how_to_move_the_mysql_data_directory-ubuntu_change_datadir_issue


How to move the mysql data directory in ubuntu

  • Open the terminal
  • Stop MySQL with the command
    /etc/init.d/mysql stop
  • Copy the existing data directory (which is located in /var/lib/mysql) using the command
    cp -R -p /var/lib/mysql /usr/new_datadir
  • All you need are the data files. Delete the others with the command
    rm /usr/new_datadir

    (You will get a message about not being able to delete some directories, but do not care about them)
  • Edit the MySQL configuration file with the command
    vim /etc/mysql/my.cnf
  • Find the entry for datadir, change the path to the new data directory.
  • But there is a trick involved here. Ubuntu uses some security software called AppArmor that specifies the areas of your filesystem applications are allowed to access. Unless you modify the AppArmor profile for MySQL, you'll never be able to restart MySQL with the new datadir location.
  • In the terminal, enter the command
    vim /etc/apparmor.d/usr.sbin.mysqld
  • Copy the lines beginning with /var/lib/mysql
  • Comment out the originals with hash marks (#),(in my way I just added new lines NOT COMMENT) and paste the lines below the originals.
  • Now change /var/lib/mysql in the two new lines with /usr/new_datadir. Save and close the file.
  • Restart the AppArmor profiles with the command
    /etc/init.d/apparmor restart
  • Restart MySQL with the command
    /etc/init.d/mysql restart
  • MySQL should now start without any errors and your data will be stored in the new location. See also article Linux Ubuntu move mysql database to other path in 5 minutes


четверг, 12 июля 2012 г.

Install Jungledisk on the ubuntu

1. Download server and management files from https://www.jungledisk.com/downloads/business/server/linux/.


To check bit version of your system:


uname -a
Result for 32-bit Ubuntu:
Linux discworld 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:50 UTC 2011 i686 i686i386 GNU/Linux
whereas the 64-bit Ubuntu will show:
Linux discworld 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:50 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux



I prefer .deb for my 64-bit Ubuntu


wget https://downloads.jungledisk.com/jungledisk/junglediskserver_316-0_amd64.deb
wget https://downloads.jungledisk.com/jungledisk/junglediskservermanagement_316-0_amd64.deb


2. Install management first and then server deb:
sudo dpkg -i package_file.deb
or to delete
sudo dpkg -r package_file.deb
to see the list of deb packages:
dpkg --get-selections 


So I done:
sudo dpkg -i junglediskservermanagement_316-0_amd64.deb
sudo dpkg -i junglediskserver_316-0_amd64.deb


3. Then you need to set up licence key:
cp /usr/local/share/junglediskserver/junglediskserver-license-EXAMPLE.xml  /etc/jungledisk/junglediskserver-license.xml
And set up license key in the junglediskserver-license.xml file.


4. Restart the service:
sudo service junglediskserver restart


!!!







Set up couchdb on the Ubuntu server

upd: 1.6.1 for ubuntu 14.04 https://github.com/pixelpark/ppnet/wiki/Install-CouchDB-1.6.1-on-Ubuntu-14.04

UPD: 2 Logrotation: https://www.digitalocean.com/community/tutorials/how-to-manage-log-files-with-logrotate-on-ubuntu-12-10


New way:
http://onabai.wordpress.com/2012/05/10/installing-couchdb-1-2-in-ubuntu-12-04/
https://gist.github.com/jsdavo/3054201

old way(not good at all)
The better way to install couchdb 1.2 on the ubuntu:
https://github.com/iriscouch/build-couchdb

Tunning:

1. Set bind_address to 0.0.0.0 to allow couchdb from outside.
2. Set delayed_commits to false

Don't forget to configure logging!


-Setup log rotate:
First off, a lot of people run CouchDB from source which means that in 99% of all installs, the log rotation is not activated.
To fix this (on Ubuntu/Debian), do the following:
sudo ln -s /usr/local/etc/logrotate.d/couchdb /etc/logrotate.d/couchdb
- Don't forget to change the path to match your installation.

Example:

/usr/local/var/log/couchdb/*.log {
       weekly
       rotate 10
       copytruncate
       delaycompress
       compress
       notifempty
       missingok
}

UPDATE... remembered... it's
Code:
sudo logrotate -f /etc/logrotate.conf

четверг, 14 июня 2012 г.

Ubuntu Rails3 rvm

Original please see: http://thekindofme.wordpress.com/2010/10/24/rails-3-on-ubuntu-10-10-with-rvm-passenger-and-nginx/

Before installation:
sudo apt-get update
sudo apt-get install build-essential git-core curl libmysqlclient-dev nodejs
sudo apt-get install libtool
sudo apt-get install gcc

Install rvm:
curl -L https://get.rvm.io | bash -s stable --ruby

If you have problem due installing nginx(openssl) please see:
http://jamiecurle.co.uk/blog/setting-up-rails-in-ubuntu-10-dot-04-using-nginx-and-passenger/


Install nginx+passenger and make it as service:
https://gist.github.com/sathishmanohar/5491263

Ubuntu ssh keys.

Please see https://help.ubuntu.com/community/SSH/OpenSSH/Keys


mkdir ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -t rsa
sudo service ssh restart
vi .ssh/authorized_keys


Add your local id_rsa.pub to the authorized_keys.

chmod 600 ~/.ssh/authorized_keys


Luck!

Set up new user on the ubuntu.

Add new user:
sudo useradd ubuntu -m -s /bin/bash
Add new group:
# sudo addgroup admin
Add user to group:
# sudo adduser <username> <groupname>
in our case:
# sudo adduser ubuntu admin
Make ubuntu sudoers without password:
 # sudo vi /etc/sudoers
Set up
%admin ALL=NOPASSWD: ALL 
for %admin group.

Check:
#sudo su ubuntu 
sudo ls -ls //should not need password

Good luck!


среда, 30 мая 2012 г.

Как я моунтил диски для Amazon

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html

Есть амазон инстанц с 3 volume.  Второй на 50 гиг но в консоли я его не видел.
Шаги для mount disk

1. sudo mkdir /opt/extra
2. sudo mount /dev/xvdf /opt/extra
3. sudo vi /etc/fstab
LABEL=cloudimg-rootfs   /        ext4   defaults        0 0
/swapfile1 swap swap defaults 0 0
/dev/xvdb       /mnt    auto    defaults,nobootwait,comment=cloudconfig 0       2
/dev/xvdf       /opt/extra      auto    defaults,nobootwait,comment=cloudconfig 0       2

latest row has been added.

4. To check:

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1            7.9G  4.0G  3.6G  54% /
udev                  1.9G  4.0K  1.9G   1% /dev
tmpfs                 752M  156K  752M   1% /run
none                  5.0M     0  5.0M   0% /run/lock
none                  1.9G     0  1.9G   0% /run/shm
/dev/xvdb             394G  199M  374G   1% /mnt
/dev/xvdf              50G  374M   47G   1% /opt/extra

*********************

$ umount /opt/extra
$ mount /opt/extra

should not be errors

*********************
Good lack!

UPD:
Use the lsblk command to view your available disk devices and their mount points (if applicable) to help you determine the correct device name to use.
[ec2-user ~]$ lsblk
NAME  MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
xvdf  202:80   0  100G  0 disk
xvda1 202:1    0    8G  0 disk /

четверг, 17 мая 2012 г.

Update Ubuntu 9.04 to 10.04

Вчера столкнулся с такой проблемой: при установке nginx(rvmsudo passenger-install-nginx-module) на Ubuntu 9.04 необходимо было установить libcurl4-openssl-dev:
$ sudo apt-get install libcurl4-openssl-dev
Однако библиотеки не находились. Ubuntu 9.04 is not supported.
Пришлось обновлять до 10.04.
Общий подход обновления: http://thanhsiang.org/faqing/node/156
Но перед этим нужно поменять archive на old-releases в файле /etc/apt/sources.list в урлах.

После этого nginx установился отлично!

Удачного обновления!



среда, 16 мая 2012 г.

RubyAmp with ruby 1.9

Обновился до 1.9 и обнаружил, что не работает такой полезный textmate bundle, как RubyAmp.
Однако удалось найти fork для него:

в инструкции http://code.leadmediapartners.com/ использовать 

git clone git://github.com/lastobelus/rubyamp.git RubyAMP.tmbundle

вместо оригинального.
Перезапустить textmate и  переустановить gem rb-appscript. 

Немного глючный(появляются всплывающие алерты), но функционал сохранился!

Удачи в использовании!

Monit for rails application on the ubuntu production server

Решил прикрутить monit для рестарта процессов на сервере(Ubuntu)

Коротко про monit и установку: http://www.darkcoding.net/software/setting-up-monit-on-ubuntu/
Мне же нужно было отслеживать nginx, couchdb, delayed_job и sunspot_solr. Для двух последних необходимо использовать rvm для перезапуска процесса. В итоге получился следующий /etc/monit/monitrc файл:

  set daemon  120           # check services at 2-minute intervals
  set logfile /var/log/monit.log

set httpd port 2812
  allow localhost

check process nginx with pidfile /opt/nginx/logs/nginx.pid
    start program = "/etc/init.d/nginx start"
    stop program = "/etc/init.d/nginx stop"

check process couchdb with pidfile /home/ubuntu/build-couchdb/build/var/run/couchdb/couchdb.pid
    start program = "/usr/bin/sudo /home/ubuntu/build-couchdb/build/bin/couchdb -b"
    stop program = "/usr/bin/sudo /home/ubuntu/build-couchdb/build/bin/couchdb -d"

check process sunspot-solr with pidfile /tmp/sunspot-solr-production.pid
    start program = "/bin/su - ubuntu -c 'cd /var/www/apps/xan/current; rvm 1.9.3@xan do rake RAILS_ENV=production sunspot:solr:start'"
    stop program =  "/bin/su - ubuntu -c 'cd /var/www/apps/xan/current; rvm 1.9.3@xan do rake RAILS_ENV=production sunspot:solr:stop'"

check process delayed-job with pidfile /var/www/apps/xan/shared/pids/delayed_job.pid
    start program = "/bin/su - ubuntu -c 'rvm use 1.9.3@xan; RAILS_ENV=production /var/www/apps/xan/current/script/delayed_job start'"
    stop program =  "/bin/su - ubuntu -c 'rvm use 1.9.3@xan; RAILS_ENV=production /var/www/apps/xan/current/script/delayed_job stop'"

 Детали:

Для nginx и couchdb все было просто.
Sunspot-solr запускается rake коммандой c использованием 'rvm rake'(https://rvm.io/set/rake/).
Для delayed-job просто переключился на нужный мне gemset и выполнил комманду.


/bin/su - ubuntu -c 
использовал для имитации shell.

 Удачи в использовании!