Job
A Job is a deployable task that includes configuration and execution logic.
This guide demonstrates creating and deploying a job to manage node_exporter across multiple workers.
Create a Job
-
Create the
jobs
folder inworkspace
and thenode_exporter
folder for the job:$ mkdir -p workspace/jobs/node_exporter
-
Verify the folder structure:
. └── workspace ├── workers.json ├── jobs │ └── node_exporter │ ├── docker-compose.yaml │ ├── manifest.json │ └── Makefile
Add Job Files
-
manifest.json
Define the roles the job applies to:{ "labels": [ "worker" ] }
-
Makefile
Define job commands to manage the task:start: docker-compose up -d --remove-orphans stop: docker-compose down restart: stop start
-
docker-compose.yaml
Configuration for runningnode_exporter
:services: node_exporter: image: quay.io/prometheus/node-exporter:latest container_name: node_exporter command: - '--path.rootfs=/host' network_mode: host pid: host restart: unless-stopped volumes: - '/:/host:ro,rslave'
Build
Compile changes
$ maand build
View Jobs
-
List all jobs:
$ maand cat jobs
Example output:
job_id name disabled deployment_seq labels ------------------------------------ ------------- -------- -------------- ----- a255d9cb-7286-59f1-8775-8a0544503891 node_exporter 0 0 agent
-
Check job's allocations:
$ maand cat allocations
Example output:
worker_ip job disabled removed ------------- ------------- -------- ------- 10.27.221.181 node_exporter 0 0 10.27.221.144 node_exporter 0 0 10.27.221.170 node_exporter 0 0
Deploy
Deploy the job to the workers:
$ maand deploy
Verify
-
SSH into an worker and confirm the job files are deployed:
$ ssh -i secrets/worker.key worker@10.27.221.181 'tree /opt/worker'
-
Example output:
/opt/worker └── db3c0da7-6709-4d8c-94a0-5f66b0e32249 ├── jobs │ └── node_exporter │ ├── docker-compose.yml │ ├── Makefile │ └── manifest.json
Key Notes
- Labels: Ensure the job's
manifest.json
roles match the workers' labels inworkers.json
. - Update After Changes: Always run
maand build
andmaand deploy
after modifying job files or configurations. - File Locations: Deployed jobs reside under
/opt/worker
on each worker.