Atomia Agents

Atomia Cron Job Agent

17 views 0

This manual covers the installation and configuration of the Atomia Cron Agent to enable your customers to schedule regular tasks.

Overview

The Cron agent allows customers to schedule regular tasks. The agent manages Cron job entries and will call for each entry a specified URL after configured period passes (or call it only once).

Before you begin

The Atomia Cron Agent is part of the Atomia agents package. You should start by reading the general package overview and instructions here.

Pre-installation actions

The preconditions are that the machine has a MySQL database installed and the system should have a Linux user named atomia-agent.

Good to know

The Linux username that the agent expects can be changed in the file: /etc/atomia/config after package installation.

Set up MySQL

First, you need to install and do a basic MySQL setup on the server. There a lot of guides for that on the Internet.

Now create Cron DB and a new Atomia MySQL User Account. It’s recommended to create a new MySQL user with all privileges. This can be done by executing the following SQL:

CREATE DATABASE IF NOT EXISTS cron-agent;
CREATE USER 'newdbuser'@'localhost' IDENTIFIED BY 'newdbuserpassword';
GRANT ALL PRIVILEGES ON cron-agent.* TO 'newdbuser'@'localhost';

Replace the placeholder value newdbuser with your intended new user name and placeholder value newdbuserpassword with the user password. These values will be used for a config file later in the Post-installation actions section.

Post-installation actions

Before the Cron agent can be used, we need to create and set up its configuration file. Start by copying the example config file:

sudo cp /etc/atomia/cron-agent.json.example /etc/atomia/cron-agent.json

Edit new copy and change some default properties if needed.

Example file and what each option means:

{
    "auth":{
        "username":"someauthusername",
        "password":"someauthpassword"
    },
    "db":{
        "host": "localhost",
        "port": 3306,
        "user": "newdbuser",
        "password": "newdbuserpassword",
        "name": "cron-agent"
      },
    "mail":{
        "host": "smtp.gmail.com",
        "port": "465",
        "user": "[email protected]",
        "password": "somesmtppassword",
        "ssl": "true",
        "from": "[email protected]"
    },
    "port": 5000,
    "host": "192.168.33.13",
    "min_part":"0",
    "max_part":"1000",
    "interval":5,
    "timezone":"UTC",
    "log_path": "/var/log/atomia/cron-agent.log"
}
Option Meaning
auth Basic access authentication (username and password) for the atomia Cron agent. Without these fields, the client won’t be able to use the Cron agent.
db Access to the MySQL database.
mail Access to the SMTP server.
port Port for the management interface to listen on.
host The IP address of the machine which gonna be used for listening by the Cron agent.
min_part, max_part These values are used to balance the load between the different machines. Every task is assigned a random number between 0 and 1000 (inclusive) and is only executed on the agent in which part range it falls. So for example, if you wanted to balance the load between two machines you could set the part to 0-499 on machine 1 and 500-1000 on machine 2.
interval How often the Cron agent should check if cron tasks are due (in seconds). Note that this does not affect how often the actual tasks are running.
log_path The file where Cron agent should log info and error messages.

Changes in the Automation Server

In order to connect the Cron agent with the Atomia provisioning module, Resource and ProvisioningDescription files should be updated on the server where Atomia Automation Server is installed.

Resource description

Make sure you have the following resource in the resource file (C:\Program Files (x86)\Atomia\AutomationServer\Common\Resources.xml):

<?xml version="1.0"?>
<resourceDescription xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <bindings>
        <moduleList>
            <module name="Atomia.Provisioning.Modules.CronAgentRest.CronAgent" resourceAsignmentPolicy="RoundRobin" />
        <resourceList>
            <resource name="CronAgent01" xdt:Transform="Insert">
                <property name="CronBaseUrl">http://192.168.33.13:5000</property>
                <property name="Username">someauthusername</property>
                <property name="Password">someauthpassword</property>
            </resource>
        </resourceList>
    </bindings>
</resourceDescription>

In the transformation file example above, the CronBaseUrl property should match exactly the host and port properties in the cron-agent.json file (as defined in the example at the beginning of this section). Also, the Username and Password properties should be equivalent to the corresponding fields in the auth section of the same config file.

Provisioning description

Make sure that CronTasks service providing module is set to the REST client. You can do that by placing the following transformation file on the Automation server inside the folder: C:\Program Files (x86)\Atomia\AutomationServer\Common\Resources.xml

<?xml version="1.0" encoding="utf-8"?>
<provisioningDescription xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
	<simpleService providingModule="Atomia.Provisioning.Modules.CronAgentRest.CronAgent" xdt:Locator="XPath(//*[@providingModule='Atomia.Provisioning.Modules.CronAgent.CronAgent'])" xdt:Transform="SetAttributes(providingModule)" />
</provisioningDescription>

To add the Cron service to your package, just add CronTasks simple service in the package serviceList section:

<package name="PremiumPackage">
        <serviceList>
          ...
          <service name="CronTasks" />
        </serviceList>

Running the service

systemctl start atomia-cron-agent

To start the service that is executing customer’s Cron job entries:

systemctl start atomia-cron-daemon

 

Was this helpful?