Skip to content

Instantly share code, notes, and snippets.

@abecciu
abecciu / bootstrap_chef_server.rb
Created August 26, 2012 03:03
Little script to bootstrap a chef server
require "fog"
def exec_commands_in_server(server, cmds)
results = server.ssh(cmds) do |stdout, stderr|
$stdout.puts stdout unless stdout.empty?
$stderr.puts stderr unless stderr.empty?
end
unless results.all? { |res| res.status == 0 }
puts "\nWhoops! something went wrong! :("
@abecciu
abecciu / gist:991636
Created May 25, 2011 18:55 — forked from jtimberman/gist:881058
i can has ruby-1.9.2 package with fpm
#!/usr/bin/env bash
sudo apt-get install build-essential libssl-dev libreadline6-dev
sudo gem install fpm
wget ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p180.tar.gz
tar -zxvf ruby-1.9.2-p180.tar.gz
cd ruby-1.9.2-p180
time (./configure --prefix=/usr && make && make install DESTDIR=/tmp/installdir)
cd ..
--- runner.rb.orig 2010-12-03 18:47:21.000000000 -0300
+++ runner.rb 2010-12-03 18:48:16.000000000 -0300
@@ -50,6 +50,9 @@
# Determine the appropriate provider for the given resource, then
# execute it.
def run_action(resource, action)
+ # Resolve lazy/forward references in notifications
+ resource.resolve_notification_references
+
resource.run_action(action)
@abecciu
abecciu / gist:707118
Created November 19, 2010 20:34
run bgrewriteaof without blocking redis
#!/usr/bin/env ruby
require 'rubygems'
require 'redis'
r = Redis.new(:timeout => 1)
append_fsync_val = r.config(:get, 'appendfsync').values.first
puts "Disabling appendfsync..."
r.config(:set, 'appendfsync', 'no')
[Thread debugging using libthread_db enabled]
[New Thread 0x7f248ff936f0 (LWP 1744)]
keysCommand (c=0x69c3ec78) at redis.c:4612
4612 if ((pattern[0] == '*' && pattern[1] == '\0') ||
#0 keysCommand (c=0x69c3ec78) at redis.c:4612
#1 0x000000000040f213 in call (c=0x30ee0948, cmd=0x1444528) at redis.c:2275
#2 0x0000000000419102 in processCommand (c=0x69c3ec78) at redis.c:2459
#3 0x00000000004183d8 in processInputBuffer (c=0x69c3ec78) at redis.c:2673
#4 0x0000000000419bad in readQueryFromClient (el=<value optimized out>,
deploy@redis1:~$ redis-stat latency delay 100 [20/161]
1: 0.52 ms
2: 0.13 ms
3: 0.48 ms
4: 0.34 ms
5: 0.14 ms
6: 0.19 ms
7: 0.47 ms
8: 0.48 ms
9: 0.18 ms
@abecciu
abecciu / gist:660145
Created November 2, 2010 19:27
nginx patch for newrelic queue wait time updated for nginx 0.8
--- src/http/modules/ngx_http_proxy_module.c.orig 2010-08-03 09:59:14.000000000 -0300
+++ src/http/modules/ngx_http_proxy_module.c 2010-11-02 14:58:16.000000000 -0300
@@ -73,6 +73,8 @@
ngx_uint_t headers_hash_max_size;
ngx_uint_t headers_hash_bucket_size;
++ ngx_flag_t queue_wait_hdrs;
} ngx_http_proxy_loc_conf_t;
@abecciu
abecciu / gist:589241
Created September 21, 2010 05:10
nginx patch for queue wait time
--- src/http/modules/ngx_http_proxy_module.c.orig 2010-09-21 02:07:05.000000000 -0300
+++ src/http/modules/ngx_http_proxy_module.c 2010-09-21 02:09:05.000000000 -0300
@@ -74,6 +74,8 @@
ngx_uint_t headers_hash_max_size;
ngx_uint_t headers_hash_bucket_size;
+
+ ngx_flag_t queue_wait_hdrs;
} ngx_http_proxy_loc_conf_t;
@abecciu
abecciu / Dynamic addition of candidate nodes in gen_leader
Created July 30, 2010 03:17
Dynamic addition of candidate nodes in gen_leader
Algorithm
----------
Let's say we have a cluster of nodes A < B < C where A is the leader, and B and C are
candidates. We want to add a new candidate D to the cluster, and we select node B as
the seed node.
When node D is started, the following happens:
(1) D sends a 'join' msg to B, and D starts monitoring B
(2) B replies with a 'hasLeader, A' message
class Ohm::Model
@@associations = ::Hash.new { |hash, key| hash[key] = [] }
@@references = ::Hash.new { |hash, key| hash[key] = [] }
def self.associations
@@associations[self]
end
def associations
self.class.associations