Skip to content

Instantly share code, notes, and snippets.

@heynemann
Created July 3, 2011 04:26
Show Gist options
  • Save heynemann/1061953 to your computer and use it in GitHub Desktop.
Save heynemann/1061953 to your computer and use it in GitHub Desktop.
provy sample code 2
servers = {
'frontend': {
'address': '33.33.33.33',
'user': 'vagrant',
'roles': [
FrontEnd
],
'options': {
'mysql-db-password':
AskFor('mysql-db-password',
'Please enter the password for the app database')
}
}
}
user {{ user }};
worker_processes 1;
error_log /home/frontend/error.log;
pid /home/frontend/nginx.pid;
events {
worker_connections 1024;
use epoll;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /home/frontend/nginx.access.log;
keepalive_timeout 65;
proxy_read_timeout 200;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
gzip on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/css text/xml
application/x-javascript application/xml
application/atom+xml text/javascript;
proxy_next_upstream error;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
$ provy --help
Usage: console.py [options]
Options:
-h, --help show this help message and exit
-s SERVER, --server=SERVER
Servers to provision with the specified role. This is
a recursive option.
-p PASSWORD, --password=PASSWORD
Password to use for authentication with servers.
If passwords differ from server to server this does
not work.
#!/usr/bin/python
# -*- coding: utf-8 -*-
from provy.core import Role
from provy.more.debian import UserRole, TornadoRole
class FrontEnd(Role):
def provision(self):
pass
class BackEnd(Role):
def provision(self):
with self.using(UserRole) as role:
role.ensure_user('frontend', identified_by='pass', is_admin=True)
self.update_file('website.py', '/home/frontend/website.py', owner='frontend')
self.provision_role(TornadoRole)
servers = {
'test': {
'frontend': {
'address': '33.33.33.33',
'user': 'vagrant',
'roles': [
FrontEnd
]
},
'backend': {
'address': '33.33.33.34',
'user': 'vagrant',
'roles': [
BackEnd
]
}
}
}
#!/usr/bin/python
# -*- coding: utf-8 -*-
from provy.core import Role
from provy.more.debian import UserRole, TornadoRole, SupervisorRole
class FrontEnd(Role):
def provision(self):
pass
class BackEnd(Role):
def provision(self):
with self.using(UserRole) as role:
role.ensure_user('frontend', identified_by='pass', is_admin=True)
self.update_file('website.py', '/home/frontend/website.py', owner='frontend')
self.provision_role(TornadoRole)
# make sure we have a folder to store our logs
self.ensure_dir('/home/backend/logs', owner='backend')
with self.using(SupervisorRole) as role:
role.config(
config_file_directory='/home/backend',
log_file='/home/backend/logs/supervisord.log',
user='backend'
)
with role.with_program('website') as program:
program.directory = '/home/backend'
program.command = 'python website.py 800%(process_num)s'
program.number_of_processes = 4
program.log_folder = '/home/backend/logs'
servers = {
'test': {
'frontend': {
'address': '33.33.33.33',
'user': 'vagrant',
'roles': [
FrontEnd
]
},
'backend': {
'address': '33.33.33.34',
'user': 'vagrant',
'roles': [
BackEnd
]
}
}
}
#!/usr/bin/python
# -*- coding: utf-8 -*-
from provy.core import Role
from provy.more.debian import UserRole, TornadoRole, SupervisorRole, NginxRole
class FrontEnd(Role):
def provision(self):
with self.using(UserRole) as role:
role.ensure_user('frontend', identified_by='pass', is_admin=True)
with self.using(NginxRole) as role:
role.ensure_conf(conf_template='nginx.conf', options={'user': 'frontend'})
role.ensure_site_disabled('default')
role.create_site(site='website', template='website')
role.ensure_site_enabled('website')
class BackEnd(Role):
def provision(self):
with self.using(UserRole) as role:
role.ensure_user('frontend', identified_by='pass', is_admin=True)
self.update_file('website.py', '/home/frontend/website.py', owner='frontend')
self.provision_role(TornadoRole)
# make sure we have a folder to store our logs
self.ensure_dir('/home/backend/logs', owner='backend')
with self.using(SupervisorRole) as role:
role.config(
config_file_directory='/home/backend',
log_file='/home/backend/logs/supervisord.log',
user='backend'
)
with role.with_program('website') as program:
program.directory = '/home/backend'
program.command = 'python website.py 800%(process_num)s'
program.number_of_processes = 4
program.log_folder = '/home/backend/logs'
servers = {
'test': {
'frontend': {
'address': '33.33.33.33',
'user': 'vagrant',
'roles': [
FrontEnd
]
},
'backend': {
'address': '33.33.33.34',
'user': 'vagrant',
'roles': [
BackEnd
]
}
}
}
$ vagrant up
$ provy -s test
$ curl http://33.33.33.33
class MyRole(Role):
def provision(self):
self.provision_role(TornadoRole)
class MyRole(Role):
def provision(self):
with self.using(AptitudeRole) as role:
# do something with role
role.ensure_package_installed('some-package')
upstream frontends {
server 33.33.33.34:8000;
server 33.33.33.34:8001;
server 33.33.33.34:8002;
server 33.33.33.34:8003;
}
server {
listen 8888;
server_name localhost 33.33.33.33;
access_log /home/frontend/website.access.log;
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://frontends;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment