-->

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 levelsname <on|off|reset
chkconfig [--level levelsname 

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

Friday, April 13, 2012

sphinx and delayed job on dev after startup

Steps to do to start the delayed job worker
stop all workers :
script/delayed_job stop
Start a new worker with monitoring to screen ( use start instead run to lunch in background)
script/delayed_job run

stop sphinx server
sudo service sphinxsearch stop
build the index and update configuration
rake ts:index
run the search server with the rails configuration
rake ts:start



Monday, April 9, 2012

comment visual block vim

select your lines using visual block: CTRL+v
type I to go to insert mode before the block
type the comment char (e.g. #)
press ESC

Saturday, April 7, 2012

update date from internet on linux

shut down ntp server if runing by :
sudo service ntp stop
update the date and time from internet server 
sudo ntpdate pool.ntp.org
start back the ntp server 
sudo service ntp start

Friday, April 6, 2012

Delayed job startup on rails boot


DELAYED_JOB_PID_PATH = "#{Rails.root}/tmp/pids/delayed_job.pid"

def start_delayed_job
  Thread.new do
    `ruby script/delayed_job start`
  end
end

def process_is_dead?
  begin
    pid = File.read(DELAYED_JOB_PID_PATH).strip
    Process.kill(0, pid.to_i)
    false
  rescue
    true
  end
end

if !File.exist?(DELAYED_JOB_PID_PATH) && process_is_dead?
  start_delayed_job
end

mysql utf support

need to set in the conf file before creating the db :

unders mysqld section :


character-set-server=utf8
collation-server=utf8_general_ci

deploy sphinx rails

using thinking-sphinx gem Config file at :
App/config/sphinx.yml

rake tasks

rake ts:index # create the configuration file based on sphinx.yml and create the index



Thursday, April 5, 2012

Vim folding commands


In visual mode ty zf to fold the visual area.

zf#j creates a fold from the cursor down # lines.
zf/string creates a fold from the cursor to string .
zj moves the cursor to the next fold.
zk moves the cursor to the previous fold.
zo opens a fold at the cursor.
zO opens all folds at the cursor.
zm increases the foldlevel by one.
zM closes all open folds.
zr decreases the foldlevel by one.
zR decreases the foldlevel to zero -- all folds will be open.
zd deletes the fold at the cursor.
zE deletes all folds.
[z move to start of open fold.
]z move to end of open fold.

Passenger monitoring


passenger-memory-stats
passenger-status --verbose

Wednesday, April 4, 2012

Linux commands

w  list of connected users
tty  my connection name
pkill -9 -t pty/0  kill connection pty/0
path global info

global system profile (including ssh session) at :
/etc/bashrc (ssh is non interactive mode, so check for this condition)
/etc/profile
/etc/environment

search for files:  find / -name 'program.c'



MYSSQL on amazon ec2


yum install mysql mysql-server mysql-libs 
service mysqld start
chkconfig --levels 235 mysqld on
mysql_secure_installation


setting to load on boot (as service):


$> chkconfig --level 235 mysqld on


Create the database and user:

mysql -u root -p

create database smifr_prod
grant all privileges on smifr_prod.* to 'smifr'@'localhost' identified by 'thepass';

Gem for mysql : mysql2 , support utf8 , install :

gem install mysql2 -- --with-mysql-dir=/usr/bin --with-mysql-include=/usr/include/mysql --with-mysql-lib=/usr/lib64/mysql --with-mysql-config=/usr/bin/mysql_config