Skip to content

Instantly share code, notes, and snippets.

@arthuralvim
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arthuralvim/10046137 to your computer and use it in GitHub Desktop.
Save arthuralvim/10046137 to your computer and use it in GitHub Desktop.
Examples of Provyfile.
#!/usr/bin/python
# -*- coding: utf-8 -*-
from provy.core import Role
from provy.more.debian import AptitudeRole
from provy.more.debian import NginxRole
from provy.more.debian import SupervisorRole
from provy.more.debian import TornadoRole
from provy.more.debian import UserRole
class FrontEndServer(Role):
def provision(self):
with self.using(UserRole) as role:
# role.ensure_group('admin')
# self.ensure_line('%admin ALL=(ALL) NOPASSWD: ALL', '/etc/sudoers', sudo=True)
role.ensure_user('frontend', identified_by='pass', is_admin=True)
# if self.is_process_running('nginx', sudo=True):
# self.execute('pkill nginx', stdout=False, sudo=True)
with self.using(NginxRole) as role:
nginx_options = {
'user': 'frontend',
'pid_path': '/home/frontend/nginx.pid',
'error_log_path': '/home/frontend/nginx.error.log',
'access_log_path': '/home/frontend/nginx.access.log'}
role.ensure_conf(conf_template='nginx.conf', options=nginx_options)
role.ensure_site_disabled('default')
website_options = {
'user': 'frontend',
'pid_path': '/home/frontend/nginx.pid',
'error_log_path': '/home/frontend/nginx.error.log',
'access_log_path': '/home/frontend/nginx.access.log',
'servers_0': [('33.33.33.34', '800'),
('33.33.33.34', '800'), ],
'servers_1': [
('33.33.33.34', '8002'),
('33.33.33.34', '8003')],
'servers_2': {'from': 3, 'to': 6, 'server': '33.33.33.34', 'port': '800'},
'servers_3': {'n_server':2,}
}
role.create_site(site='website', template='website', options=website_options)
role.ensure_site_enabled('website')
self.remote_symlink(nginx_options['pid_path'], '/var/run/nginx.pid', sudo=True)
class BackEndServer(Role):
def provision(self):
with self.using(UserRole) as role:
role.ensure_group('admin')
self.ensure_line('%admin ALL=(ALL) NOPASSWD: ALL', '/etc/sudoers', sudo=True)
role.ensure_user('backend', identified_by='pass', is_admin=True)
self.update_file('website.py', '/home/backend/website.py', owner='backend', sudo=True)
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_folder='/home/backend/logs/',
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 = 1
program.log_folder = '/home/backend/logs'
class DatabaseServer(Role):
def provision(self):
pass
class MessageQueueServer(Role):
def provision(self):
pass
servers = {
'stack': {
'frontend': {
'address': '33.33.33.33:2221',
'user': 'root',
'ssh_key': 'key.pem',
'roles': [
FrontEndServer
]
},
'backend': {
'address': '33.33.33.33:2222',
'user': 'root',
'ssh_key': 'key.pem',
'roles': [
BackEndServer
]
},
'postgres': {
'address': '33.33.33.33:2223',
'user': 'root',
'ssh_key': 'key.pem',
'roles': [
DatabaseServer
]
},
'rabbit': {
'address': '33.33.33.33:2224',
'user': 'root',
'ssh_key': 'key.pem',
'roles': [
MessageQueueServer
]
},
}
}
#!/usr/bin/python
# -*- coding: utf-8 -*-
from provy.core import Role
from provy.more.debian import UserRole
from provy.more.debian import AptitudeRole
from provy.more.debian import NginxRole
class SimpleServer(Role):
def provision(self):
with self.using(UserRole) as role:
role.ensure_group('admin')
self.ensure_line('%admin ALL=(ALL) NOPASSWD: ALL', '/etc/sudoers', sudo=True)
role.ensure_user('frontend_user', identified_by='pass', is_admin=True)
with self.using(AptitudeRole) as role:
role.ensure_package_installed('vim')
servers = {
'frontend': {
'address': '33.33.33.33',
'user': 'root',
'roles': [
SimpleServer
]
}
}
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
application = tornado.web.Application([
(r"/", MainHandler),
])
if __name__ == "__main__":
port = int(sys.argv[1])
application.listen(port, '0.0.0.0')
print ">> Website running at http://0.0.0.0:%d" % port
tornado.ioloop.IOLoop.instance().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment