16
Fabric - a server management tool from Instagram Jay <[email protected]> 2014.03.28 Shanghai, China

Fabric - a server management tool from Instagram

  • Upload
    jay-ren

  • View
    755

  • Download
    0

Embed Size (px)

DESCRIPTION

Fabric - a server management tool from Instagram. It's written in Python

Citation preview

Page 1: Fabric - a server management tool from Instagram

Fabric - a server management tool from Instagram

Jay <[email protected]> 2014.03.28 Shanghai, China

Page 2: Fabric - a server management tool from Instagram

Agenda

What Powers Instagram?

Fabric Introduction

Fabric Demo

Q&A

Page 3: Fabric - a server management tool from Instagram

What Powers Instagram ?

Instagram was acquired by Facebook in April 2012 for approximately US$1 billion in cash and stock.

So, what powers Instagram?

Page 4: Fabric - a server management tool from Instagram

What Powers Instagram ?

OS/Hosting: Ubuntu on Amazon EC2

Load Balance: Amazon’s Elastic Load Balancer

Application Server: Django + Gunicorn

Data Storage: PostgreSQL + Redis + Memcached + Solr

Task Queue & Push Notifications: Gearman + Pyapns

Monitoring: Python-Munin + Pingdom + Sentry

From: http://instagram-engineering.tumblr.com/post/13649370142/what-powers-instagram-hundreds-of-instances-dozens-of

Page 5: Fabric - a server management tool from Instagram

Fabric Introduction (1) - Overview

Fabric is a Python (2.5-2.7) library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks.

!

from: http://docs.fabfile.org/en/1.8/#about

Page 6: Fabric - a server management tool from Instagram

Fabric Introduction (2) - Features

execute local or remote shell commands

parallel execution

upload/download files

prompt the running user for input

abort execution

Page 7: Fabric - a server management tool from Instagram

Fabric Introduction (3) - Environment

Environment as configuration (fabric.state.env) env.host env.hosts (a list of hosts) env.port env.user env.password env.passwords (a dict of host/password pairs) env.warn_only env.parallel env.roledefs (a dict defining role name to host list mappings)

The settings context manager (temporarily modify env vars so that a given settings change only applies to a block of code)

Page 8: Fabric - a server management tool from Instagram

Fabric Introduction (3) - Execution model

Execution strategy

A list of tasks is created.

For each task, a task-specific host list is generated from various sources.

The task list is walked through in order, and each task is run once per host in its host list.

Tasks with no hosts in their host list are considered local-only, and will always run once and only once.

Page 9: Fabric - a server management tool from Instagram

Fabric Introduction (4) - Defining tasks

New-style (Task based; Exclusive)

The @task decorator

Task subclasses

Classic

Fabric will consider any callable object found in your fabfile, except the following:

Callables whose name starts with an underscore (_).

Callables defined within Fabric itself.

Page 10: Fabric - a server management tool from Instagram

Fabric Introduction (5) - Parallel execution

Serial execution (by default)

Concurrent execution

command-line flag -P or the env variable env.parallel

Bubble size: the pool_size keyword argument to @parallel, or globally via -z.

Page 11: Fabric - a server management tool from Instagram

Fabric Introduction (6) -Context Managers

Context managers for use with the with statement.

fabric.context_managers.cd(), lcd()

hide(), show(), quiet()

settings()

shell_env()

prefix()

path()

warn_only()

Page 12: Fabric - a server management tool from Instagram

Fabric Introduction (7) - Managing output

Standard output levels

status, aborts, warnings, running, stdout, stderr, user

Debug output

debug

Output level aliases

output, everything, commands

Hiding and/or showing output levels

Direct modification of fabric.state.output: fabric.state.output

Context managers: hide()/show()

Command-line arguments: --hide and/or --show arguments

Page 13: Fabric - a server management tool from Instagram

Fabric Introduction (8) - APIs

Core API

Color output functions

Context Managers

Decorators

Documentation helpers

Network

Operations

Tasks

Utils

Contrib API

Console Output Utilities

Django Integration

File and Directory Management

Project Tools

Page 14: Fabric - a server management tool from Instagram

Fabric Demo

Page 15: Fabric - a server management tool from Instagram

Q&A

Page 16: Fabric - a server management tool from Instagram

THE END