process management with foreman - stac.works€¦ · foreman can either run processes directly or...

74
Process management with Foreman

Upload: others

Post on 06-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Process management with Foreman

Page 2: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Josh Nesbitt

Stac wearestac.com

Page 3: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Overview

Page 4: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Foreman is a way to define processes for your application in code

Page 5: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

It does not handle installing or managing dependencies

Page 6: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Foreman can either run processes directly or delegate that

responsibility to other linux tools

Page 7: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

It was originally built by David Dollar at Heroku

Page 8: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Heroku leveraged Foreman to define processes you wished

to run on their platform

Page 9: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

You should use it if…

Page 10: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

You care about making your processes portable and reproducible across

different environments

Page 11: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

You care about making your processes portable and reproducible across

different environments

Page 12: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

You care about making your processes portable and reproducible across

different environments

Page 13: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Infrastructure as code is vital in a world dominated

by cloud services

Page 14: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Getting started

Page 15: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

name: [command]

Page 16: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

one: [command]two: [command]three: [command]

Page 17: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

web: unicorn -c config.rb

Page 18: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

web: unicorn -c config.rbredis: redis-server redis.conf

Page 19: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

web: unicorn -p $PORT —c config.rb

Page 20: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

foreman start

Page 21: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

foreman start [process name]

Page 22: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

foreman start web

Page 23: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

foreman start -c web=2

Page 24: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

foreman start -c web=2,redis=1

Page 25: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Configuration management

Page 26: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

It’s important to separate configuration values

from the codebase

Page 27: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Foreman uses a well known key/value syntax to define

configuration values

Page 28: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

foreman start -e .env

Page 29: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

RAILS_ENV=productionHTTP_USERNAME=bobHTTP_PASSWORD=secr3t

Page 30: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

ENV[‘RAILS_ENV’]

Page 31: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

foreman start -e .env.development

Page 32: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

foreman start -e .env.test

Page 33: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Exporting

Page 34: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

foreman export [args]

Page 35: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

launchd

Page 36: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

systemd

Page 37: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

upstart

Page 38: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

foreman export upstart

Page 39: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

foreman export upstart \ /etc/init \ -a app

Page 40: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

foreman export upstart \ /etc/init \ -a app \ -u deploy

Page 41: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

/etc/init/app.conf/etc/init/app-web-1.conf/etc/init/app-web.conf/etc/init/app-redis-1.conf/etc/init/app-redis.conf

Page 42: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

start app

Page 43: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

stop app

Page 44: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Usage on NHSx

Page 45: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools
Page 46: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

NHSx is a learning platform from the NHS Leadership Academy

delivering leadership development to the public sector

Page 47: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

It is split up into services that run independent from each other

Page 48: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Main application (Rails)

Page 49: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

API (Rails)

Page 50: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Administration (Rails)

Page 51: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Sidekiq

Page 52: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Redis

Page 53: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Elasticsearch

Page 54: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Uses the same Procfile for development, test and production

Page 55: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Configure overrides using command line options (such as concurrency)

Page 56: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

web: bundle exec unicorn \ -p $PORT \ -c ./unicorn.rb

Page 57: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

redis: redis-server redis.conf

Page 58: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

workers: bundle exec sidekiq

Page 59: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

start nhsx

Page 60: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Integrate with AWS

Page 61: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Many options for instrumenting Foreman into your deployment workflow

Page 62: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

OpsWorks

Page 63: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Capistrano

Page 64: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Capistrano

Page 65: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

after ‘deploy:published', ‘foreman:export’

Page 66: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

task :export do on roles(:app) do within current_path do # ...export here end endend

Page 67: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

sudo '/usr/bin/bundle exec foreman export upstart /etc/init -a nhsx -u deploy'

Page 68: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

task :start do on roles(:app) do sudo 'start nhsx' end end

Page 69: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Further reading

Page 70: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

http://goo.gl/BXHdyL

Page 71: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

http://goo.gl/05eaeV

Page 72: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

http://goo.gl/Z1YmN1

Page 73: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Thank you

Page 74: Process management with Foreman - stac.works€¦ · Foreman can either run processes directly or delegate that responsibility to other linux tools

Questions?