/
Rudyfile
196 lines (167 loc) · 7.35 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
184
185
186
187
188
189
190
191
192
193
194
195
# = Rudy -- Skeleton configuration
#
# Rudy automatically looks for configuration files in the following
# locations (in this order):
#
# ./.rudy/config
# ~/.rudy/config
#
# ~/.rudy/*.rb
# ./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 five sections: accounts, defaults, machines, commands and routines.
#
# By convention, accounts go in ./.rudy/config or ~/.rudy/config
# machines, commands, routines, and defaults 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
region :'us-east-1' do
ami 'ami-e348af8a' # Alestic Debian 5.0, 32-bit (US)
end
region :'eu-west-1' 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
user :root # User to connect as
size 'm1.small' # EC2 machine type for all machines
# in the 'stage' environment
role :app do # stage-app is the default
end # machine group.
role :db do
positions 1 # 2 machines 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 :balancer do # You can define as many roles
end # as you like. These are just
# a couple examples.
users do # Specify existing private keys per user
#rudy do
# keypair '/path/2/private-key'
#end
end
role :ubuntu do
ami 'ami-1a837773'
root 'ubuntu'
user 'ubuntu'
end
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 :gem_install, '/usr/bin/gem', 'install', :V, '--no-rdoc', '--no-ri'
allow :apt_get, 'apt-get', :y, :q
allow :rubycode do
puts "Some ruby code running in #{self}"
end
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-db
role :db do # and prod-db machine groups.
user :root # The default remote user
startup do # $ rudy startup
adduser :rudy # Create a user called 'rudy'
#
disks do # Define EBS volume routines
create '/rudy/disk1' # Create an EBS volume, attach it, give
end # it a filesystem, and mount it.
#
remote :root 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
remote :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_remote do # Run any pre-reboot tasks like stopping
uptime # web servers and databases.
end #
remote do # Run any startup tasks like starting
uname # processes or initializing the filesystem
end
disks do
mount "/rudy/disk1"
end
end
end
end
# Define global routines available to all machine groups
# This routine will update a basic Debian machine and
# install essential libraries.
# See http://github.com/rudy/arcade
sysupdate do # $ rudy sysupdate
adduser :rudy
remote :root do
apt_get 'update' # Update debian / ubuntu
apt_get 'install', 'build-essential', 'sqlite3', 'libsqlite3-dev'
apt_get 'install', 'apache2-prefork-dev', 'libapr1-dev', 'rubygems'
gem_install 'rudy'
end
end
anything do # $ rudy anything
before :uptime # Specify a dependency
local do # This is Ruby, so any valid syntax
ls :l # can be used in the definitions.
end # See: SysInfo gem for more info.
end
uptime do # $ rudy uptime
local { uptime } # Short block syntax
end
end
# ----------------------------------------------------------- DEFAULTS --------
# These values are used as defaults for their respective global settings. They
# can be overridden by the command-line global options.
#
defaults do
zone :'us-east-1d'
environment :stage
role :app
color true # Terminal colors? true/false
#root 'rootuser' # The "root" account (on Ubuntu, set to "ubuntu")
#user 'someuser' # The default remote user
#localhost 'hostname' # A local hostname instead of localhost
#auto true # Skip interactive confirmation?
#keydir 'path/2/keys/' # The path to store SSH keys
end