Skip to content

Instantly share code, notes, and snippets.

View maurorappa's full-sized avatar

maurorappa maurorappa

  • zerolatency
  • Asso
View GitHub Profile
@maurorappa
maurorappa / s3upload.py
Created April 8, 2016 16:00
S3 upload via proxy (tested with Squid)
import boto
import sys,os.path
from boto.s3.key import Key
file_name=sys.argv[1]
if not os.path.isfile(file_name):
print file_name + " not found!"
sys.exit()
aws_access_key=''
@maurorappa
maurorappa / jenkins-backup.sh
Created October 27, 2016 12:43
Jenkins Backup bash script with all latest job status
#!/bin/bash -xe
##################################################################################
function usage(){
echo "usage: $(basename $0) /path/to/jenkins_home archive.tar.gz"
}
##################################################################################
readonly JENKINS_HOME=$1
readonly DEST_FILE=$2
@maurorappa
maurorappa / gist:f0cbd577d2b2a30dbc273d15de840cc7
Last active November 25, 2016 11:50
MongoDB backup on readonly slaves
You can't simply run a backup on a specific node in a cluster, since its role can change to master and lead to an overload for it.
You need some intelligence to choose the right node (slave) and allow multiple nodes to execute the backup; you want to be safe without
designing a specific node to run it.
This is my approach:
* schedule the script below in any MongoDB host
* the script will exit if it's running on a master
* if it's a slave, it will wait a random interval, check if there's a lock document on the master and if not present perform the backup.
in such a way you are covered from any single node failure
@maurorappa
maurorappa / ssl
Created December 2, 2016 16:02
TCP / SSL connection times measurements
/* ------------------------------------------------------------ *
* file: sslconnect.c *
* ------------------------------------------------------------ *
* file: sslconnect.c *
* purpose: utility to time an SSL connection and *
* to compile: *
* gcc -lssl -lcrypto -o sslconnect sslconnect.c *
* ------------------------------------------------------------ */
#include <sys/socket.h>
@maurorappa
maurorappa / turret.rb
Created December 16, 2016 17:31
Turret: a small service to get notified when Redis Sentinel elects a new master
require 'rubygems'
require 'redis'
require 'uri'
uri = URI.parse('redis://127.0.0.1:26379')
REDIS = Redis.new(:host => uri.host, :port => uri.port)
REDIS.psubscribe('*switch-master' ) do |on|
on.psubscribe do |event, total|
puts "Subscribed to ##{event} (#{total} subscriptions)"
@maurorappa
maurorappa / Vagrantfile
Created January 18, 2017 11:12
Vagrant + Ansible using a single config file
# -*- mode: ruby -*-
# vi: set ft=ruby :
# the envionment variable 'mode' will select the type of deployment from the yml file
require 'yaml'
mode = ENV['mode']
puts ("mode selected: #{mode}")
box_details = YAML.load_file("vagrant_ansible.yml")
@maurorappa
maurorappa / keepalived.conf
Created January 18, 2017 11:14
Keepalived config with VIP bounded on Redis master
! Configuration File for keepalived
global_defs {
}
vrrp_script chk_redis_master {
script "redis-cli info replication|grep master > /dev/null"
interval 2 # check every 2 seconds
weight 2 # add 2 points of prio if OK
}
@maurorappa
maurorappa / gist:9cef7f572ba9954768b8d39165a520b3
Created February 10, 2017 13:13
Interview lab: simple bootstrap file to create a WP machine with some error to fix
#!/bin/sh
yum update
yum install -y unzip php httpd mysql-server mysql php-mysql vim telnet
conf=" \n
[mysqld] \n
port=3307 \n
datadir=/var/lib/mysql \n
socket=/var/lib/mysql/mysql.sock\n
@maurorappa
maurorappa / check-redis.rb
Created February 15, 2017 17:02
Sensu check Redis test
#!/usr/bin/env ruby
# No Frills script with basic dependencies
#
require 'rubygems' if RUBY_VERSION < '1.9.0'
require 'sensu-plugin/check/cli'
require 'socket'
require 'timeout'
class PingRedis < Sensu::Plugin::Check::CLI
FROM centos:latest
MAINTAINER The CentOS Project <cloud-ops@centos.org>
LABEL Vendor="CentOS"
RUN yum -y install sensu erlang rabbitmq-server redis
# rename sample config
RUN mv /etc/sensu/config.json.example /etc/sensu/config.json
# setup rabbitmq
RUN echo $HOSTNAME && /etc/init.d/rabbitmq-server start && rabbitmqctl add_vhost /sensu && rabbitmqctl add_user sensu sensu && rabbitmqctl set_permissions -p /sensu sensu ".*" ".*" ".*"
#start all services
ENTRYPOINT redis-server --daemonize yes && /etc/init.d/rabbitmq-server start && /etc/init.d/sensu-server start && /etc/init.d/sensu-api start && /etc/init.d/sensu-client start && bash