Skip to content

Instantly share code, notes, and snippets.

@bvajda
Created August 22, 2011 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bvajda/1162003 to your computer and use it in GitHub Desktop.
Save bvajda/1162003 to your computer and use it in GitHub Desktop.
RoR app server on CentOS 5.6
#/etc/rc.d/init.d/nginx
#!/bin/bash
#
# nginx Startup script for the nginx HTTP Server
#
# chkconfig: 345 85 15
# description: Web server
# processname: nginx: master process /opt/nginx/sbin/nginx
# nginx: worker process
# config: /opt/nginx/conf/nginx.conf
# pidfile: /opt/nginx/logs/nginx.pid
case "$1" in
"start")
/opt/nginx/sbin/nginx
;;
"stop")
/opt/nginx/sbin/nginx -s stop
;;
"graceful_shutdown")
kill -QUIT $( cat /opt/nginx/logs/nginx.pid )
;;
"reload")
/opt/nginx/sbin/nginx -s reload
;;
"testconfig")
/opt/nginx/sbin/nginx -t -c /opt/nginx/conf/nginx.conf
;;
"status")
ps -ef|grep nginx | grep -v grep
;;
"version")
/opt/nginx/sbin/nginx -v
;;
"config")
/opt/nginx/sbin/nginx -V
;;
*)
echo "Usage: $0 (start|graceful_shutdown|stop|reload|testconfig|status)"
;;
esac

install oracle instant client:

download the installer rpm's: basic and sdk (devel) check the cksum

copy to /tmp

rpm -Uvh /tmp/*installer*.rpm
cd /usr/lib/oracle/11.2/client64/lib
ls -s linclntsh.so.11.1 libclntsh.so

add to the PATH and LD_LIBRARY_PATH

vi .bash_profile
...
export PATH=$PATH:/usr/lib/oracle/11.2/client64/lib
export LD_LIBRARY_PATH=/usr/local/oracle/11.2/client64/lib
...

test with the ruby-oci8 gem:

gem install ruby-oci8
ruby -r oci8 -e "OCI8.new('*username*', '*password*', '//*server*:*port*/*service*').exec('select sysdate from dual') { |r| puts r.join }"

Ruby on Rails Application Server on CentOS 5.6

Install CentOS on a server.

Upgrade the packages

yum upgrade

Perform the following steps as root:

make sure that the server time is right. If needed, sync it to a time server with ntpd service.

download and install git:

rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm
yum install --enablerepo=webtatic git

install RVM (http://beginrescueend.com/rvm/install/)

bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

reload shell (or log out and back) to get rvm

install RVM dependencies

rvm notes # => lists dependencies
yum list | grep *package* # => shows if the package is installed
# if not:
rpm -Uvh *uri_to_epel_repository* # e.g. http://download.fedora.redhat.com/pub/epel/5/x86_64/repoview/*package*
# rinse-repeat for each package

test rvm installation:

type rvm | head -1
``` should return "rvm is a function"

set default ruby

    rvm list known # => select rubies to install
    rvm install *selected_ruby*
    rvm use --default *default_ruby*

install Ngnix/Passenger

    gem install passenger
    passenger-install-nginx-module
create start-up script for nginx

    touch /etc/rc.d/init.d/ngnix
    chmod 755 /etc/rc.d/init.d/nginx
    vi /etc/rc.d/init.d/nginx
    # the contents are in the "nginx" file in this gem
make sure the firewall allows http

    lokkit
add nginx to chkconfig (either from /etc/rc.d/init.d/nginx or /etc/init.d/nginx)

    chkconfig --add nginx
make sure no other httpd (Apache) servers are running (just nginx)

    chkconfig --list | grep http # => other servers should be off
    chkconfig --list | grep nginx # => should be "on"
add /opt/nginx/sbin to the path: edit .bash_profile

setup a deploy user with git

make a dir for the app

add the deploy user to the rvm group

    vi /etc/group
    # add "deploy_user" to the end of the rvm row
edit nginx.conf (http://www.modrails.com/documentation/Users%20guide%20Nginx.html#deploying_a_ror_app)

    don't forget to comment out the old root entry!
    
add postgresql client and postgresql-devel and other packages required

    # download pgdg-centos-9.0-2.noarch.rpm from http://yum.pgrpms.org/reporpms/repoview/pgdg-centos.html
    rpm -Uvh http://yum.pgrpms.org/reporpms/9.0/pgdg-centos-9.0-2.noarch.rpm
    yum install /tmp/pgdg-centos-9.0-2.noarch.rpm --nogpgcheck
    # yum info postgresql90.x86_64 --enablerepo=pgdg90
    yum install postgresql90.x86_64 --enablerepo=pgdg90
    yum info postgresql90-devel.x86_64 --enablerepo=pgdg90
    yum install postgresql90-devel.x86_64 --enablerepo=pgdg90
    # add the peel repo
    rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
    yum install libpqxx.x86_64 libpqxx-devel.x86_64 postgresql-odbcng.x86_64 --enablerepo=pgdg90
add path to pg_config to PATH on the root and the deploy users

   echo -e "export PATH=/usr/pgsql-9.0/bin:$PATH" >> .bash_profile

Rails >3.1 => make sure the app has javascript runtime (gem 'execjs', gem 'therubyracer')
pull the git repo

    
install gems

    bundle install --deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment