|
@@ -37,8 +37,13 @@ def load_deployment():
|
|
|
raise ValueError("deployment must be a mapping")
|
|
raise ValueError("deployment must be a mapping")
|
|
|
namlv2 = deployment.get("namlv2")
|
|
namlv2 = deployment.get("namlv2")
|
|
|
pipewire = deployment.get("pipewire")
|
|
pipewire = deployment.get("pipewire")
|
|
|
- if not isinstance(namlv2, dict) or not isinstance(pipewire, dict):
|
|
|
|
|
- raise ValueError("deployment.namlv2 and deployment.pipewire must be mappings")
|
|
|
|
|
|
|
+ reconcile = deployment.get("reconcile")
|
|
|
|
|
+ if (
|
|
|
|
|
+ not isinstance(namlv2, dict)
|
|
|
|
|
+ or not isinstance(pipewire, dict)
|
|
|
|
|
+ or not isinstance(reconcile, dict)
|
|
|
|
|
+ ):
|
|
|
|
|
+ raise ValueError("deployment.namlv2, deployment.pipewire, and deployment.reconcile must be mappings")
|
|
|
for component, archive_format in PLUGIN_ARCHIVES.items():
|
|
for component, archive_format in PLUGIN_ARCHIVES.items():
|
|
|
plugin = deployment.get(component)
|
|
plugin = deployment.get(component)
|
|
|
if not isinstance(plugin, dict):
|
|
if not isinstance(plugin, dict):
|
|
@@ -823,19 +828,19 @@ def render_mod_host_service(config):
|
|
|
return content.encode("utf-8")
|
|
return content.encode("utf-8")
|
|
|
|
|
|
|
|
|
|
|
|
|
-def render_mod_host_reconcile_units(config):
|
|
|
|
|
|
|
+def render_reconcile_units(config):
|
|
|
repository_root = ROOT.resolve()
|
|
repository_root = ROOT.resolve()
|
|
|
state_file = repository_root / "config" / "desired-state.yaml"
|
|
state_file = repository_root / "config" / "desired-state.yaml"
|
|
|
observer_script = repository_root / config["observer_script"]
|
|
observer_script = repository_root / config["observer_script"]
|
|
|
- service_template = repository_root / config["reconcile_service_source"]
|
|
|
|
|
- timer_template = repository_root / config["reconcile_timer_source"]
|
|
|
|
|
|
|
+ service_template = repository_root / config["service_source"]
|
|
|
|
|
+ timer_template = repository_root / config["timer_source"]
|
|
|
for description, path in (
|
|
for description, path in (
|
|
|
("PipeWire observer", observer_script),
|
|
("PipeWire observer", observer_script),
|
|
|
("reconciliation service template", service_template),
|
|
("reconciliation service template", service_template),
|
|
|
("reconciliation timer template", timer_template),
|
|
("reconciliation timer template", timer_template),
|
|
|
):
|
|
):
|
|
|
if not path.is_file():
|
|
if not path.is_file():
|
|
|
- raise RuntimeError(f"mod-host {description} is missing: {path}")
|
|
|
|
|
|
|
+ raise RuntimeError(f"reconciliation {description} is missing: {path}")
|
|
|
|
|
|
|
|
service_replacements = {
|
|
service_replacements = {
|
|
|
"@PYTHON@": systemd_quote(config["python_path"]),
|
|
"@PYTHON@": systemd_quote(config["python_path"]),
|
|
@@ -850,20 +855,20 @@ def render_mod_host_reconcile_units(config):
|
|
|
|
|
|
|
|
timer_content = timer_template.read_text(encoding="utf-8").replace(
|
|
timer_content = timer_template.read_text(encoding="utf-8").replace(
|
|
|
"@RECONCILE_INTERVAL_SECONDS@",
|
|
"@RECONCILE_INTERVAL_SECONDS@",
|
|
|
- str(config["reconcile_interval_seconds"]),
|
|
|
|
|
|
|
+ str(config["interval_seconds"]),
|
|
|
)
|
|
)
|
|
|
if re.search(r"@[A-Z_]+@", timer_content):
|
|
if re.search(r"@[A-Z_]+@", timer_content):
|
|
|
raise RuntimeError("unexpanded placeholder remains in reconciliation timer template")
|
|
raise RuntimeError("unexpanded placeholder remains in reconciliation timer template")
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
"service": {
|
|
"service": {
|
|
|
- "name": config["reconcile_service"],
|
|
|
|
|
- "destination": Path.home() / config["reconcile_service_destination"],
|
|
|
|
|
|
|
+ "name": config["user_service"],
|
|
|
|
|
+ "destination": Path.home() / config["service_destination"],
|
|
|
"content": service_content.encode("utf-8"),
|
|
"content": service_content.encode("utf-8"),
|
|
|
},
|
|
},
|
|
|
"timer": {
|
|
"timer": {
|
|
|
- "name": config["reconcile_timer"],
|
|
|
|
|
- "destination": Path.home() / config["reconcile_timer_destination"],
|
|
|
|
|
|
|
+ "name": config["user_timer"],
|
|
|
|
|
+ "destination": Path.home() / config["timer_destination"],
|
|
|
"content": timer_content.encode("utf-8"),
|
|
"content": timer_content.encode("utf-8"),
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
@@ -886,15 +891,15 @@ def file_sha256(path):
|
|
|
return hashlib.sha256(path.read_bytes()).hexdigest() if path.is_file() else None
|
|
return hashlib.sha256(path.read_bytes()).hexdigest() if path.is_file() else None
|
|
|
|
|
|
|
|
|
|
|
|
|
-def install_mod_host_reconcile_units(config, registry):
|
|
|
|
|
- units = render_mod_host_reconcile_units(config)
|
|
|
|
|
- managed = registry.get("mod_host_reconcile")
|
|
|
|
|
|
|
+def install_reconcile_units(config, registry):
|
|
|
|
|
+ units = render_reconcile_units(config)
|
|
|
|
|
+ managed = registry.get("reconcile")
|
|
|
if managed is not None and managed.get("pending_uninstall"):
|
|
if managed is not None and managed.get("pending_uninstall"):
|
|
|
- raise RuntimeError("reconciliation units are pending uninstall; retry uninstall mod-host first")
|
|
|
|
|
|
|
+ raise RuntimeError("reconciliation units are pending uninstall; retry uninstall reconcile first")
|
|
|
if managed is None and (
|
|
if managed is None and (
|
|
|
- mod_host_unit_is_active(config["reconcile_service"])
|
|
|
|
|
- or mod_host_unit_is_active(config["reconcile_timer"])
|
|
|
|
|
- or mod_host_unit_is_enabled(config["reconcile_timer"])
|
|
|
|
|
|
|
+ user_unit_is_active(config["user_service"])
|
|
|
|
|
+ or user_unit_is_active(config["user_timer"])
|
|
|
|
|
+ or user_unit_is_enabled(config["user_timer"])
|
|
|
):
|
|
):
|
|
|
raise RuntimeError(
|
|
raise RuntimeError(
|
|
|
"an unmanaged Rigforge reconciliation unit is already active or enabled; "
|
|
"an unmanaged Rigforge reconciliation unit is already active or enabled; "
|
|
@@ -964,7 +969,7 @@ def install_mod_host_reconcile_units(config, registry):
|
|
|
managed = managed or {}
|
|
managed = managed or {}
|
|
|
managed["files"] = records
|
|
managed["files"] = records
|
|
|
managed["pending_install"] = True
|
|
managed["pending_install"] = True
|
|
|
- registry["mod_host_reconcile"] = managed
|
|
|
|
|
|
|
+ registry["reconcile"] = managed
|
|
|
write_registry(registry)
|
|
write_registry(registry)
|
|
|
|
|
|
|
|
for key, unit in units.items():
|
|
for key, unit in units.items():
|
|
@@ -988,7 +993,7 @@ def install_mod_host_reconcile_units(config, registry):
|
|
|
for record in records.values():
|
|
for record in records.values():
|
|
|
record.pop("previous_installed_sha256", None)
|
|
record.pop("previous_installed_sha256", None)
|
|
|
managed.pop("pending_install", None)
|
|
managed.pop("pending_install", None)
|
|
|
- registry["mod_host_reconcile"] = managed
|
|
|
|
|
|
|
+ registry["reconcile"] = managed
|
|
|
write_registry(registry)
|
|
write_registry(registry)
|
|
|
|
|
|
|
|
timer_name = units["timer"]["name"]
|
|
timer_name = units["timer"]["name"]
|
|
@@ -1007,14 +1012,14 @@ def install_mod_host_reconcile_units(config, registry):
|
|
|
]
|
|
]
|
|
|
)
|
|
)
|
|
|
run(["systemctl", "--user", "is-active", "--quiet", timer_name])
|
|
run(["systemctl", "--user", "is-active", "--quiet", timer_name])
|
|
|
- print(f"Installed and activated Rigforge PipeWire reconciliation timer ({timer_name}).")
|
|
|
|
|
|
|
+ print(f"Installed and activated Rigforge reconciliation timer ({timer_name}).")
|
|
|
|
|
|
|
|
|
|
|
|
|
-def uninstall_mod_host_reconcile_units(config, registry):
|
|
|
|
|
- managed = registry.get("mod_host_reconcile")
|
|
|
|
|
|
|
+def uninstall_reconcile_units(config, registry):
|
|
|
|
|
+ managed = registry.get("reconcile")
|
|
|
if managed is None:
|
|
if managed is None:
|
|
|
return
|
|
return
|
|
|
- units = render_mod_host_reconcile_units(config)
|
|
|
|
|
|
|
+ units = render_reconcile_units(config)
|
|
|
records = managed.get("files")
|
|
records = managed.get("files")
|
|
|
if not isinstance(records, dict) or set(records) != set(units):
|
|
if not isinstance(records, dict) or set(records) != set(units):
|
|
|
raise RuntimeError("managed reconciliation unit registry has an unexpected file set")
|
|
raise RuntimeError("managed reconciliation unit registry has an unexpected file set")
|
|
@@ -1049,11 +1054,11 @@ def uninstall_mod_host_reconcile_units(config, registry):
|
|
|
raise RuntimeError(f"managed reconciliation unit changed locally; refusing removal: {destination}")
|
|
raise RuntimeError(f"managed reconciliation unit changed locally; refusing removal: {destination}")
|
|
|
|
|
|
|
|
managed["pending_uninstall"] = True
|
|
managed["pending_uninstall"] = True
|
|
|
- registry["mod_host_reconcile"] = managed
|
|
|
|
|
|
|
+ registry["reconcile"] = managed
|
|
|
write_registry(registry)
|
|
write_registry(registry)
|
|
|
|
|
|
|
|
- run(["systemctl", "--user", "disable", "--now", config["reconcile_timer"]])
|
|
|
|
|
- run(["systemctl", "--user", "stop", config["reconcile_service"]])
|
|
|
|
|
|
|
+ run(["systemctl", "--user", "disable", "--now", config["user_timer"]])
|
|
|
|
|
+ run(["systemctl", "--user", "stop", config["user_service"]])
|
|
|
|
|
|
|
|
for key, unit in units.items():
|
|
for key, unit in units.items():
|
|
|
record = records[key]
|
|
record = records[key]
|
|
@@ -1075,19 +1080,53 @@ def uninstall_mod_host_reconcile_units(config, registry):
|
|
|
raise RuntimeError(f"recorded reconciliation unit backup is missing: {backup_path}")
|
|
raise RuntimeError(f"recorded reconciliation unit backup is missing: {backup_path}")
|
|
|
|
|
|
|
|
run(["systemctl", "--user", "daemon-reload"])
|
|
run(["systemctl", "--user", "daemon-reload"])
|
|
|
- registry.pop("mod_host_reconcile")
|
|
|
|
|
|
|
+ registry.pop("reconcile")
|
|
|
write_registry(registry)
|
|
write_registry(registry)
|
|
|
- print("Rigforge PipeWire reconciliation timer and units removed.")
|
|
|
|
|
|
|
+ print("Rigforge reconciliation timer and units removed.")
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def deploy_reconcile(action, config, registry):
|
|
|
|
|
+ if action == "install":
|
|
|
|
|
+ install_reconcile_units(config, registry)
|
|
|
|
|
+ return
|
|
|
|
|
+ if action == "uninstall":
|
|
|
|
|
+ uninstall_reconcile_units(config, registry)
|
|
|
|
|
+ if "reconcile" not in registry:
|
|
|
|
|
+ print("No managed reconciliation units to uninstall.")
|
|
|
|
|
+ return
|
|
|
|
|
+
|
|
|
|
|
+ managed = registry.get("reconcile")
|
|
|
|
|
+ if managed is None:
|
|
|
|
|
+ raise RuntimeError("reconciliation timer is not managed; install reconcile first")
|
|
|
|
|
+ if managed.get("pending_install") or managed.get("pending_uninstall"):
|
|
|
|
|
+ raise RuntimeError("reconciliation unit deployment is incomplete; retry install or uninstall reconcile")
|
|
|
|
|
+ units = render_reconcile_units(config)
|
|
|
|
|
+ records = managed.get("files")
|
|
|
|
|
+ if not isinstance(records, dict) or set(records) != set(units):
|
|
|
|
|
+ raise RuntimeError("managed reconciliation unit registry has an unexpected file set")
|
|
|
|
|
+ for key, unit in units.items():
|
|
|
|
|
+ destination = unit["destination"]
|
|
|
|
|
+ validate_user_destination(destination)
|
|
|
|
|
+ if not destination.is_file() or file_sha256(destination) != records[key].get("installed_sha256"):
|
|
|
|
|
+ raise RuntimeError(f"managed reconciliation unit changed locally or is missing: {destination}")
|
|
|
|
|
+
|
|
|
|
|
+ run(["systemctl", "--user", "start", config["user_timer"]])
|
|
|
|
|
+ run(["systemctl", "--user", "is-active", "--quiet", config["user_timer"]])
|
|
|
|
|
+ run(["systemctl", "--user", "start", config["user_service"]])
|
|
|
|
|
+ print("Rigforge desired PipeWire graph reconciled once.")
|
|
|
|
|
|
|
|
|
|
|
|
|
def mod_host_runtime_digest(config):
|
|
def mod_host_runtime_digest(config):
|
|
|
state_path = ROOT / "config" / "desired-state.yaml"
|
|
state_path = ROOT / "config" / "desired-state.yaml"
|
|
|
script_path = ROOT / config["configure_script"]
|
|
script_path = ROOT / config["configure_script"]
|
|
|
|
|
+ validator_path = ROOT / "scripts" / "validate_desired_state.py"
|
|
|
binary_path = ROOT / config["binary_source"]
|
|
binary_path = ROOT / config["binary_source"]
|
|
|
with state_path.open(encoding="utf-8") as stream:
|
|
with state_path.open(encoding="utf-8") as stream:
|
|
|
state = yaml.safe_load(stream)
|
|
state = yaml.safe_load(stream)
|
|
|
- files = [state_path, script_path, binary_path]
|
|
|
|
|
- for processor in state["routing"]["mod_host_chains"]["guitar"]["processors"]:
|
|
|
|
|
|
|
+ guitar_chain = state["routing"]["mod_host_chains"]["guitar"]
|
|
|
|
|
+ mod_host_config = state["deployment"]["mod_host"]
|
|
|
|
|
+ files = [script_path, validator_path, binary_path]
|
|
|
|
|
+ for processor in guitar_chain["processors"]:
|
|
|
asset_path = PurePosixPath(processor["asset_path"])
|
|
asset_path = PurePosixPath(processor["asset_path"])
|
|
|
if asset_path.is_absolute() or ".." in asset_path.parts:
|
|
if asset_path.is_absolute() or ".." in asset_path.parts:
|
|
|
raise RuntimeError(f"unsafe mod-host asset path: {processor['asset_path']!r}")
|
|
raise RuntimeError(f"unsafe mod-host asset path: {processor['asset_path']!r}")
|
|
@@ -1097,6 +1136,14 @@ def mod_host_runtime_digest(config):
|
|
|
files.append(resolved)
|
|
files.append(resolved)
|
|
|
|
|
|
|
|
digest = hashlib.sha256()
|
|
digest = hashlib.sha256()
|
|
|
|
|
+ digest.update(
|
|
|
|
|
+ json.dumps(
|
|
|
|
|
+ {"deployment.mod_host": mod_host_config, "routing.mod_host_chains.guitar": guitar_chain},
|
|
|
|
|
+ sort_keys=True,
|
|
|
|
|
+ separators=(",", ":"),
|
|
|
|
|
+ ).encode("utf-8")
|
|
|
|
|
+ + b"\0"
|
|
|
|
|
+ )
|
|
|
for path in files:
|
|
for path in files:
|
|
|
if not path.is_file():
|
|
if not path.is_file():
|
|
|
raise RuntimeError(f"mod-host runtime input is missing: {path}")
|
|
raise RuntimeError(f"mod-host runtime input is missing: {path}")
|
|
@@ -1114,7 +1161,7 @@ def mod_host_port_is_open(port):
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
-def mod_host_unit_is_active(service_name):
|
|
|
|
|
|
|
+def user_unit_is_active(service_name):
|
|
|
result = subprocess.run(
|
|
result = subprocess.run(
|
|
|
["systemctl", "--user", "is-active", "--quiet", service_name],
|
|
["systemctl", "--user", "is-active", "--quiet", service_name],
|
|
|
check=False,
|
|
check=False,
|
|
@@ -1124,7 +1171,7 @@ def mod_host_unit_is_active(service_name):
|
|
|
return result.returncode == 0
|
|
return result.returncode == 0
|
|
|
|
|
|
|
|
|
|
|
|
|
-def mod_host_unit_is_enabled(service_name):
|
|
|
|
|
|
|
+def user_unit_is_enabled(service_name):
|
|
|
result = subprocess.run(
|
|
result = subprocess.run(
|
|
|
["systemctl", "--user", "is-enabled", "--quiet", service_name],
|
|
["systemctl", "--user", "is-enabled", "--quiet", service_name],
|
|
|
check=False,
|
|
check=False,
|
|
@@ -1175,8 +1222,6 @@ def deploy_mod_host(action, config, registry):
|
|
|
registry["mod_host"] = managed
|
|
registry["mod_host"] = managed
|
|
|
write_registry(registry)
|
|
write_registry(registry)
|
|
|
|
|
|
|
|
- uninstall_mod_host_reconcile_units(config, registry)
|
|
|
|
|
-
|
|
|
|
|
destination_digest = (
|
|
destination_digest = (
|
|
|
hashlib.sha256(destination.read_bytes()).hexdigest()
|
|
hashlib.sha256(destination.read_bytes()).hexdigest()
|
|
|
if destination.is_file()
|
|
if destination.is_file()
|
|
@@ -1246,7 +1291,7 @@ def deploy_mod_host(action, config, registry):
|
|
|
backup = managed.get("backup")
|
|
backup = managed.get("backup")
|
|
|
backup_sha256 = managed.get("backup_sha256")
|
|
backup_sha256 = managed.get("backup_sha256")
|
|
|
else:
|
|
else:
|
|
|
- if mod_host_unit_is_active(service_name) or mod_host_unit_is_enabled(service_name):
|
|
|
|
|
|
|
+ if user_unit_is_active(service_name) or user_unit_is_enabled(service_name):
|
|
|
raise RuntimeError(
|
|
raise RuntimeError(
|
|
|
f"an unmanaged {service_name} is already active or enabled; "
|
|
f"an unmanaged {service_name} is already active or enabled; "
|
|
|
"inspect and disable it before installing Rigforge's unit"
|
|
"inspect and disable it before installing Rigforge's unit"
|
|
@@ -1313,7 +1358,6 @@ def deploy_mod_host(action, config, registry):
|
|
|
managed.pop("pending_activation", None)
|
|
managed.pop("pending_activation", None)
|
|
|
registry["mod_host"] = managed
|
|
registry["mod_host"] = managed
|
|
|
write_registry(registry)
|
|
write_registry(registry)
|
|
|
- install_mod_host_reconcile_units(config, registry)
|
|
|
|
|
print(f"Installed and activated Rigforge mod-host user service at {destination}.")
|
|
print(f"Installed and activated Rigforge mod-host user service at {destination}.")
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1322,7 +1366,7 @@ def main(argv=None):
|
|
|
parser.add_argument("action", choices=("install", "uninstall", "reload"))
|
|
parser.add_argument("action", choices=("install", "uninstall", "reload"))
|
|
|
parser.add_argument(
|
|
parser.add_argument(
|
|
|
"target",
|
|
"target",
|
|
|
- choices=("namlv2", "lsp", "dragonfly-reverb", "pipewire", "mod-host"),
|
|
|
|
|
|
|
+ choices=("namlv2", "lsp", "dragonfly-reverb", "pipewire", "mod-host", "reconcile"),
|
|
|
)
|
|
)
|
|
|
args = parser.parse_args(argv)
|
|
args = parser.parse_args(argv)
|
|
|
try:
|
|
try:
|
|
@@ -1338,6 +1382,8 @@ def main(argv=None):
|
|
|
deploy_pipewire(args.action, deployment["pipewire"], registry, quantum_frames)
|
|
deploy_pipewire(args.action, deployment["pipewire"], registry, quantum_frames)
|
|
|
elif args.target == "mod-host":
|
|
elif args.target == "mod-host":
|
|
|
deploy_mod_host(args.action, deployment["mod_host"], registry)
|
|
deploy_mod_host(args.action, deployment["mod_host"], registry)
|
|
|
|
|
+ elif args.target == "reconcile":
|
|
|
|
|
+ deploy_reconcile(args.action, deployment["reconcile"], registry)
|
|
|
else:
|
|
else:
|
|
|
component = "dragonfly_reverb" if args.target == "dragonfly-reverb" else args.target
|
|
component = "dragonfly_reverb" if args.target == "dragonfly-reverb" else args.target
|
|
|
deploy_lv2_archives(args.action, component, deployment[component], registry)
|
|
deploy_lv2_archives(args.action, component, deployment[component], registry)
|