-->

Monday, June 18, 2012

capistrano deploy and multistage

Just a check list :

cap deploy:setup - use for the first time
cap deploy:check - check that the system is ok and ready for deploy

multi stage example deploy.rb :

set :stages, %w(staging production)
set :default_stage, "staging"
require 'capistrano/ext/multistage'
# since :domain is defined in another file (staging.rb and production.rb),
# we need to delay its assignment until they're loaded
set(:domain) { "#{domain}" }
role(:web) { domain }


And in deploy/staging.rb
set :domain, '111.111.210.211'

set :user, "username"
set :deploy_to, "/home/rubyapps/#{application}"
set :rails_env, "staging"

Use Bitnami Redmine for deploy of my redmine version

I need to deploy Redmine on windows ,to minimize work and issues, I use Bitnami Redmine for windows installer.
I will update the installtion to use my own custom version of redmine , that will be stored on a remote git branch (currently github).

The steps

1. Install redmine stack from bitnami , make sure that every thing is working (browser), then stop all services of Redmine stack.
2.  Goto BitNami\RedmineStack\apps\redmine folder , rename the "htdocs" folder to "htdocs_org" and create a new blank "htdocs" folder.
3. In the blank "htdocs" folder , we will init a new git repo and link it to our remote branch by doing :

cd htdocs
git init
git remote add -t my_work -f origin git://github.com/haimlankry/redmine-1.git
git checkout my_work


At this stage you should have a full redmine project from your git, now will copy some data from the original folder.


4. Copy the folowing folders and files from "htdocs_org" to "htdocs" in the relevant location
root: .bundle, bin , Gemfile.lock 
config/database.yml configuration.rb and additional_environment.rb
tmp/ cache sessions and sockets folder
config\initializers\secret_token.rb

5. Add to the Gemfile the line: gem 'thin' #(if it is not allready in the gemfile)

Test your settings buy starting the thin server, (takes a while on windows) :
start mysql using the service manager utility (or any other way) then type:
bundle exec thin start -e production -p 3001 --prefix /redmine

This should start a thin webserver listens on port 3001 , you can check on the browser for :
http://localhost:3001/redmine
This should result in the redmine home page.

Thats it , now you can develop on your machine , push to git hub, then "git clone" on deploy to get latest update.

Thursday, June 7, 2012

Git And ssh on server

Adding a user to existing server to have git access sup

$ sudo groupadd developers
$ sudo useradd -G developers -d /home/john -m -s /bin/bash john
$ sudo useradd -G developers -d /home/andrew -m -s /bin/bash andrew

$ sudo passwd john
$ sudo passwd andrew

connect users toserver withut pssword , using public key that is in the .ssh/authorized_keys ander the home user folder
Verify that user is owner of /home/username and .ssh and authrization_keys

cd .ssh
chmod og-rw authorized_keys
chmod a-x authorized_keys
cd ~
chmod 700 .ssh
the user public key should have strict access so we need to :
chmod u+rwx /home/ec2-user/.ssh/ -R
chmod a-rwx /home/ec2-user/.ssh/ -R ??? not sure

Tuesday, June 5, 2012

Install apache & passenger for rails on amazon linux

First we need to have apache and curl-dev installed  using root..
sudo -s
yum install httpd httpd-devel
yum install libcurl-devel
exit

# now install passenger , if you have problems with gemfiles , fix them first. (check bundle )
gem install passenger
passenger-install-apache2-module

if all goes good you should get instructions like this :
---------------------------------------------------------------
Please edit your Apache configuration file, and add these lines:

   LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.3-head@smifr/gems/passenger-3.0.12/ext/apache2/mod_passenger.so
   PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-head@smifr/gems/passenger-3.0.12
   PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.3-head@smifr/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!


<VirtualHost *:80>
      ServerName www.yourhost.com
      # !!! Be sure to point DocumentRoot to 'public'!
      DocumentRoot /somewhere/public  
      <Directory /somewhere/public>
         # This relaxes Apache security settings.
         AllowOverride all
         # MultiViews must be turned off.
         Options -MultiViews
      </Directory>
   </VirtualHost>

And that's it! You may also want to check the Users Guide for security and
optimization tips, troubleshooting and other useful information:

  /usr/local/rvm/gems/ruby-1.9.3-head@smifr/gems/passenger-3.0.12/doc/Users guide Apache.html

Enjoy Phusion Passenger, a product of Phusion (www.phusion.nl) :-)
http://www.modrails.com/
------------------------------
follow the instractions and update the httpd.conf file , to find it use the command :
apachectl -V

then restart apache using

apachectl -k restart

# After configuring httpd.conf the restart has an error, you need to provide more rights I did:
passenger-config --root
#Returns path_to_root
chcon -R -h -t httpd_sys_content_t /path_to_root


403 error :
You should set permissions for the rails app , so apache can access these files
I am runing:
chmod 755 /home/ec2-user/ -R

If still not working ..
in file: /etc/sysconfig/selinux
change to SELinux=enforced to SELinux=disabled






Monday, June 4, 2012

install sphinx from source on ec2 linux

sphinx install needs my sql location .
download the sources and extract to folder then installed using :

./configure --prefix=/usr/local/sphinx --with-mysql-includes=/usr/include/mysql51/
make
make install 

PostgreSQL 9 install for rails on centos

sudo -s
# follow instructions in the next link, to install the needed RPM
http://wiki.postgresql.org/wiki/YUM_Installation
#change the name to the version you need
yum install postgresql9
yum install postgresql9-devel
yum install postgresql9-server

service postgresql initdb
service postgresql start
# start on boot
chkconfig --levels 235 postgresql on

# create user that already exists in the system, and should have a database create rights
sudo -u postgres createuser ec2-user -d


# exit from the sudo to the user that is going to be owner of the db (ec2-user in here)
exit

createdb smifr_prod

login to that db with the current user :

psql -d smifr_prod

you should be in the psql console

\q
to exit


set up access to this user throgh rails , it is acting as a loclhost connection so we need to edit :
edit /var/lib/pgsql9/data/pg_hba.conf using root user and set:
local    all         all                                     trust

host    all         all         127.0.0.1/32          trust
host    all         all         ::1/128               trust


TODO : better security method needed here

sudo service postgresql restart

check in the application folder for db connection :


Add local git repo to remote server

On server with a folder named "repos" accessible for the user

mkdir -p repositories/project.git
cd repositories/project.git
git init --bare --shared=group
chgrp -R <developers group> .


On local machine:

git remote add origin haim@IPADDRESS:repos/project.git
git push -u origin master

EC2 linux rvm ruby rails install steps

Steps to install ec2 amazon linux with rails


An old ruby version is required, currently it is intalled by default (v1.8.7), if not, install it using "yum install ruby" .

Steps

sudo -s
yum install -y git gcc-c++ autoconf automake make patch
yum install -y bzip2 readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel iconv-devel

curl -L get.rvm.io | bash -s stable

gpasswd -a ec2-user rvm
source /etc/profile.d/rvm.sh
yum install -y bison
run the follwing to see that things are OK:
rvm requirements 


## for problems with rvm and kernel header file:
vi /etc/yum.conf
change the line to comment : #exclude=kernel*
yum install kernel-headers  
======

Install ruby

rvm install 1.9.3-head


## create a new gemset and set the ruby and gemset to be default by rvm

rvm gemset create mygemset

rvm use 1.9.3-head@mygemset --default

# ruby is ready with rvm , now install rails (without documentation)

gem install rails -v 3.2.2 --no-rdoc --no-ri


next steps:
- install database 
- install passanger with apache