Skip to content
ivey edited this page Dec 10, 2012 · 6 revisions

A component is a piece of your Application that can be managed individually.

Component definitions consist of:

(all of the below may have multiple defined blocks for the various groups services and commands that a component may control)

  • group - how to identify what types of nodes are included in this Component.
group "database_master" do
  chef_attribute "database.master", true
end

group "database_slave" do
  chef_attribute "database.master", false
end
  • service - A declaration of a service that this Component is responsible for.
service "database" do
  action :start do
    node_attribute 'database.start', true
  end

  action :stop do
    node_attribute 'database.start', false
  end
end
  • command - A definition of an action that can be performed on the Component.
command "start" do
  execute do
    on("database_master")
      service("database").run(:start)
    end
  end
end

command "stop" do
  execute do
    on("database_master")
      service("database").run(:stop)
    end
  end
end

If actions do not need to run in order, async blocks can speed up execution:

command "start_all" do
  execute do
    on("database_master")
      service("first").run(:start)
      async do
        service("async_one").run(:start)
        service("async_two").run(:start)
        service("async_three").run(:start)
      end
    end
  end
end

Multiple Components

Most applications are not single component entities. Even a simple web application often consists of a web server, such as nginx, as reverse proxy to an application process, such as Unicorn, connecting to a database, such as PostgreSQL.

Mother Brain allows you to orchestrate these components individually and as a whole.

Creating multiple components is no harder than creating a single component:

component "application" do
  # ...
end

component "web_server" do
  # ...
end

component "database" do
  # ...
end

Commands may be defined on the top level to bundle up functionality for all of the Components for Application-wide commands:

+command "start" do
+  description "Start the whole thing"
+  
+  execute do
+    on("all") do
+      component("database").invoke("start")
+      component("web_server").invoke("start")
+      component("application").invoke("start")
+    end
+  end
+end

component "application" do
  # ...
end

component "web_server" do
  # ...
end

component "database" do
  # ...
end
Clone this wiki locally