Skip to content

Commit

Permalink
Deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhjain committed May 28, 2013
1 parent 38e3dfb commit b44616b
Show file tree
Hide file tree
Showing 14 changed files with 435 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/agents/event_formatting_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class EventFormattingAgent < Agent
message => "Today's conditions look like <$.conditions> and high temperaure is going to be <$.high.celsius> degree Celsius.""
subject => "$.data"
JSONPaths must be between < and > . Make sure you dont use these symbols anywhere else. You can add as many keys as you like.
JSONPaths must be between < and > . Make sure you dont use these symbols anywhere else.
Event generated by Event Formatting Agent will be like
Expand Down
1 change: 0 additions & 1 deletion app/models/agents/twilio_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def post_url(server_url,secret)
end

def receive_webhook(params)
create_event :payload => params
if memory[:pending_calls].has_key? params[:secret].to_sym
response = Twilio::TwiML::Response.new {|r| r.Say memory[:pending_calls][params[:secret].to_sym], :voice => 'woman'}
memory[:pending_calls].delete params[:secret].to_sym
Expand Down
1 change: 1 addition & 0 deletions deployment/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
10 changes: 10 additions & 0 deletions deployment/Cheffile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env ruby
#^syntax detection

site 'http://community.opscode.com/api/v1'

cookbook 'runit'
cookbook 'git', :git => 'git://github.com/opscode-cookbooks/git.git'
cookbook 'nginx', :git => 'git://github.com/opscode-cookbooks/nginx.git'
cookbook 'mysql', :git => 'git://github.com/opscode-cookbooks/mysql.git'
cookbook 'nodejs', :git => 'git://github.com/mdxp/nodejs-cookbook.git'
45 changes: 45 additions & 0 deletions deployment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Install librarian-chef gem

gem install librarian-chef

And Vagrant plugins

vagrant plugin install vagrant-aws
vagrant plugin install vagrant-omnibus

Move to repo directory and run

librarian-chef install

This will install all the cookbooks mentioned in Cheffile.

To install Huginn on AWS, fill the Vagrantfile with your account details and run

vagrant up ec2 --provider=aws

To install it on a virtualbox VM:

vagrant up vb

It'll install huginn and get the server started. You can now go to `yourserver.com/3000` to use huginn if you are in virtualbox. On ec2, pointing to public DNS will let you access huginn. Huginn will be at `/home/huginn/huginn`. A new dedicated user will be created for managing huginn with username `huginn` and password `huginn`. To ssh into ec2:

vagrant ssh ec2

Similarly, to ssh into VirtualBox

vagrant ssh vb

After ssh-ing into ec2, you can start(its already running), stop or restart huginn by

sudo start huginn
sudo stop huginn
sudo restart huginn

To terminate ec2 instance:

vagrant destroy ec2

Similarly, to destroy VirtualBox VM

vagrant destroy vb

63 changes: 63 additions & 0 deletions deployment/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
# Every Vagrant virtual environment requires a box to build off of.
config.omnibus.chef_version = :latest
config.vm.define :vb do |vb|
# vagrant up vb
vb.vm.box = "precise32"
vb.vm.box_url = "http://files.vagrantup.com/precise32.box"
vb.vm.network :forwarded_port, host: 3000, guest: 3000

vb.vm.provision :chef_solo do |chef|
chef.roles_path = "roles"
chef.cookbooks_path = ["cookbooks", "site-cookbooks"]
chef.add_role("huginn_development")
chef.json = {
"mysql"=> {
"server_root_password" => "",
"server_repl_password" => "",
"server_debian_password"=> ""
},
"nginx" => {
'init_style' => "upstart"
}
}
end
end

config.vm.define :ec2 do |ec2|
# vagrant plugin install vagrant-aws
# vagrant plugin install vagrant-omnibus -- So as to make sure chef is installed on ec2 instance
# vagrant up ec2 --provider=aws
ec2.vm.box = "dummy"
ec2.vm.box_url = "https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box"

ec2.vm.provider :aws do |aws, override|
aws.access_key_id = ""
aws.secret_access_key = ""
aws.keypair_name = ""
aws.region = "us-east-1"
aws.ami = "ami-d0f89fb9"

