UNPKG

pmcf

Version:

Poor mans configuration management

77 lines (68 loc) 2.19 kB
import { addType, string_attribute_writable, duration_attribute_writable } from "pacc"; import { ExtraSourceService, ExtraSourceServiceTypeDefinition, ServiceTypeDefinition, serviceEndpoints, addServiceType } from "pmcf"; import { filterConfigurable } from "../utils.mjs"; const SystemdTimesyncdServiceTypeDefinition = { name: "systemd-timesyncd", extends: ExtraSourceServiceTypeDefinition, specializationOf: ServiceTypeDefinition, owners: ServiceTypeDefinition.owners, attributes: { NTP: {...string_attribute_writable, configurable: true }, FallbackNTP: {...string_attribute_writable, configurable: true }, RootDistanceMaxSec: {...duration_attribute_writable, configurable: true }, PollIntervalMinSec: {...duration_attribute_writable, configurable: true }, PollIntervalMaxSec: {...duration_attribute_writable, configurable: true }, ConnectionRetrySec: {...duration_attribute_writable, configurable: true }, SaveIntervalSec: {...duration_attribute_writable, configurable: true } }, service: {} }; export class SystemdTimesyncdService extends ExtraSourceService { static { addType(this); addServiceType(this.typeDefinition.service, this.typeDefinition.name); } static get typeDefinition() { return SystemdTimesyncdServiceTypeDefinition; } get type() { return SystemdTimesyncdServiceTypeDefinition.name; } get systemdServices() { return this.type; } systemdConfigs(name) { const options = (lower, upper) => { return { services: `in("ntp",types) && priority >= ${lower} && priority <= ${upper}`, endpoints: e => e.networkInterface && e.networkInterface.kind !== "loopback", select: endpoint => endpoint.address, join: " ", limit: 2 }; }; return { serviceName: "systemd-timesyncd.service", configFileName: `etc/systemd/timesyncd.conf.d/${name}.conf`, content: [ "Time", { NTP: serviceEndpoints(this, options(300, 399)), FallbackNTP: serviceEndpoints(this, options(100, 199)), ...this.getProperties(filterConfigurable) } ] }; } }