Skip to content

Instantly share code, notes, and snippets.

@rahul100885
rahul100885 / monitor_passenger_rails_instances
Created February 11, 2011 05:08
This script will kill a rails instance which is taking more than 500 MB and retsrat a request if it has served 100 requests
#!/bin/sh
while true; do
passenger-memory-stats | grep Rails:\ /home | awk ' { if($2 > 500) print "kill -9 " $1}' | bash
# above line will kill all the rails instances which are using memory more than 500MB
passenger-status | grep Processed: | awk ' { if($7 > 100) print "kill -6 " $3}' | bash
# above line will abort all rails instance who have processed 100 request.
@rahul100885
rahul100885 / sphinx
Created May 19, 2011 15:31
Simple starup service using ruby
#!/usr/bin/env ruby
RAILS_CODE_PATH='/home/rahul/workspace/livia_portal_3/livia_portal/'
RAKE_PATH='/usr/local/rvm/gems/ree-1.8.7-2010.02@global/bin/rake'
USER="rahul"
case ARGV[0]
when "start"
STDOUT.puts "called start"
system "su - #{USER} -c \"cd #{RAILS_CODE_PATH} && #{RAKE_PATH} ts:rebuild\""
@rahul100885
rahul100885 / nginx.conf
Created August 17, 2011 08:44
Nginx configuration for force https and www url
user deploy;
worker_processes 6;
events {
worker_connections 1024;
}
http {
passenger_root /usr/local/rvm/gems/ree-1.8.7-2011.03/gems/passenger-3.0.7;
@rahul100885
rahul100885 / redis.conf
Created August 23, 2011 06:32
Configuration for redis
# Redis configuration file example
# Note on units: when memory size is needed, it is possible to specifiy
# it in the usual form of 1k 5GB 4M and so forth:
#
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
#! /bin/sh
### BEGIN INIT INFO
# Provides: redis-server
# Required-Start: $syslog $remote_fs
# Required-Stop: $syslog $remote_fs
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-server - Persistent key-value db
@rahul100885
rahul100885 / redmine_heroku_deploy.sh
Created September 26, 2011 07:48
Deploy Redmine to Heroku
#!/bin/bash
set -e
REDMINE_URL="http://rubyforge.org/frs/download.php/75097/redmine-1.2.1.tar.gz"
S3_ACCESS_KEY_ID=""
S3_SECRET_ACCESS_KEY=""
S3_BUCKET_NAME=""
HEROKU_APP_NAME=""
@rahul100885
rahul100885 / nginx.conf
Created October 14, 2011 08:33
Sample nginx file for web application with gzip and cache
user www-user;
worker_processes 1;
error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;
pid logs/nginx.pid;
@rahul100885
rahul100885 / passenger_status.rb
Created October 31, 2011 09:42 — forked from dan-manges/passenger_status.rb
munin plugin for passenger
#!/usr/bin/env ruby
def output_config
puts <<-END
graph_category App
graph_title passenger status
graph_vlabel count
sessions.label sessions
max.label max processes
require "benchmark"
val = (1..9).to_a
Benchmark.bm(7) do |x|
x.report("if:") {
val.each { |v|
if v == 9
a = 9
elsif v == 8
@rahul100885
rahul100885 / bench1.rb
Created December 22, 2011 09:45
Benchmarking for uuid and hex(16)
require 'benchmark'
require 'securerandom'
Benchmark.bm(7) do |x|
x.report("UUID") { SecureRandom.uuid }
x.report("hex(16)") { SecureRandom.hex(16) }
end
#Output