override.ssh.username = "ubuntu"
override.ssh.private_key_path = ""
end
ec2.vm.provision :chef_solo do |chef|
chef.roles_path = "roles"
chef.cookbooks_path = ["cookbooks", "site-cookbooks"]
chef.add_role("huginn_production")
chef.json = {
"mysql"=> {
"server_root_password" => "",
"server_repl_password" => "",
"server_debian_password"=> ""
},
"nginx" => {
'init_style' => "upstart"
}
}
end
end
end
18 changes: 18 additions & 0 deletions deployment/roles/huginn_development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{

"name" : "huginn_development",

"chef_type" : "role",

"json_class" : "Chef::Role",

"description" : "Huginn Development Environment",

"run_list":[
"recipe[git]",
"recipe[apt]",
"recipe[mysql::server]",
"recipe[nodejs::install_from_binary]",
"recipe[huginn_development]"
]
}
19 changes: 19 additions & 0 deletions deployment/roles/huginn_production.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{

"name" : "huginn_production",

"chef_type" : "role",

"json_class" : "Chef::Role",

"description" : "Huginn Production Environment",

"run_list":[
"recipe[git]",
"recipe[apt]",
"recipe[mysql::server]",
"recipe[nodejs::install_from_binary]",
"recipe[nginx]",
"recipe[huginn_production]"
]
}
44 changes: 44 additions & 0 deletions deployment/site-cookbooks/huginn_development/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
include_recipe 'apt'
include_recipe 'build-essential'

%w("ruby1.9.1" "ruby1.9.1-dev" "libxslt-dev" "libxml2-dev" "curl").each do |pkg|
package pkg do
action :install
end
end

git "/usr/local/huginn" do
repository 'git://github.com/cantino/huginn.git'
reference 'master'
action :sync
end

gem_package("rake")
gem_package("bundle")

bash "huginn dependencies" do
user "root"
cwd "/usr/local/huginn"
code <<-EOH
export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
bundle install
sed s/REPLACE_ME_NOW\!/$(rake secret)/ .env.example > .env
rake db:create
rake db:migrate
rake db:seed
EOH
end

#log "huginn start" do
# level :info
# message "Huginn has been installed and wil start at your instance in two minutes"
#end

bash "Huginn has been installed and server will start in a minute" do
user "root"
cwd "/usr/local/huginn"
code <<-EOH
sudo foreman start
EOH
end
59 changes: 59 additions & 0 deletions deployment/site-cookbooks/huginn_production/files/default/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
source 'https://rubygems.org'

gem 'rails'
gem 'rake'
gem 'mysql2'
gem 'devise'
gem 'rails_admin'
gem 'kaminari'
gem 'bootstrap-kaminari-views'
gem "rufus-scheduler", :require => false
gem 'json', '>= 1.7.7'
gem 'jsonpath'
gem 'twilio-ruby'

gem 'delayed_job', :git => 'https://github.com/wok/delayed_job' # Until the YAML issues are fixed in master.
gem 'delayed_job_active_record', "~> 0.3.3" # newer was giving a strange MySQL error
gem "daemons"
# gem "delayed_job_web"
group :production do
gem 'unicorn'
end
gem 'foreman'
gem 'dotenv-rails', :groups => [:development, :test]

group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
gem 'select2-rails'
gem 'jquery-rails'
end

gem 'geokit-rails3'
gem 'kramdown'
gem "typhoeus"
gem 'nokogiri'
gem 'wunderground'

gem "twitter"
gem 'twitter-stream', '>=0.1.16'
gem 'em-http-request'

platforms :ruby_18 do
gem 'system_timer'
gem 'fastercsv'
end

group :development do
gem 'pry'
end

group :development, :test do
gem 'rspec-rails'
gem 'rspec'
gem 'shoulda-matchers'
gem 'rr'
gem 'webmock', :require => false
gem 'rake'
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
web: sudo bundle exec unicorn_rails -c config/unicorn.rb
schedule: sudo bundle exec rails runner bin/schedule.rb
twitter: sudo bundle exec rails runner bin/twitter_stream.rb
dj: sudo bundle exec script/delayed_job run
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#worker_process 2;
#user huginn huginn;

events {
worker_connections 1024;
accept_mutex on;
}

http {
upstream huginn_server {
server unix:/home/huginn/huginn/tmp/sockets/unicorn.sock;
}

server {
listen 80;
server_name _;
keepalive_timeout 5;
root /home/huginn/huginn/public;
try_files $uri/index.html $uri.html $uri @app;
error_page 500 502 503 504 /500.html;
location = /500.html {
root /home/huginn/huginn/public;
}
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header X-Forwarded-Proto $scheme;

proxy_set_header Host $http_host;

proxy_redirect off;

proxy_pass http://huginn_server;
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
app_path = "/home/huginn/huginn"

worker_processes 2
preload_app true
timeout 180
listen '/home/huginn/huginn/tmp/sockets/unicorn.sock'

working_directory app_path

rails_env = ENV['RAILS_ENV'] || 'production'

# Log everything to one file
stderr_path "log/unicorn_out.log"
stdout_path "log/unicorn_err.log"

# Set master PID location
pid '/home/huginn/huginn/tmp/pids/unicorn.pid'

before_fork do |server, worker|
ActiveRecord::Base.connection.disconnect!
old_pid = "#{server.config[:pid]}.oldbin"
if File.exists?(old_pid) && server.pid != old_pid
begin
Process.kill("QUIT", File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
# someone else did our job for us
end
end
end

after_fork do |server, worker|
ActiveRecord::Base.establish_connection
end
Loading

0 comments on commit b44616b

Please sign in to comment.