/
Rudyfile
184 lines (159 loc) · 7.17 KB
/
Rudyfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# = 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.sysinfo.user do # This is Ruby, so any valid syntax
ls :l, Rudy.sysinfo.home # can be used in the definitions.
end # See: SysInfo gem for more info.
end
display_uptime do # $ rudy display-uptime
script Rudy.sysinfo.user do # NOTE: You can use 'dashes' on the
uptime # command-line instead of underscores
end
end
end