Skip to content

Instantly share code, notes, and snippets.

@delano
Created December 1, 2016 16:42
Show Gist options
  • Save delano/8edbc88729c93e49efe4135e76a4921d to your computer and use it in GitHub Desktop.
Save delano/8edbc88729c93e49efe4135e76a4921d to your computer and use it in GitHub Desktop.
# = Rudy -- Skeleton configuration
#
# Rudy automatically looks for configuration files in the following
# locations (in this order):
#
# ./.rudy/config
# ~/.rudy/config
#
# ./Rudyfile
# ./machines.rb, ./routines.rb, ./commands.rb
# ./config/rudy/*.rb
# ./.rudy/*.rb
# /etc/rudy/*.rb
#
# When multuple files are found, the configuration is NOT OVERRIDDEN,
# it's ADDED or APPENDED depending on context. This means you can split
# configuration across many files as you please.
#
# There are four sections: accounts, defaults, machines, commands and routines.
#
# By convention, accounts and defaults go in ~/.rudy/config or ./.rudy/config
# machines, commands and routines configuration go in ./Rudyfile or into
# separate files in ./.rudy or ./config/rudy (machines.rb, commands.rb, ...)
#
# --------------------------------------------------------- MACHINES --------
# The machines block describes the "physical" characteristics of your machines.
machines do
zone :"us-east-1b" do
ami 'ami-e348af8a' # Alestic Debian 5.0, 32-bit (US)
end
zone :"eu-west-1b" do
ami 'ami-6ecde51a' # Alestic Debian 5.0, 32-bit (EU)
end
hostname :rudy # One of: :default, :rudy, "your-name"
# We've defined an environment called "stage" with one role: "app".
# The configuration inside the env block is available to all its
# roles. The configuration inside the role blocks is available only
# to machines in that specific role.
env :stage, :prod do
size 'm1.small' # EC2 machine type for all machines
# in the "stage" environment
role :app do
positions 1 # Only 1 machine in stage-app
#addresses '11.22.33.44' # Define an elastic IP to reuse
disks do # Define EBS volumes
path "/rudy/disk1" do # The paths can be anything but
size 2 # they must be unique.
device "/dev/sdr" # Devices must be unique too.
end
end
end
role :db do # You can define as many roles
end # as you like. These are just
role :balancer do # a couple examples.
end
users do # Specify existing private keys per user
#root do
# keypair "/path/2/private-key"
#end
end
end
# The routines section below contains calls to local and remote
# scripts. The config contained in this block is made available
# those scripts in the form of a yaml file. The file is called
# rudy-config.yml.
config do
dbmaster 'localhost'
newparam 573114
end
end
# ----------------------------------------------------------- COMMANDS --------
# The commands block defines shell commands that can be used in routines. The
# ones defined here are added to the default list defined by Rye::Cmd (Rudy
# executes all SSH commands via Rye).
#
# Usage:
#
# allow COMMAND-NAME
# allow COMMAND-NAME, '/path/2/COMMAND'
# allow COMMAND-NAME, '/path/2/COMMAND', 'default argument', 'another arg'
#
commands do
allow :make
allow :gem_install, "/usr/bin/gem", "install", :V, "--no-rdoc", "--no-ri"
allow :apt_get, "/usr/bin/apt-get", :y, :q
end
# ----------------------------------------------------------- ROUTINES --------
# The routines block describes the repeatable processes for each machine group.
# To run a routine, specify its name on the command-line: rudy startup
routines do
env :stage, :prod do # We'll define routines for the stage-app
role :app do # and prod-app machine groups
startup do # $ rudy startup
adduser :rudy # Create a user called "rudy"
authorize :rudy # Enable passwordless logins as rudy
#
disks do # Define EBS volume routines
create "/rudy/disk1" # Create an EBS volume, attach it, give
end # it a filesystem, and mount it.
#
after :rudy do # Run remote SSH commands after startup
mkdir :p, "great" # $ mkdir -p great
touch "great/scott" # $ touch great/scott
ls :l, :a # $ ls -l -a
end
end
shutdown do # $ rudy shutdown
before :root do # Run remote SSH commands before shutdown
uptime
end
disks do
destroy "/rudy/disk1" # Unmount and destroy the EBS volume
end
end
reboot do # $ rudy reboot
before :root do # Run any pre-reboot tasks like stopping
uptime # web servers and databases.
end #
after :root do # Run any startup tasks like starting
uptime # processes or initializing the filesystem
end
end
backup do # $ rudy backup
disks do # A simple routine that creates an EBS
snapshot "/rudy/disk1" # snapshot of the specified volume.
end
end
restore_example do # $ rudy restore_example
disks do # A contrived example of restoring a
destroy "/rudy/disk1" # disk from a backup. NOTE: You'll need
restore "/rudy/disk1" # to run "rudy backup" at least once
end # before otherise there are no backups
end # to restore from.
end
end
# Define global routines available to all machine groups
# This routine will update a basic Debian machine and
# install essential libraries.
# See examples/ for more.
sysupdate do # $ rudy sysupdate
before :root do
apt_get "update" # Update debian / ubuntu
apt_get "install", "build-essential", "sqlite3", "libsqlite3-dev"
apt_get "install", "apache2-prefork-dev", "libapr1-dev"
gem_install 'rudy'
end
end
anything do # $ rudy anything
before :display_uptime # Specify a dependency
script :rudy do # This is Ruby, so any valid syntax
ls :l # can be used in the definitions.
end # See: SysInfo gem for more info.
end
display_uptime do # $ rudy display-uptime
script :rudy do # NOTE: You can use 'dashes' on the
uptime # command-line instead of underscores
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment