Integrating OS Package Management and the Erlang VM.

155
Integrating OS Package Management and the Erlang VM

Transcript of Integrating OS Package Management and the Erlang VM.

Page 1: Integrating OS Package Management and the Erlang VM.

Integrating OS Package Management and the Erlang VM

Page 2: Integrating OS Package Management and the Erlang VM.

An Erlang Startup

• Write awesome Erlang code.• ???• Profit.

Page 3: Integrating OS Package Management and the Erlang VM.

An Erlang Startup

• Write awesome Erlang code.• ???• Deploy to EC2.• ???• Profit.

Page 4: Integrating OS Package Management and the Erlang VM.

An Erlang Startup

• Write awesome Erlang code.• ???• Deploy to EC2.• ???• Profit.

Page 5: Integrating OS Package Management and the Erlang VM.

How do I launch my software

Page 6: Integrating OS Package Management and the Erlang VM.

How do I launch my software

… to EC2

Page 7: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 8: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 9: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 10: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 11: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 12: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 13: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 14: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 15: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 16: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 17: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 18: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 19: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 20: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 21: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 22: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 23: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 24: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 25: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 26: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 27: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 28: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 29: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 30: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

Page 31: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

cool.erl

Page 32: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

cool.erl

Page 33: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

cool.erl

Page 34: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

cool.erl

Page 35: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

cool.erl

Page 36: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

cool.erl

mega.erl

Page 37: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

cool.erl

mega.erl

sweet.erl

src

Page 38: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structuresrc

Page 39: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

src

Page 40: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

src

Page 41: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

src

Page 42: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

src

ebin

foo-0.1.0

Page 43: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

src

ebin

foo.app

foo-0.1.0

foo.appup

Page 44: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

src

ebin

foo.app

foo-0.1.0

foo.appup

{application, foo, [{description, ”My App"}, {vsn, “0.1.0"}, {modules, [cool,mega,sweet]}, {registered, [foobar]}, {applications, [kernel,stdlib,sasl,bar]}, {mod, {cool,[]}} ]}.

Page 45: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

src

ebin

foo.app

foo-0.1.0

foo.appup

{application, foo, [{description, ”My App"}, {vsn, “0.1.0"}, {modules, [cool,mega,sweet]}, {registered, [foobar]}, {applications, [kernel,stdlib,sasl,bar]}, {mod, {cool,[]}} ]}.

Which modules?

Page 46: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

src

ebin

foo.app

foo-0.1.0

foo.appup

{application, foo, [{description, ”My App"}, {vsn, “0.1.0"}, {modules, [cool,mega,sweet]}, {registered, [foobar]}, {applications, [kernel,stdlib,sasl,bar]}, {mod, {cool,[]}} ]}.

Which modules?

Prerequisites

Page 47: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

src

ebin

foo.app

foo-0.1.0

foo.appup

{“0.1.0", [{“0.0.0", [{load_module, mega, [ch3]}]}], [{“0.0.0", [{load_module, mega, [ch3]}]}]}.

Page 48: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

src

ebin

foo.app

foo-0.1.0

foo.appup

{“0.1.0", [{“0.0.0", [{load_module, mega, [ch3]}]}], [{“0.0.0", [{load_module, mega, [ch3]}]}]}.

DSL Upgrade Commands

Page 49: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

src

ebin

foo.app

foo-0.1.0

foo.appup

Page 50: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structurefoo-0.1.0

Page 51: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

foo-0.1.0

Page 52: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

foo-0.1.0

Page 53: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

foo-0.1.0

Page 54: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

foo-0.1.0

bar-0.2.1

lib

Page 55: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

foo-0.1.0

bar-0.2.1

baz-1.3.4

lib

Page 56: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structurelib

Page 57: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

lib

Page 58: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

lib

Page 59: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

lib

Page 60: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

lib

releases

Page 61: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

lib

releases

0.4.5

zzz.rel

Page 62: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

lib

releases

0.4.5

zzz.rel

{release,{”zzz","0.4.5"}, {erts,"5.5.5"}, [{kernel,"2.11.4"}, {stdlib,"1.14.4"}, {foo,"0.1.0"}, {bar,”0.2.1"}]}.

Page 63: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

lib

releases

0.4.5

zzz.rel zzz.script

What applications to startThe order to start them

Page 64: Integrating OS Package Management and the Erlang VM.

Erlang/OTP software structure

• A module is a unit of code.• An application is a collection of modules.– Defines how to start and stop.– Defines how to upgrade/downgrade.

• A release is a collection of applications.– Defines what constitutes the system.– Defines how to start the system.– Also can define upgrade/downgrade.

Page 65: Integrating OS Package Management and the Erlang VM.

Erlang/OTP Launch Strategy

• Collect versioned applications together.– Defines the new state of the system.– Complete, not incremental.

• Create the release using OTP tools.• Make the release accessible.– The deployment problem.

• Upgrade using release handler tools.

Page 66: Integrating OS Package Management and the Erlang VM.

Large Companies

• Infrequent complete releases.

• Heavy integrative QA.

Page 67: Integrating OS Package Management and the Erlang VM.

Large Companies

• Infrequent complete releases

• Heavy integrative QA

Page 68: Integrating OS Package Management and the Erlang VM.

Large Companies

• Infrequent complete releases

• Heavy integrative QA

Page 69: Integrating OS Package Management and the Erlang VM.

Large Companies

• Infrequent complete releases

• Heavy integrative QA

Page 70: Integrating OS Package Management and the Erlang VM.

Startup

• “Agile” launch processes

Page 71: Integrating OS Package Management and the Erlang VM.

Large Companies

• Infrequent complete releases

• Heavy integrative QA

Page 72: Integrating OS Package Management and the Erlang VM.

Use the OS Package Manager

• Uniformity.• Dependency Specification.– Between Erlang applications.– Between Erlang and non-Erlang components.

• Installation hooks.– Hot code management.

• Provisioning.• Deployment.

Page 73: Integrating OS Package Management and the Erlang VM.

1 Xen Instance = 1 Erlang VM

Page 74: Integrating OS Package Management and the Erlang VM.

1 Xen Instance = 1 Erlang VM

Page 75: Integrating OS Package Management and the Erlang VM.

1 Xen Instance = 1 Erlang VM

Page 76: Integrating OS Package Management and the Erlang VM.

1 Xen Instance = 1 Erlang VM

Page 77: Integrating OS Package Management and the Erlang VM.

1 Xen Instance = 1 Erlang VM

Page 78: Integrating OS Package Management and the Erlang VM.

1 Xen Instance = 1 Erlang VM

Page 79: Integrating OS Package Management and the Erlang VM.

1 Xen Instance = 1 Erlang VM

Page 80: Integrating OS Package Management and the Erlang VM.

1 Xen Instance = 1 Erlang VM

Page 81: Integrating OS Package Management and the Erlang VM.

1 Xen Instance = 1 Erlang VM

Page 82: Integrating OS Package Management and the Erlang VM.

1 Xen Instance = 1 Erlang VM

Page 83: Integrating OS Package Management and the Erlang VM.

1 Xen Instance = 1 Erlang VM

Page 84: Integrating OS Package Management and the Erlang VM.

1 Xen Instance = 1 Erlang VM

Page 85: Integrating OS Package Management and the Erlang VM.

1 Xen Instance = 1 Erlang VM

Page 86: Integrating OS Package Management and the Erlang VM.

1 Xen Instance = 1 Erlang VM

Page 87: Integrating OS Package Management and the Erlang VM.

1 Xen Instance = 1 Erlang VM

Page 88: Integrating OS Package Management and the Erlang VM.

1 Xen Instance = 1 Erlang VM

Erlang VMEC2 Instance

Package Archive

s3fs

Page 89: Integrating OS Package Management and the Erlang VM.

1 Package = 1 Application

• Small enough to launch frequently.– No need to assemble all application changes.– “Release” = set of packages.

• Large enough to be interesting.– Supervision hierarchy.– Upgrade semantics.

Page 90: Integrating OS Package Management and the Erlang VM.

Our Launch Process

• Create application OS package.– Province of the build system.

• Upload to package archive.– Standard tools available.

• Install the package on server.– Automatically starts, stops, upgrades, downgrades

applications as appropriate.

Page 91: Integrating OS Package Management and the Erlang VM.

Our Launch Process

• Create application OS package.– Province of the build system.

• Upload to package archive.– Standard tools available.

• Install the package on server.– Automatically starts, stops, upgrades, downgrades

applications as appropriate.

Page 92: Integrating OS Package Management and the Erlang VM.

Erlrc: The Vision …pmineiro@ub32srvvmw-199% sudo apt-get install egerlReading package lists... DoneBuilding dependency tree Reading state information... DoneThe following packages will be upgraded: egerl1 upgraded, 0 newly installed, 0 to remove and 34 not upgraded.Need to get 0B/113kB of archives.After unpacking 0B of additional disk space will be used.WARNING: The following packages cannot be authenticated! egerlInstall these packages without verification [y/N]? y(Reading database ... 48221 files and directories currently installed.)Preparing to replace egerl 4.0.1 (using .../archives/egerl_4.1.0_all.deb) ...Unpacking replacement egerl ...erlrc-upgrade: Upgrading 'egerl': (cb8eec1a1b85ec017517d3e51c5aee7b) upgradedSetting up egerl (4.1.0) ...erlrc-start: Starting 'egerl': (cb8eec1a1b85ec017517d3e51c5aee7b) already_running

Page 93: Integrating OS Package Management and the Erlang VM.

Erlrc: The Vision …pmineiro@ub32srvvmw-199% sudo apt-get install egerlReading package lists... DoneBuilding dependency tree Reading state information... DoneThe following packages will be upgraded: egerl1 upgraded, 0 newly installed, 0 to remove and 34 not upgraded.Need to get 0B/113kB of archives.After unpacking 0B of additional disk space will be used.WARNING: The following packages cannot be authenticated! egerlInstall these packages without verification [y/N]? y(Reading database ... 48221 files and directories currently installed.)Preparing to replace egerl 4.0.1 (using .../archives/egerl_4.1.0_all.deb) ...Unpacking replacement egerl ...erlrc-upgrade: Upgrading 'egerl': (cb8eec1a1b85ec017517d3e51c5aee7b) upgradedSetting up egerl (4.1.0) ...erlrc-start: Starting 'egerl': (cb8eec1a1b85ec017517d3e51c5aee7b) already_running

Page 94: Integrating OS Package Management and the Erlang VM.

Problems to solve

• Static: booting the VM properly• Dynamic: hot install/upgrade/remove

Page 95: Integrating OS Package Management and the Erlang VM.

Erlang VM Boot

lib

releases

0.4.5

zzz.rel zzz.script

What applications to startThe order to start them

Page 96: Integrating OS Package Management and the Erlang VM.

Config File vs. Config Directory

apache.conf

Page 97: Integrating OS Package Management and the Erlang VM.

Config File vs. Config Directory

apache.conf

Page 98: Integrating OS Package Management and the Erlang VM.

Config File vs. Config Directory

apache.conf

Page 99: Integrating OS Package Management and the Erlang VM.

Config File vs. Config Directory

apache.conf

Page 100: Integrating OS Package Management and the Erlang VM.

Config File vs. Config Directory

apache.conf

Page 101: Integrating OS Package Management and the Erlang VM.

Config File vs. Config Directory

apache.conf

Page 102: Integrating OS Package Management and the Erlang VM.

Config File vs. Config Directory

apache.conf apache.conf.d

Page 103: Integrating OS Package Management and the Erlang VM.

Config File vs. Config Directory

apache.conf apache.conf.d

Page 104: Integrating OS Package Management and the Erlang VM.

Config File vs. Config Directory

apache.conf apache.conf.d

Page 105: Integrating OS Package Management and the Erlang VM.

Config File vs. Config Directory

apache.conf apache.conf.d

Page 106: Integrating OS Package Management and the Erlang VM.

Config File vs. Config Directory

zzz.script /etc/erlrc.d/applications

Page 107: Integrating OS Package Management and the Erlang VM.

Actual Applications Directory% ls /etc/erlrc.d/applicationsappinspect egerl fragmentron genherd nodefinder zfilecombonodefinder erlrc fuserl loggins schemafinderec2nodefinder erlsom gencron n54etsbugfix virtuerl

Page 108: Integrating OS Package Management and the Erlang VM.

Actual Applications Directory

Filename = Application NameFiles are Empty (for Now)

% ls /etc/erlrc.d/applicationsappinspect egerl fragmentron genherd nodefinder zfilecombonodefinder erlrc fuserl loggins schemafinderec2nodefinder erlsom gencron n54etsbugfix virtuerl

Page 109: Integrating OS Package Management and the Erlang VM.

Actual Applications Directory

Filename = Application NameFiles are Empty (for Now)Start Up Order

% ls /etc/erlrc.d/applicationsappinspect egerl fragmentron genherd nodefinder zfilecombonodefinder erlrc fuserl loggins schemafinderec2nodefinder erlsom gencron n54etsbugfix virtuerl

Page 110: Integrating OS Package Management and the Erlang VM.

Actual Applications Directory% ls /etc/erlrc.d/applicationsappinspect egerl fragmentron genherd nodefinder zfilecombonodefinder erlrc fuserl loggins schemafinderec2nodefinder erlsom gencron n54etsbugfix virtuerl

Filename = Application NameFiles are Empty (for Now)Start Up Order?

Page 111: Integrating OS Package Management and the Erlang VM.

Determining the Startup Order

src

ebin

foo.app

foo-0.1.0

foo.appup

Page 112: Integrating OS Package Management and the Erlang VM.

Determining the Startup Order

src

ebin

foo.app

foo-0.1.0

foo.appup

{application, foo, [{description, ”My App"}, {vsn, “0.1.0"}, {modules, [cool,mega,sweet]}, {registered, [foobar]}, {applications, [kernel,stdlib,sasl,bar]}, {mod, {cool,[]}} ]}.

Page 113: Integrating OS Package Management and the Erlang VM.

Determining the Startup Order

src

ebin

foo.app

foo-0.1.0

foo.appup

{application, foo, [{description, ”My App"}, {vsn, “0.1.0"}, {modules, [cool,mega,sweet]}, {registered, [foobar]}, {applications, [kernel,stdlib,sasl,bar]}, {mod, {cool,[]}} ]}.

Prerequisites define a partial orderChoose a consistent start order

Page 114: Integrating OS Package Management and the Erlang VM.

Regular Application

foo

Page 115: Integrating OS Package Management and the Erlang VM.

Regular Application

foo

Page 116: Integrating OS Package Management and the Erlang VM.

Regular Application

foo

applicationcontroller

Page 117: Integrating OS Package Management and the Erlang VM.

Included Application

foo

Page 118: Integrating OS Package Management and the Erlang VM.

Included Application

foo

Page 119: Integrating OS Package Management and the Erlang VM.

Included Application

foo

Page 120: Integrating OS Package Management and the Erlang VM.

Included Application

foo

bar

Page 121: Integrating OS Package Management and the Erlang VM.

Included Application

foo

bar Starting bar starts foo.

applicationcontroller

Page 122: Integrating OS Package Management and the Erlang VM.

Included Application Logic

• If bar includes foo, and• both bar and foo are to be started, then• only start bar.• If baz depends upon foo, and• bar is to be started, then• baz depends upon bar.

Page 123: Integrating OS Package Management and the Erlang VM.

Boot Procedure

• Packages contain additional empty file. /etc/erlrc/applications/<appname>

• .app prerequisites are correct.• Start using any boot script, e.g., start_sasl. • Pass control to erlrc_boot:boot/0.

erl –boot start_sasl –s erlrc_boot boot

Page 124: Integrating OS Package Management and the Erlang VM.

Problems to solve

Static: booting the VM properly• Dynamic: hot install/upgrade/remove

Page 125: Integrating OS Package Management and the Erlang VM.

Erlrc upgrade components

• erlrcdynamic module methods.– erlrcdynamic:downgrade/3

• shell scripts– erlrc-downgrade

• rendezvous at /etc/erlrc.d/nodes % ls /etc/erlrc.d/nodes cb8eec1a1b85ec017517d3e51c5aee7b

Page 126: Integrating OS Package Management and the Erlang VM.

Package hook correspondenceShell script erlrcdynamic

methodDescription When (debian)

erlrc-start start/2 Idempotent start postinst configure ; postinst abort-remove

erlrc-stop stop/2 Idempotent stop prerm remove

erlrc-upgrade upgrade/3 Upgrade application postinst upgrade

erlrc-downgrade downgrade/3 Downgrade application

postinst abort_upgrade

Page 127: Integrating OS Package Management and the Erlang VM.

Example: prerm#! /bin/shpackage_name="example"package_version="0.0.0”operation="$1”case "$operation" inremove) which erlrc-stop >/dev/null 2>/dev/null test $? -ne 0 || erlrc-stop "${package_name}" "${package_version}" || exit 1;;*);;esacexit 0

Page 128: Integrating OS Package Management and the Erlang VM.

Example: prerm#! /bin/shpackage_name="example"package_version="0.0.0”operation="$1”case "$operation" inremove) which erlrc-stop >/dev/null 2>/dev/null test $? -ne 0 || erlrc-stop "${package_name}" "${package_version}" || exit 1;;*);;esacexit 0

Page 129: Integrating OS Package Management and the Erlang VM.

Best practices for build system

• Automatically generate erlrc_boot file.– /etc/erlrc.d/applications/<appname>

• Generate both dependencies from single specification.– .app prerequisites– OS package dependencies

• Automatically generate package hooks.

Page 130: Integrating OS Package Management and the Erlang VM.

Upgrade Logic

• If there is an appup file in the newer application version, use it; otherwise, generate one automatically.

• Ensure all modules listed in the current application specification are loaded.

• Find any added and removed included applications by examining the current and target version OTP app files.

• Stop any added included applications.• Execute release_handler:eval_appup_script/4.• Start any removed included applications, if they are

listed in $ERLRC_ROOT/applications.

Page 131: Integrating OS Package Management and the Erlang VM.

Upgrade Logic

• If there is an appup file in the newer application version, use it; otherwise, generate one automatically.

• Ensure all modules listed in the current application specification are loaded.

• Find any added and removed included applications by examining the current and target version OTP app files.

• Stop any added included applications.• Execute release_handler:eval_appup_script/4.• Start any removed included applications, if they are

listed in /etc/erlrc.d/applications.

Page 132: Integrating OS Package Management and the Erlang VM.

Upgrade Logic

• If there is an appup file in the newer application version, use it; otherwise, generate one automatically.

• Ensure all modules listed in the current application specification are loaded.

• Find any added and removed included applications by examining the current and target version OTP app files.

• Stop any added included applications.• Execute release_handler:eval_appup_script/4.• Start any removed included applications, if they are

listed in /etc/erlrc.d/applications.

Page 133: Integrating OS Package Management and the Erlang VM.

Upgrade Logic

• If there is an appup file in the newer application version, use it; otherwise, generate one automatically.

• Ensure all modules listed in the current application specification are loaded.

• Find any added and removed included applications by examining the current and target version OTP app files.

• Stop any added included applications.• Execute release_handler:eval_appup_script/4.• Start any removed included applications, if they are

listed in /etc/erlrc.d/applications.

Page 134: Integrating OS Package Management and the Erlang VM.

Included Application

foo

bar Starting bar starts foo.

applicationcontroller

Page 135: Integrating OS Package Management and the Erlang VM.

Included Application

bar Starting bar starts foo.does not start

applicationcontroller

Page 136: Integrating OS Package Management and the Erlang VM.

Included Application Invariants

1 If an application is listed in the /etc/erlrc.d/applications directory, then it should be running.

2 When an application is running, all of its included applications are considered running.

3 An application cannot both run itself and be included.

Page 137: Integrating OS Package Management and the Erlang VM.

Included Application Logic

• If X is included by Y, then before starting Y, X is stopped.

• If X is included by Y, then after stopping Y, X is started.• If Y is upgraded or downgraded such that X becomes

included when it was not previously, before Y is upgraded or downgraded, X is stopped.

• If Y is upgraded or downgraded such that X becomes no longer included when it was previously, after Y is upgraded or downgraded, X is started.

Page 138: Integrating OS Package Management and the Erlang VM.

Included Application Logic

• If X is included by Y, then before starting Y, X is stopped.

• If X is included by Y, then after stopping Y, X is started.• If Y is upgraded or downgraded such that X becomes

included when it was not previously, before Y is upgraded or downgraded, X is stopped.

• If Y is upgraded or downgraded such that X becomes no longer included when it was previously, after Y is upgraded or downgraded, X is started.

Page 139: Integrating OS Package Management and the Erlang VM.

.appup files

• Manual generation: tedious, error-prone.• Typically can be automatically generated.• Strategy: automation with override.– Use .appup file if provided (rare).– Otherwise automatically generate (common).

• Key tool: beam_lib:chunks/2.

Page 140: Integrating OS Package Management and the Erlang VM.

Automatic .appup generation

src

ebin

foo.app

foo-0.1.0

cool.beam

Page 141: Integrating OS Package Management and the Erlang VM.

Automatic .appup generation

src

ebin

foo.app

foo-0.1.0

cool.beam

src

ebin

foo.app

foo-0.1.1

cool.beam

postinst upgrade

Page 142: Integrating OS Package Management and the Erlang VM.

Automatic .appup generation

src

ebin

foo.app

foo-0.1.0

cool.beam

src

ebin

foo.app

foo-0.1.1

cool.beam

postinst upgrade

Compare.appfiles

Page 143: Integrating OS Package Management and the Erlang VM.

Automatic .appup generation

src

ebin

foo.app

foo-0.1.0

cool.beam

src

ebin

foo.app

foo-0.1.1

cool.beam

postinst update

Compare.beam

files

Page 144: Integrating OS Package Management and the Erlang VM.

Example: load_module

{application, foo, [{description, ”My App"}, {vsn, “0.1.0"}, {modules, [cool,mega,sweet]}, {registered, [foobar]}, {applications, [kernel,stdlib,sasl,bar]}, {mod, {cool,[]}} ]}.

{application, foo, [{description, ”My App"}, {vsn, “0.1.1"}, {modules, [cool,mega,sweet,ultra]}, {registered, [foobar]}, {applications, [kernel,stdlib,sasl,bar]}, {mod, {cool,[]}} ]}.

Page 145: Integrating OS Package Management and the Erlang VM.

Example: load_module

{application, foo, [{description, ”My App"}, {vsn, “0.1.0"}, {modules, [cool,mega,sweet]}, {registered, [foobar]}, {applications, [kernel,stdlib,sasl,bar]}, {mod, {cool,[]}} ]}.

{application, foo, [{description, ”My App"}, {vsn, “0.1.1"}, {modules, [cool,mega,sweet,ultra]}, {registered, [foobar]}, {applications, [kernel,stdlib,sasl,bar]}, {mod, {cool,[]}} ]}.

ultra is a new moduleemit load_module directive

Page 146: Integrating OS Package Management and the Erlang VM.

Example: update

• update directive is used to upgrade the code and the state of an active process, e.g., gen_server.

• All of the gen_XXX family export code_change/3 in their behaviour.

Page 147: Integrating OS Package Management and the Erlang VM.

Example: update

ebin

foo-0.1.0

cool.beam

ebin

foo-0.1.1

cool.beam

postinst update

Exports code_change/3?

If yes, issue update directive.

Page 148: Integrating OS Package Management and the Erlang VM.

.appup file generation1 Compute added and removed modules by looking at the old and new

OTP app files.2 Emit a load_module directive for every added module.3 For each module which is in both versions of the application:

1 If the module implements the supervisor behaviour1 Emit an "upgrade for supervisors" instruction.2 If the module exports a sup_upgrade_notify/2 function, emit an instruction to call it.

2 Else if the module exports a code_change/3 function, emit a update directive for that module.

3 Otherwise, emit a load_module directive for that module.

4 If there is a start module for the application:1 Determine if the new beam for the start module exports a version_change/2

function. If so, emit a directive to call it.

5 Emit a delete_module directive for every removed module.

Page 149: Integrating OS Package Management and the Erlang VM.

.appup file generation1 Compute added and removed modules by looking at the old and new

OTP app files.2 Emit a load_module directive for every added module.3 For each module which is in both versions of the application:

1 If the module implements the supervisor behaviour1 Emit an "upgrade for supervisors" instruction.2 If the module exports a sup_upgrade_notify/2 function, emit an instruction to call it.

2 Else if the module exports a code_change/3 function, emit a update directive for that module.

3 Otherwise, emit a load_module directive for that module.

4 If there is a start module for the application:1 Determine if the new beam for the start module exports a version_change/2

function. If so, emit a directive to call it.

5 Emit a delete_module directive for every removed module.

Page 150: Integrating OS Package Management and the Erlang VM.

Custom .appup hooks

• <supervisor>:sup_upgrade_notify/2– Used to start or stop newly added or removed

children.• <application>:version_change/2– Used to notify the application start module that

the application version has changed.

Page 151: Integrating OS Package Management and the Erlang VM.

Distribution and provisioning

• ec2-do– escript for rolling window execution across an ec2

group.% ec2-do –g production –m 3 apt-get install egerl

• apt-snapshot– provisioning tool based upon .deb packages% apt-snapshot create <snapshot>% apt-snapshot restore host:<snapshot>

Page 152: Integrating OS Package Management and the Erlang VM.

Practical Usage

• 5 dudes for 2 years.• Circa 30 machines per cluster.• Circa 3 clusters.

Page 153: Integrating OS Package Management and the Erlang VM.

An Erlang Startup

• Write awesome Erlang code.• ???• Deploy to EC2.• ???• Profit.

Page 154: Integrating OS Package Management and the Erlang VM.

An Erlang Startup

• Write awesome Erlang code.• Use erlrc and make OS packages.• Deploy to EC2.• ???• Profit.

Page 155: Integrating OS Package Management and the Erlang VM.

More Information

http://dukesoferl.blogspot.com/

http://code.google.com/p/erlrc/

http://n54.com/