Startup a service that depends on amino
./bin/myservice --conf=/path/to/my/conf
Startup a service using the default conf path
./bin/myservice
template "/etc/network/if-up.d/tcp_keepalive_time" do | |
source "/etc/network/if-up.d/tcp_keepalive_time.erb" | |
owner "root" | |
group "root" | |
mode "0744" | |
end | |
script "change tcp keepalive" do | |
interpreter "bash" | |
user "root" |
# | |
# NOTE: This gist is now deprecated and has been moved into a gem: https://github.com/reidmorrison/mongo_ha | |
# | |
require 'mongo/collection' | |
module Mongo | |
class Collection | |
alias_method :find_one_original, :find_one | |
def find_one(*args) |
We had to deploy ElasticSearch in a particular environment, where our hosts would be connected to Internet and access 2 different subnets, but with some restrictions. This makes our setup somehow tricky as we need the following: | |
eth0: external IP, listening on the Internet. There are iptables rules blocking every connection there on ports 9200 and 9300. | |
eth1: RFC1918 IP address. | |
lo:0: a single RFC1918 address used on every node for IPVS / IPFail for load balancing and fail over purpose. | |
Why is this setup tricky? | |
1. By default, ElasticSearch will listen on eth0 if it exists and is up. Shutting down eth0 and setting it up will just break your setup. Add iptables rules and you'll really be in trouble. Using unicast and a list of IPs won't be enough to solve the issue. | |
#encoding: utf-8 | |
require 'tire' | |
require 'json' | |
require 'active_support/core_ext/object/to_query' | |
require 'active_support/core_ext/object/to_param' | |
conf = { | |
settings: { | |
number_of_shards: 1, | |
number_of_replicas: 0, |
// Underscore mixing for partial functions and async calls. | |
// Based on this microsoft post: http://msdn.microsoft.com/en-us/scriptjunkie/gg575560 | |
_.mixin({ | |
// Turn a normal function into an asynchronous version. | |
// It will return a function that expect's the last argument | |
// to be a callback expecting (err, result) as arguments. | |
wrapAsync: function(fn) { | |
return function() { | |
var args = _(arguments).toArray(); |
# This is a configuration script for using Rainbows with EventMachine. I'm providing it incase somebody finds it useful. But honestly, you | |
# should stop using EventMachine and use threads instead. The ThreadPool version of this is also in my gist list, and I recommend taking a look at that instead. | |
# NO, SERIOUSLY, STOP USING EVENTMACHINE. | |
Rainbows! do | |
name = 'yourappname' | |
use :EventMachine | |
client_max_body_size nil # This is set in nginx | |
# keepalive_timeout 1 |
Startup a service that depends on amino
./bin/myservice --conf=/path/to/my/conf
Startup a service using the default conf path
./bin/myservice
# Fix for a Rails - Ruby 1.9 bug | |
# Rails Router, now that it's UTF-8 default, blows up when routing requests | |
# with invalid chars in the URL; it should properly return a 400 error | |
# Have to monkey-patch the fix in, since it's not scheduled for release until | |
# Rails 4.0. | |
# Adapted Andrew White (pixeltrix)'s fix at | |
# https://github.com/rails/rails/commit/3fc561a1f71edf1c2bae695cafa03909d24a5ca3, | |
# but edited to work in 3.0.x. | |
# 3.1.x, 3.2.x compatibility unknown | |
require 'action_dispatch/routing/route_set' |
# Unicorn self-process killer | |
require ::File.expand_path('../lib/unicorn/unicorn_killer', __FILE__) | |
use UnicornKiller::MaxRequests, 10240 + Random.rand(10240) | |
use UnicornKiller::Oom, 96 * 1024 + Random.rand(32) * 1024 | |
# Out-Of-Band GC | |
require 'unicorn/oob_gc' | |
use Unicorn::OobGC |
// Updated example to utilize 'basic' Domains with express. | |
// Website Scraper that scrapes off a site (without permission I may add) | |
// had seen some screen scraping examples using jQuery this example is jQuery-less. | |
var express = require('express'), | |
request = require('request'), | |
jsdom = require('jsdom'), | |
builder = require('xmlbuilder').create(), | |
sys = require('util'), | |
createDomain = require('domain').create, | |
app = express.createServer(); |