# Brewblox services

TIP

This page explains how and why the service configuration works.

If you prefer to get started immediately with setting up a second Spark: you can skip forward to Adding a Spark service.

Brewblox is designed to let you control multiple devices with a single application.

To make this both reliable and easy, devices are connected to a central hub (the server).

Server linked to devices

On the server, we need some software to talk to individual devices. To make it easy to add new devices, we split the software into services.

Some services are used for shared functionality: The history service collects data from device services, and stores it for later use in graphs. Others are used to control individual devices.

Services overview

# Service configuration

Services are configured using the docker-compose.yml file. YAML (opens new window) is a markup language that uses indentation to show nested values. You can follow this guide to install a graphical text editor for your configuration files.

A shortened configuration file:

version: "3"

services:
  history:
    image: brewblox/brewblox-history:edge

  spark-one:
    image: brewblox/brewblox-devcon-spark:edge

  spark-two:
    image: brewblox/brewblox-devcon-spark:edge

There are three services here:

  • history
  • spark-one
  • spark-two

All of them have a unique name, but spark-one and spark-two share the same type. That's ok: as long as the name is unique, services can have the same settings.

GOOD:

services:
  service-one:
    image: brewblox-image-one

  service-two:
    image: brewblox-image-one

BAD:

services:
  service-one:
    image: brewblox-image-one

  service-one:
    image: brewblox-image-two

# Adding devices

If we want to add a new device, we need a new service to manage it. Once again: the name must be unique, but the type can be the same.

Each type of service may have a slightly different configuration. We'll take a detailed look at a Spark service here, but other services will have configuration that is very much like it.

# Docker-compose service syntax

When you install Brewblox, it generates a docker-compose.yml file for you. This includes the default spark-one service.

  spark-one:
    image: brewblox/brewblox-devcon-spark:${BREWBLOX_RELEASE}
    privileged: true
    restart: unless-stopped
    command: '--name=spark-one'

This configuration is more advanced than what we've seen so far. To make sense of it, we'll look at the individual settings.


spark-one:
  image: brewblox/brewblox-devcon-spark:${BREWBLOX_RELEASE}
  ...

This is like the short service configurations we saw earlier. The two most important settings in a service's configuration are its name (spark-one), and its type (everything after image:).

The basic principles still apply. When you want to control multiple Spark devices, you'll need one service per device. Every service will have the same image, but a different name.


  ...
  privileged: true
  restart: unless-stopped

These settings are the same for every Spark service (and many other services).

privileged services can use USB connections.

restart: unless-stopped does what it says: when your service crashes, it will automatically restart.


  ...
  command: '--name=spark-one'

The command setting contains arguments for the software running inside the service.

The --name argument must (again) be the same as the service name.

For a Spark service, the command is where you add the settings for how it connects to a Spark controller

TIP

The service name is mentioned two times in the YAML for a Spark service. The values must match.

  • at the top (spark-one:)
  • in the command (--name=spark-one)