Enhance POE project with health check server, sensor tracking, and dynamic MQTT topic structure. Updated configuration for multiple Modbus hosts and added alerting system for sensor failures and recoveries. Improved logging and error handling throughout the application.
This commit is contained in:
109
poe-sensor.nomad
Normal file
109
poe-sensor.nomad
Normal file
@ -0,0 +1,109 @@
|
||||
job "poe-sensor" {
|
||||
region = "global"
|
||||
datacenters = ["hs"]
|
||||
type = "service"
|
||||
namespace = "production"
|
||||
meta {
|
||||
version = "20250617"
|
||||
}
|
||||
|
||||
group "sensor-bridge" {
|
||||
count = 1
|
||||
|
||||
# Network configuration - using host mode for Modbus access
|
||||
network {
|
||||
mode = "host"
|
||||
port "health" {
|
||||
static = 8080
|
||||
}
|
||||
}
|
||||
|
||||
# Restart policy
|
||||
restart {
|
||||
attempts = 3
|
||||
interval = "30m"
|
||||
delay = "15s"
|
||||
mode = "fail"
|
||||
}
|
||||
|
||||
# Update strategy
|
||||
update {
|
||||
max_parallel = 1
|
||||
min_healthy_time = "30s"
|
||||
healthy_deadline = "3m"
|
||||
progress_deadline = "10m"
|
||||
auto_revert = true
|
||||
canary = 0
|
||||
}
|
||||
|
||||
service {
|
||||
name = "${NOMAD_JOB_NAME}"
|
||||
port = "health"
|
||||
tags = [
|
||||
"sensor",
|
||||
"modbus",
|
||||
"mqtt",
|
||||
"iot",
|
||||
"health-check"
|
||||
]
|
||||
|
||||
check {
|
||||
type = "http"
|
||||
path = "/health"
|
||||
interval = "30s"
|
||||
timeout = "10s"
|
||||
check_restart {
|
||||
limit = 3
|
||||
grace = "10s"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task "poe-sensor" {
|
||||
driver = "docker"
|
||||
|
||||
config {
|
||||
image = "registry.dev.meisheng.group/ms_qc_db:20250409"
|
||||
command = "/bin/bash"
|
||||
args = [
|
||||
"-c",
|
||||
"cd local/poe-sensor && apt-get update -qq && apt-get install -y procps && python -m pip install --upgrade pip && python -m pip install -r requirements.txt && python -c 'import pymodbus, paho.mqtt.client; print(\"Dependencies installed successfully\")' && python main.py"
|
||||
]
|
||||
}
|
||||
|
||||
# Git artifact - using SSH similar to qc-scanner
|
||||
artifact {
|
||||
source = "git::ssh://git@gitea.service.mesh:2222/Mei_Sheng_Textiles/POE-sensor.git"
|
||||
destination = "local/poe-sensor"
|
||||
options {
|
||||
ref = "main"
|
||||
sshkey = "LS0tLS1CRUdJTiBPUEVOU1NIIFBSSVZBVEUgS0VZLS0tLS0KYjNCbGJuTnphQzFyWlhrdGRqRUFBQUFBQkc1dmJtVUFBQUFFYm05dVpRQUFBQUFBQUFBQkFBQUFNd0FBQUF0emMyZ3RaVwpReU5UVXhPUUFBQUNEbWF6M0ZWdlE1YTRaalY4dUdobENleEFjN0VxbmVVN0FETnFBSXg0cUI4d0FBQUpqNGlkSVcrSW5TCkZnQUFBQXR6YzJndFpXUXlOVFV4T1FBQUFDRG1hejNGVnZRNWE0WmpWOHVHaGxDZXhBYzdFcW5lVTdBRE5xQUl4NHFCOHcKQUFBRURpRXM1ejJRb2dTempvVzdDUnZ3U2RONUpVMTNmZm14cnFIQjNOS3hXUmp1WnJQY1ZXOURscmhtTlh5NGFHVUo3RQpCenNTcWQ1VHNBTTJvQWpIaW9IekFBQUFFbUpoYmk1dVpFQnRjM1JsZUhadUxtTnZiUUVDQXc9PQotLS0tLUVORCBPUkVOU1NIIFBSSVZBVEUgS0VZLS0tLS0K"
|
||||
}
|
||||
}
|
||||
|
||||
# Environment variables
|
||||
env {
|
||||
LOG_LEVEL = "INFO"
|
||||
PYTHONUNBUFFERED = "1"
|
||||
TZ = "Asia/Ho_Chi_Minh"
|
||||
# MQTT configuration (can be overridden by config.py)
|
||||
MQTT_BROKER = "mqtt.service.mesh"
|
||||
MQTT_PORT = "1883"
|
||||
MQTT_USERNAME = "relay"
|
||||
MQTT_PASSWORD = "Sey@K9c&Q4^"
|
||||
}
|
||||
|
||||
# Resource allocation
|
||||
resources {
|
||||
cpu = 256
|
||||
memory = 256
|
||||
}
|
||||
|
||||
# Logs configuration
|
||||
logs {
|
||||
max_files = 10
|
||||
max_file_size = 20
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user