src.nth.io/

summaryrefslogtreecommitdiff
path: root/mattertimectl/controller
diff options
context:
space:
mode:
authorLuke Hoersten <[email protected]>2026-07-28 21:11:08 -0500
committerLuke Hoersten <[email protected]>2026-07-28 21:11:08 -0500
commit207bff9cb9773e3e0ef7fe7114e4b1aa70ffd4b6 (patch)
treecc38ab4e2cb82ecdc9a8e4d03b3afbe2f6af6be0 /mattertimectl/controller
parenta55c5e9d35530d03fa8c52ceef5d2457827f0851 (diff)
Rename mattertimesync role to mattertimectl (build + controller)HEADmain
- Rename role dir and all vars from mattertimesync to mattertimectl - Rename the server subrole to controller - Build via cargo instead of npm; run the binary directly (no node) - Default fabricLabel to "Matter Time Controller"
Diffstat (limited to 'mattertimectl/controller')
-rw-r--r--mattertimectl/controller/defaults/main.yaml25
-rw-r--r--mattertimectl/controller/handlers/main.yaml6
-rw-r--r--mattertimectl/controller/meta/main.yaml5
-rw-r--r--mattertimectl/controller/tasks/main.yaml80
-rw-r--r--mattertimectl/controller/templates/config.json.j26
-rw-r--r--mattertimectl/controller/templates/mattertimectl.service.j215
-rw-r--r--mattertimectl/controller/templates/mattertimectl.timer.j210
7 files changed, 147 insertions, 0 deletions
diff --git a/mattertimectl/controller/defaults/main.yaml b/mattertimectl/controller/defaults/main.yaml
new file mode 100644
index 0000000..933a4bb
--- /dev/null
+++ b/mattertimectl/controller/defaults/main.yaml
@@ -0,0 +1,25 @@
+---
+
+# https://github.com/lukehoersten/mattertimectl/tags
+mattertimectl_version: "0.1.0"
+
+mattertimectl_user: "mattertimectl"
+mattertimectl_install_dir: "/opt/mattertimectl"
+mattertimectl_config_dir: "/etc/mattertimectl"
+# Persistent Matter fabric state: holds the controller's private keys and
+# operational certs, so it stays mode 0700 and owned by the service user.
+mattertimectl_storage_path: "/var/lib/mattertimectl"
+
+# --- config.json ---
+# IANA time-zone name (never a fixed UTC offset; DST is derived from it).
+mattertimectl_timezone: "America/Chicago"
+mattertimectl_log_level: "info" # debug, info, warn, error
+mattertimectl_fabric_label: "Matter Time Controller"
+
+# --- systemd timer schedule ---
+mattertimectl_on_boot_sec: "2min"
+mattertimectl_on_active_sec: "1h"
+mattertimectl_randomized_delay_sec: "5min"
+
+# mattertimectl_bin_url: required, set in host_vars, e.g.
+# http://{{build_server_host}}:{{build_server_port}}/mattertimectl-{{mattertimectl_version}}.tar.gz
diff --git a/mattertimectl/controller/handlers/main.yaml b/mattertimectl/controller/handlers/main.yaml
new file mode 100644
index 0000000..9b124e3
--- /dev/null
+++ b/mattertimectl/controller/handlers/main.yaml
@@ -0,0 +1,6 @@
+---
+
+- name: reload systemd
+ become: yes
+ systemd:
+ daemon_reload: "yes"
diff --git a/mattertimectl/controller/meta/main.yaml b/mattertimectl/controller/meta/main.yaml
new file mode 100644
index 0000000..0fa3794
--- /dev/null
+++ b/mattertimectl/controller/meta/main.yaml
@@ -0,0 +1,5 @@
+---
+
+# No runtime dependency: the Rust build is a single self-contained binary,
+# so the target needs no node or other runtime.
+dependencies: []
diff --git a/mattertimectl/controller/tasks/main.yaml b/mattertimectl/controller/tasks/main.yaml
new file mode 100644
index 0000000..a77145c
--- /dev/null
+++ b/mattertimectl/controller/tasks/main.yaml
@@ -0,0 +1,80 @@
+---
+
+- name: add mattertimectl user
+ become: yes
+ user:
+ name: "{{mattertimectl_user}}"
+ system: "yes"
+ shell: "/usr/sbin/nologin"
+ home: "{{mattertimectl_storage_path}}"
+ create_home: "no"
+
+- name: create mattertimectl directories
+ become: yes
+ file:
+ path: "{{item.path}}"
+ state: "directory"
+ owner: "{{item.owner}}"
+ group: "{{item.owner}}"
+ mode: "{{item.mode}}"
+ loop:
+ - { path: "{{mattertimectl_install_dir}}", owner: "root", mode: "0755" }
+ - { path: "{{mattertimectl_config_dir}}", owner: "root", mode: "0755" }
+ - { path: "{{mattertimectl_storage_path}}", owner: "{{mattertimectl_user}}", mode: "0700" }
+
+- name: check installed mattertimectl version
+ become: yes
+ stat:
+ path: "{{mattertimectl_install_dir}}/.installed-{{mattertimectl_version}}"
+ register: mattertimectl_installed
+
+- name: install mattertimectl bundle
+ become: yes
+ unarchive:
+ remote_src: yes
+ src: "{{mattertimectl_bin_url}}"
+ dest: "{{mattertimectl_install_dir}}/"
+ owner: "root"
+ group: "root"
+ when: not mattertimectl_installed.stat.exists
+
+- name: stamp installed mattertimectl version
+ become: yes
+ copy:
+ dest: "{{mattertimectl_install_dir}}/.installed-{{mattertimectl_version}}"
+ content: "{{mattertimectl_version}}\n"
+ mode: "0644"
+ when: not mattertimectl_installed.stat.exists
+
+- name: configure mattertimectl
+ become: yes
+ template:
+ src: "config.json.j2"
+ dest: "{{mattertimectl_config_dir}}/config.json"
+ owner: "root"
+ group: "{{mattertimectl_user}}"
+ mode: "0640"
+
+- name: install mattertimectl systemd service
+ become: yes
+ template:
+ src: "mattertimectl.service.j2"
+ dest: "/etc/systemd/system/mattertimectl.service"
+ mode: "0644"
+ notify: reload systemd
+
+- name: install mattertimectl systemd timer
+ become: yes
+ template:
+ src: "mattertimectl.timer.j2"
+ dest: "/etc/systemd/system/mattertimectl.timer"
+ mode: "0644"
+ notify: reload systemd
+
+- name: enable mattertimectl timer
+ become: yes
+ systemd:
+ name: "mattertimectl.timer"
+ enabled: "yes"
+ state: "started"
+ daemon_reload: "yes"
diff --git a/mattertimectl/controller/templates/config.json.j2 b/mattertimectl/controller/templates/config.json.j2
new file mode 100644
index 0000000..34f319c
--- /dev/null
+++ b/mattertimectl/controller/templates/config.json.j2
@@ -0,0 +1,6 @@
+{
+ "storagePath": "{{mattertimectl_storage_path}}",
+ "timezone": "{{mattertimectl_timezone}}",
+ "logLevel": "{{mattertimectl_log_level}}",
+ "fabricLabel": "{{mattertimectl_fabric_label}}"
+}
diff --git a/mattertimectl/controller/templates/mattertimectl.service.j2 b/mattertimectl/controller/templates/mattertimectl.service.j2
new file mode 100644
index 0000000..96cbeee
--- /dev/null
+++ b/mattertimectl/controller/templates/mattertimectl.service.j2
@@ -0,0 +1,15 @@
+[Unit]
+Description=Matter device clock synchronization
+Wants=network-online.target
+After=network-online.target time-sync.target
+
+[Service]
+Type=oneshot
+User={{mattertimectl_user}}
+Group={{mattertimectl_user}}
+ExecStart={{mattertimectl_install_dir}}/mattertimectl --config {{mattertimectl_config_dir}}/config.json sync
+NoNewPrivileges=true
+PrivateTmp=true
+ProtectSystem=strict
+ProtectHome=true
+ReadWritePaths={{mattertimectl_storage_path}}
diff --git a/mattertimectl/controller/templates/mattertimectl.timer.j2 b/mattertimectl/controller/templates/mattertimectl.timer.j2
new file mode 100644
index 0000000..a4242de
--- /dev/null
+++ b/mattertimectl/controller/templates/mattertimectl.timer.j2
@@ -0,0 +1,10 @@
+[Unit]
+Description=Periodic Matter device clock synchronization
+
+[Timer]
+OnBootSec={{mattertimectl_on_boot_sec}}
+OnUnitActiveSec={{mattertimectl_on_active_sec}}
+RandomizedDelaySec={{mattertimectl_randomized_delay_sec}}
+
+[Install]
+WantedBy=timers.target