Skip to content

Instantly share code, notes, and snippets.

View ihassin's full-sized avatar
🏠
Working from home

Itamar Hassin ihassin

🏠
Working from home
View GitHub Profile
@ihassin
ihassin / Reconnect
Created June 3, 2012 14:51
Reconnect to a lost database connection using an exception block trick (ruby, rails, mysql, activerecord)
def my_task
while(true) do
begin
database_access_here
rescue Exception => ex
begin
ActiveRecord::Base.connection.reconnect!
rescue
sleep 10
retry # will retry the reconnect
@ihassin
ihassin / Vagrantfile
Last active February 24, 2020 20:30
Vagrantfile used in the blog entry
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.define :web do |web_config|
web_config.vm.box = "precise64"
web_config.vm.box_url = "http://files.vagrantup.com/precise64.box"
web_config.vm.network :private_network, ip: "33.33.33.33"
web_config.vm.network :forwarded_port, guest: 80, host: 8080
@ihassin
ihassin / user.yml
Last active June 23, 2018 09:56
Ansible user.yml playbook used in blog post
---
- hosts: webservers
user: vagrant
sudo: True
vars_files:
- vars.yml
vars:
deploy: deploy
home_dir: /home/deploy
@ihassin
ihassin / vars.yml
Last active December 31, 2015 09:39
Vars.yml used in the blog post
---
app_name: <APP_NAME>
# created with:
# python -c 'import crypt; print crypt.crypt("<PASS>", "SomeSaltedValue")'
password: SosJkZOQixRak
mysql_root_password: <PASS>
home_dir: "/home/deploy"
repo: <PATH_TO_REPO>
project_ruby: 2.0.0-p353
@ihassin
ihassin / webserver.yml
Last active December 31, 2015 09:39
Ansible webserver.yml playbook used in the blog post
- hosts: webservers
user: vagrant
sudo: True
vars_files:
- vars.yml
vars:
deploy: deploy
home_dir: /home/deploy
tasks:
- hosts: webservers
user: vagrant
vars_files:
- vars.yml
tasks:
- name: Download ruby
get_url: "url={{ruby_url}} dest={{ruby_dir}}/ruby-{{ project_ruby }}.tar"
- name: Extract ruby
@ihassin
ihassin / project.yml
Last active December 31, 2015 09:39
Ansible project.yml playbook for blog post
- hosts: webservers
user: deploy
vars_files:
- vars.yml
tasks:
- name: Make directory for database.yml
shell: mkdir -p {{home_dir}}/rails/narui/shared/config
- name: Copy database.yml
@ihassin
ihassin / deploy.rb
Created December 24, 2013 00:11
Capistrano 3 script to deploy the app
set :application, '<APP_NAME>'
set :repo_url, "<git@PATH/REPO.git>"
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
set :deploy_to, "/home/deploy/rails/<APP_NAME>"
# set :scm, :git
set :format, :pretty
set :log_level, :debug
@ihassin
ihassin / dbserver.yml
Created December 24, 2013 00:17
Ansible script to install mySQL
- hosts: webservers
user: vagrant
sudo: true
vars_files:
- vars.yml
tasks:
- name: Install MySQL
action: apt pkg=$item state=installed
with_items:
@ihassin
ihassin / production.rb
Created December 24, 2013 00:31
config/deploy/production.rb - Capistrano file to deploy
set :stage, :production
# Simple Role Syntax
# ==================
# Supports bulk-adding hosts to roles, the primary
# server in each group is considered to be the first
# unless any hosts have the primary property set.
role :app, %w{deploy@33.33.33.33}
role :web, %w{deploy@33.33.33.33}
role :db, %w{deploy@33.33.33.33}