Register now and start sharing your code snippets.
-->

Installing Rails, mongrel and mongrel_cluster on Debian

Shell Script (Bash) posted 8 months ago by christian

DRAFT …

Install RubyGems

   1  http://rubyforge.org/frs/download.php/29548/rubygems-1.0.1.tgz
   2  
   3  tar zxvf rubygems-1.0.1.tgz
   4  
   5  cd rubygems-1.0.1
   6  
   7  ruby setup.rb

Install Rails

   1  gem install rails

Install sqlite3 (optional)

   1  apt-get install sqlite3 libsqlite3-dev
   2  gem install sqlite3-ruby

Install mongrel and mongrel_cluster

   1  $ gem install mongrel mongrel_cluster
   2  
   3  $ mongrel_rails cluster::configure -e production \
   4    -p 8000 \
   5    -a 127.0.0.1 \
   6    -N 3 \
   7    -c /var/www/xyz/current
   8  
   9  
  10  $ mongrel_rails cluster::start
  11  
  12  
  13  $ useradd -g www-data -d /var/www mongrel

Surviving reboots

   1  sudo mkdir /etc/mongrel_cluster
   2  
   3  sudo ln -s /var/www/xyz/config/mongrel_cluster.yml /etc/mongrel_cluster/xyz.yml
   4  
   5  sudo cp /usr/local/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/resources/mongrel_cluster /etc/init.d/
   6  
   7  sudo chmod +x /etc/init.d/mongrel_cluster
   8  
   9  sudo /usr/sbin/update-rc.d -f mongrel_cluster defaults
  10  
  11  mongrel_cluster_ctl status

Stale pids

If your mongrels crash or if you kill them, mongrel_cluster won’t start your mongrels because mongrel_cluster believes the processes are still running, instead mongrel_cluster complains and does nothing:

   1  ** !!! PID file tmp/pids/mongrel.8000.pid already exists.  Mongrel could be running already.  Check your log/mongrel.8000.log for errors.
   2  ** !!! Exiting with error.  You must stop mongrel and clear the .pid before I'll attempt a start.

To fix this simply add the —clean switch to the /usr/local/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/resources/mongrel_cluster startup script:

   1  mongrel_cluster_ctl start -c $CONF_DIR --clean

Tagged rails, ruby, debian, install, sqlite3, mongrel, mongrel_cluster

Installing nginx on Debian

Shell Script (Bash) posted 8 months ago by christian

DRAFT …

Find latest version of nginx

http://sysoev.ru/en/ http://wiki.codemongers.com/NginxInstallOptions

Install a compiler otherwise: ./configure: error: C compiler gcc is not found

The command:

   1  sudo apt-get install build-essential

Install pre-requisites otherwise you’ll get:

Configuration summary + threads are not used + PCRE library is not found + OpenSSL library is not found + md5 library is not used + sha1 library is not used + zlib library is not found

The command:

   1  sudo apt-get install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev

Much better:

Configuration summary + threads are not used + using system PCRE library + using system OpenSSL library + md5 library is not used + sha1 library is not used + using system zlib library

Compile and install nginx

   1  $ ./configure \
   2          --sbin-path=/usr/local/sbin \
   3          --conf-path=/etc/nginx/nginx.conf \
   4          --pid-path=/var/run/nginx.pid \
   5          --error-log-path=/var/log/nginx/error.log \
   6          --http-log-path=/var/log/nginx/access.log \
   7          --with-http_ssl_module \
   8          --http-client-body-temp-path=/tmp/nginx_client \
   9          --http-proxy-temp-path=/tmp/nginx_proxy \
  10          --http-fastcgi-temp-path=/tmp/nginx_fastcgi
  11  $ make
  12  $ sudo make install

Run the install script

   1  cd /usr/local/src
   2  
   3  wget http://sysoev.ru/nginx/nginx-0.5.35.tar.gz
   4  
   5  tar zxvf nginx-0.5.35
   6  
   7  cd nginx-0.5.35

Create an nginx user and group

   1  $ useradd -g www-data -d /var/www nginx

Create the web server directory

   1  mkdir /var/www
   2  chown root.www-data /var/www
   3  chmod ug=rwx,o= /var/www

Test configuration

   1  nginx -t
   2  2008/03/09 20:51:05 [info] 5034#0: the configuration file /etc/nginx/nginx.conf syntax is ok
   3  2008/03/09 20:51:05 [info] 5034#0: the configuration file /etc/nginx/nginx.conf was tested successfully

Start nginx

   1  nginx

Tagged nginx, install, debian

Xen DomU maintenance from Dom0

Shell Script (Bash) posted 8 months ago by christian

   1  xm shutdown xyz
   2  mount -o loop disk.img /mnt/os-image/
   3  chroot /mnt/os-image/
   4  
   5  # Do your stuff
   6  
   7  exit
   8  umount /mnt/os-image

Tagged xen, domu, dom0, maintenance

The meaning of life, the universe and everything

Shell Script (Bash) posted 9 months ago by marko

The meaning of life, the universe and everything.

   1  42
Unfortunately we work under NDA and are not allowed to reveal the question to the meaning of life, the universe and everything. Sorry :(

Tagged the meaning of life the universe and everything

Scheduling jobs to run daily, weekly or monthly with Cron

Shell Script (Bash) posted 9 months ago by christian

Cron syntax and valid values:

   1  # +---------------- minute (0 - 59)
   2  # |  +------------- hour (0 - 23)
   3  # |  |  +---------- day of month (1 - 31)
   4  # |  |  |  +------- month (1 - 12)
   5  # |  |  |  |  +---- day of week (0 - 6) (Sunday=0 or 7)
   6  # |  |  |  |  |
   7    *  *  *  *  *  command to be executed

Below are a few examples on how to run a script every 10 minutes, every 30 minutes, every hour, daily, weekly, monthly.

Execute crontab -e and add the following (see man crontab):

   1  # Every 10 minutes
   2  */10 * * * * /home/belsebub/delete_old_stuff.sh
   3  
   4  # Every 30 minutes
   5  */30 * * * * /home/belsebub/delete_old_stuff.sh
   6  
   7  # Every 60 minutes
   8  */60 * * * * /home/belsebub/delete_old_stuff.sh
   9  
  10  # Every day at 00:00
  11  00 00 * * * /home/belsebub/delete_old_stuff.sh
  12  
  13  # Every saturday at 00:00
  14  00 00 * * 6 /home/belsebub/delete_old_stuff.sh
  15  
  16  # First day of every month at 00:00
  17  00 00 1 * * /home/belsebub/delete_old_stuff.sh

On Debian the configuration goes to /var/spool/cron/crontabs/username.

Tagged cron, scheduling, daily, weekly, monthly