Monday, June 4, 2012

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

Sunday, April 29, 2012

add sphinx to linux boot ( init.d )

add a init file from your app to
/etc/rc.d/init.d/searchd
with the name of the service (for sphinx it is : searchd)

file example :


#!/bin/bash
#
# Init file for searchd
#
# chkconfig: 2345 55 25
#
# description: searchd 
#
# USE "chkconfig --add searchd" to configure Sphinx searchd service
#
# by Vladimir Fedorkov Mar 1, 2006, info@astellar.com
# public domain


BASE_PATH=/usr/local/sphinx/
PID_FILE=/home/rubyapps/smifr/shared/pids/searchd.pid


# point the conf to rails smifr version
# CONFIG_FILE=$BASE_PATH/etc/sphinx.conf
CONFIG_FILE=/home/rubyapps/smifr/current/config/production.sphinx.conf
USER=haim
EXEC_PATH=$BASE_PATH/bin/
LOG_PATH=$BASE_PATH/var/log/
DATA_PATH=$BASE_PATH/var/data/
RETVAL=0
prog="searchd"


do_config() {
mkdir -p $EXEC_PATH
mkdir -p $DATA_PATH
mkdir -p $LOG_PATH


chmod 600 $CONFIG_FILE
chmod u+rwx $EXEC_PATH/*
chmod -R u+rw,go-rwx $DATA_PATH
chmod -R u+rw,go-rwx $LOG_PATH
}


do_start() {
echo "Starting $prog"
sudo -u $USER $EXEC_PATH/$prog --config $CONFIG_FILE
RETVAL=$?
echo
return $RETVAL
}


do_stop() {
echo "Stopping $prog"
if [ -e $PID_FILE ] ; then
kill -15 `cat $PID_FILE`
sleep 5
if [ -e $PID_FILE ] ; then
kill -9 `cat $PID_FILE`
fi
fi
RETVAL=$?
echo
return $RETVAL
}


case $* in


config)
do_config
;;


start)
do_start
;;


stop)
do_stop
;;


*)
echo "usage: $0 {start|stop|config}" >&2


exit 1
;;
esac


exit $RETVAL



then chkconfig --add searchd

where searchd is the service name

then you can do

service searchd start

manage services on linux

Services info: 

chkconfig --list [name] 
chkconfig --add name 
chkconfig --del name 
chkconfig [--level levels] name <on|off|reset> 
chkconfig [--level levels] name 

start mysql service on boot :
chkconfig --levels 235 mysqld on

service utility:

service
service httpd status 
service httpd stop


runing process info :

ps aux | less
ps aux
ps aux | grep searchd 



Wednesday, April 25, 2012

sphinx server ec2 restart

on each deploy if the searchd is running it makes errors so we need to stop it
if rake ts:stop doesnt works then :

pgrep searchd
>> 1944
sudo kill -9 1944

will do the work

more process details:
ps -fw -C searchd

Thursday, April 19, 2012

chmod linux


chmod <people><+/-><permissions>
Example: chmod o-w (deny others from editing the file)
Example: chmod u+rwx (give the owner full control)
Exmaple: chmod +rwx (give everyone full control)
Example: chmod +x (allow anyone to execute the file)


r - Read
w - Write
x - Execute

u - The owner of the file
g - The group that the file belongs to
o - Anybody who is not one of the above
a - All users

+ - Add permissions
- - Remove permissions