Skip to content

Instantly share code, notes, and snippets.

class Company < ActiveRecord::Base
has_many :stocks
validates_uniqueness_of :symbol
attr_accessor :sdata, :formula, :method_name, :m_keys
def load_sdata
if !@sdata or @sdata.empty?
@sdata = Array.new
stocks = self.stocks
stocks.each_with_index do |s,i|
#
# Chef Client Config File
#
# Dynamically generated by Chef - local modifications will be replaced
#
require 'ohai'
require 'json'
o = Ohai::System.new
@Aslan
Aslan / client.rb
Created March 9, 2010 03:57 — forked from fujin/client.rb
# Chef Client Config File
# Automatically grabs configuration from ohai ec2 metadata.
require 'ohai'
require 'json'
o = Ohai::System.new
o.all_plugins
chef_config = JSON.parse(o[:ec2][:userdata])
if chef_config.kind_of?(Array)
root@domU-12-31-39-09-C4-F4:~# chef-solo -c ~/solo.rb -j ~/chef.json
[Tue, 09 Mar 2010 12:00:03 -0800] INFO: Starting Chef Solo Run
[Tue, 09 Mar 2010 12:00:07 -0800] INFO: Installing package[runit] version 2.0.0-1ubuntu2
[Tue, 09 Mar 2010 12:00:07 -0800] INFO: remote_file[/tmp/chef-solo/preseed/runit/runit-2.0.0-1ubuntu2.seed]: Creating /tmp/chef-solo/preseed/runit/runit-2.0.0-1ubuntu2.seed
[Tue, 09 Mar 2010 12:00:07 -0800] INFO: Pre-seeding package[runit] with package installation instructions.
[Tue, 09 Mar 2010 12:00:13 -0800] INFO: package[runit] sending run action to execute[start-runsvdir] (immediate)
[Tue, 09 Mar 2010 12:00:13 -0800] INFO: Ran execute[start-runsvdir] successfully
[Tue, 09 Mar 2010 12:00:13 -0800] INFO: package[runit] sending nothing action to execute[runit-hup-init] (immediate)
[Tue, 09 Mar 2010 12:00:13 -0800] INFO: Creating directory[/etc/sv/chef-client] at /etc/sv/chef-client
[Tue, 09 Mar 2010 12:00:13 -0800] INFO: Setting mode to 755 for directory[/etc/sv/chef-client]
#!/usr/bin/ruby
instances = `ec2-describe-instances --show-empty-fields`
lines = instances.split(/\n/)
running_instances = []
lines.each do |lines|
if lines =~ /^INSTANCE/
fields = lines.split(/\t/)
if fields[5] == 'running'
running_instances << fields[1]
#!/usr/bin/ruby
# == Synopsis
# This is a tool to help poolpartyrb and chef set haproxy.conf file.
# It also can list clouds and add the new clouds to the chef server i
# security group in order to let the chef clients connect to the chef server
# TODO: list all the ips of a given cloud and list the passenger process(run
# passenger-status remotly on each server).
# Note: At the moment the script would work only if there is a cloud.rb in
# your cwd.
#
cron "add chef-client to crontab to run every 5min" do
command "chef-client >> /etc/sv/chef-client/log/main/current"
user "root"
minute "*/5"
end
cloud "frontend-app" do
using :ec2
user_data File.read('instance_data/frontend_app_qa_user_data.json')
#image_id AMI_32_BIT
image_id AMI_64_BIT
instance_type "m1.large"
instances 1..25
security_group do
authorize :from_port => 22, :to_port => 22, :ip_protocol => 'tcp',:group_name => "admin-server-group" ,:owner_id => xx, :network => ""
authorize :from_port => 80, :to_port => 80
# Completely untested.
gem_package "amazon-ec2"
aws = search("aws", "main")
Gem.clear_paths
ruby_block do "register_with_elb" do
do
require 'amazon-ec2'
[Thu, 29 Apr 2010 00:53:30 +0000] ERROR: remote_file[/tmp/chef-solo/apache-couchdb-0.9.1.tar.gz] (/usr/lib/ruby/gems/1.8/gems/chef-0.8.10/lib/chef/mixin/recipe_definition_dsl_core.rb line 56) had an error:
404 "Not Found"
/usr/lib/ruby/1.8/net/http.rb:2097:in `error!'
/usr/lib/ruby/gems/1.8/gems/chef-0.8.10/bin/../lib/chef/rest.rb:296:in `run_request'
/usr/lib/ruby/gems/1.8/gems/chef-0.8.10/bin/../lib/chef/rest.rb:106:in `get_rest'
/usr/lib/ruby/gems/1.8/gems/chef-0.8.10/bin/../lib/chef/provider/remote_file.rb:107:in `get_from_uri'
/usr/lib/ruby/gems/1.8/gems/chef-0.8.10/bin/../lib/chef/provider/remote_file.rb:53:in `do_remote_file'
/usr/lib/ruby/gems/1.8/gems/chef-0.8.10/bin/../lib/chef/provider/remote_file.rb:34:in `action_create'
/usr/lib/ruby/gems/1.8/gems/chef-0.8.10/bin/../lib/chef/runner.rb:60:in `send'
/usr/lib/ruby/gems/1.8/gems/chef-0.8.10/bin/../lib/chef/runner.rb:60:in `run_action'