Skip to content

Instantly share code, notes, and snippets.

View boris's full-sized avatar
🇨🇱
Building from home

Boris Quiroz boris

🇨🇱
Building from home
View GitHub Profile
@boris
boris / deploy.rb
Created January 7, 2013 16:17
capistrano send messages to stdout
require 'capistrano/ext/multistage'
set :something
set :morethings
namespace :example do
task :some_task do
puts "\t-----------------------"
puts "\tSome message to the log"
puts "\t-----------------------"
@boris
boris / find_branch.sh
Created January 9, 2013 08:44
sometimes we have a folder 'dev' with many git local copies on it: dev/repo1, dev/repo2, dev/repoN. With this command you can see which branch is checked out on which local copy: .//repo1/.git/HEAD ref: refs/heads/master .//repo2/.git/HEAD ref: refs/heads/boris-local .//repoN/.git/HEAD ref: refs/heads/load-tests (I'm sure there should be another…
#!/bin/bash
for i in `find ./ -iname HEAD| grep .git/HEAD`; do ; echo $i; cat $i; echo ""; done
@boris
boris / environment.json
Created January 10, 2013 10:31
example for creating chef environment
{
"name": "cool_name",
"description": "some description of the environment",
"cookbook_versions": {
},
"json_class": "Chef::Environment",
"chef_type": "environment",
"default_attributes": {
},
"override_attributes": {
@boris
boris / something.sh
Created January 22, 2013 08:19
ssh to "mobile" servers and start chef client.
for i in {1..9}; do; echo mobile-$i && ssh mobile-$i sudo service chef-client start; done
@boris
boris / default.rb
Created April 18, 2013 03:24
dynamic /etc/hosts for chef
hosts = search(:node, "*:*", "X_CHEF_id_CHEF_X asc")
template "/etc/hosts" do
source "hosts.erb"
owner "root"
group "root"
mode 0644
variables(
:hosts => hosts,
:fqdn => node[:fqdn],
@boris
boris / hosts.erb
Created April 18, 2013 03:24
hosts file template for chef
# Generado automagicamente con Chef
127.0.0.1 localhost
# Nodos manejados por Chef
<% @hosts.each do |node| %>
<%= node['ipaddress'] %> <%= node['hostname'] %>
<% end %>
# Shits con IPv6
::1 ip6-localhost ip6-loopback
@boris
boris / npm.rb
Created April 23, 2013 21:30
Instala paquetes con npm luego de instalar NodeJS y npm desde chef. Obviamente que se puede mejorar, pero como sólo hacía falta instalar un paquete (forever), llegué a esa solución en unos 2 minutos. Para ejecutar este codigo, agregar la receta como recipe[nodejs::npm] o bien dentro de un role: "run_list": [ "recipe[nodejs]", "recipe[nodejs::npm…
include_recipe "nodejs"
(...)
bash "install npm packages" do
user "root" # puede ser otro user
code "npm install -g <package>"
end
@boris
boris / ubuntu12.04_bootstrap.rb
Created May 24, 2013 15:30
Chef bootstrap file for Ubuntu 12.04 installing chef from APT repository. Not my favourite, but works pretty fast.
bash -c '
<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>
if [ ! -f /usr/bin/chef-client ]; then
echo "chef chef/chef_server_url string <%= @chef_config[:chef_server_url] %>" | debconf-set-selections
[ -f /etc/apt/sources.list.d/opscode.list ] || echo "deb http://apt.opscode.com precise-0.10 main" > /etc/apt/sources.list.d/opscode.list
wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %>-O- http://apt.opscode.com/[email protected] | apt-key add -
fi
apt-get update
apt-get install -y chef
@boris
boris / watch_query.d
Created August 26, 2013 15:15
This script will print all the queries executed by mysqld process. It should be run passing the PID of mysqld: dtrace -s watch_query.d -p `pgrep -x mysqld`
#!/usr/sbin/dtrace -q
pid$target::*mysql_parse*:entry
{
printf("Query: %s\n", copyinstr(arg1));
}