Running bee agents
How to connect and configure a bee agent
Last updated
How to connect and configure a bee agent
Last updated
Before connecting a bee agent to a hive server, it must be registered following the steps shown in the section that explains .
Without the registration step the bee is not allowed to connect because it cannot authenticate with the server.
Each type of bee agent has a different executable. In this section, a Docker client bee is being used, so the executable is bee-docker. For bees of type http it would be bee-http. See the bee types section to explore how to configure and start each bee type.
The bee has to provide three parameters in order to connect to the server: Hive location, bee ID and the seed key. These parameters can be passed via command line parameters (flags) when running the bee process, as environment variables, or using a configuration file.
When a bee is connected it is shown in the hive output logs. It logs the bee ID with its public key and which is the hub where the bee is connected.
The hive logs the disconnection event when the bee is disconnected
An important part of any bee to hive connection is what to do when a connection drops off and the agent needs to reconnect. BeeOS has built-in reconnection support that can be configured to behave in ways that suit the application.
When a bee agent is starting and connecting for the first time, if it is not able to connect to hive it will try to reconnect until it can do it. Once connected to the hive, if the connection closes for whatever reason the bee will attempt to reconnect to the hive indefinitely until the connection is re-stablished again.
Once the bee is connected, it must be given instructions on how to proceed. This is done through configuration. A JSON file with the necessary settings must be created and uploaded to the hive server. Next, the recently uploaded configuration must be synchronized with the bee so that it can receive the settings to be carried out.
For this example we have used the Docker client bee (bee-docker exec). All bees have the same JSON schema, except for some section that is specific to each type of bee. Below is an example of JSON for Docker's bee client. The contents of the settings section is specific to this type of bee (image, volumes, ports, etc)
The goal of a Docker client bee (bee-docker) is to run containers on the host where the bee is installed (in the same way as a command line Docker client). The image to pull, registry, volumes, port mappings and other advanced options are available to be set at settings section.
In that case we want to run a "nginx:1.18-alpline" image from the public Docker registry mapping the container port 80 to the host 8080.
A bee1.json file is created with the contents shown above. Then the following beectl command is used to send the configuration to the hive server.
The --bee (-b) flag specifies the bee ID and the --file (-f) is the path of the JSON file containing the configuration.
When a new configuration is uploaded the config version number is increased
The current configuration can be seen or downloaded using the get config command. It prints at the console the requested configuration
If the --file (-f) flag is used it is downloaded to the specified file instead of being printed at the console.
The configured bees has its configuration stored in the hive internal database. To send the configuration to the bees, a synchronization should be done. The synchronization is an important concept because sometimes your bee configurations need to be synchronized at the same time, not when you are uploading the config file.
The following command performs a synchronization for a given bee
Now the synchronization is performed. The corresponding bee will receive its configuration as soon as it is connected if is not connected at the moment of executing the sync command. We can see the synchronization state using the get command
There is the possibility to synchronize while uploading a configuration file using the --sync flag. It avoids the need to perform two steps to upload and sync a configuration file.