mirror of
https://git.srhtnin.garden/sarah/SaraSuite.git
synced 2026-10-13 18:18:12 +02:00
Background services without systemd (runit, OpenRC, ...)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
e7e233951f
commit
f63e708572
8 files changed
+325
-110
No files matched your search
+18
-8
@@ -16,8 +16,8 @@ from typing import Optional
|
||||
import tomlkit
|
||||
|
||||
from Core import (
|
||||
CacheHome, ConfigHome, CurrentDesktop, DataHome, Home, IsWindows, LoadConfig, Platform,
|
||||
ProgramsDir, SharedConfigDir, StartMenuDir, StartupDir,
|
||||
AutostartDir, CacheHome, ConfigHome, CurrentDesktop, DataHome, HasSystemd, Home, IsWindows, LoadConfig,
|
||||
Platform, ProgramsDir, SharedConfigDir, StartMenuDir, StartupDir,
|
||||
)
|
||||
|
||||
# Never worth copying out of a source checkout, whatever Include says.
|
||||
@@ -83,19 +83,26 @@ class IniEdit:
|
||||
|
||||
@dataclass
|
||||
class Service:
|
||||
"""A background service. Linux: a systemd --user Unit (placed by a
|
||||
Template). Windows: Script (relative to the app folder) run windowless by
|
||||
ServiceRun.py in WorkingDir, at login through a Startup-folder shortcut."""
|
||||
"""A background service. Linux with systemd: a --user Unit (placed by a
|
||||
Template). Windows, and Linux without systemd (runit, OpenRC, ...):
|
||||
Script (relative to the app folder) run by ServiceRun.py in WorkingDir,
|
||||
at login through a Startup-folder shortcut / an XDG autostart entry
|
||||
(Services.py), so a Linux service gives both Unit and Name/Script."""
|
||||
|
||||
Unit: str = ""
|
||||
Option: str = "" # enabled + started only while this option is ticked
|
||||
Name: str = "" # Windows: the service's name (PID file, Startup shortcut)
|
||||
Name: str = "" # run by SaraSuite: the service's name (PID file, log, autostart)
|
||||
Script: str = ""
|
||||
WorkingDir: str = ""
|
||||
|
||||
@property
|
||||
def RunBySaraSuite(self) -> bool:
|
||||
return IsWindows or not HasSystemd
|
||||
|
||||
@property
|
||||
def Id(self) -> str:
|
||||
return self.Unit or self.Name
|
||||
"""What the receipt records: the unit under systemd, else the name."""
|
||||
return (self.Name or self.Unit) if self.RunBySaraSuite else (self.Unit or self.Name)
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -229,6 +236,7 @@ class Program:
|
||||
else:
|
||||
Context.update(
|
||||
SystemdUserDir=str(ConfigHome / "systemd" / "user"),
|
||||
AutostartDir=str(AutostartDir),
|
||||
ApplicationsDir=str(DataHome / "applications"),
|
||||
DBusServicesDir=str(DataHome / "dbus-1" / "services"),
|
||||
)
|
||||
@@ -282,7 +290,9 @@ def LoadProgram(Folder: Path) -> Program:
|
||||
RequirementsFile=Python.get("RequirementsFile", ""),
|
||||
Options=[Option(**Item) for Item in _ForPlatform(Data.get("Options", []))],
|
||||
Questions=[Question(**Item) for Item in _ForPlatform(Data.get("Questions", []))],
|
||||
Templates=[TemplateFile(**Item) for Item in _ForPlatform(Data.get("Templates", []))],
|
||||
# Without systemd, its unit files would just sit there unused.
|
||||
Templates=[TemplateFile(**Item) for Item in _ForPlatform(Data.get("Templates", []))
|
||||
if HasSystemd or "{SystemdUserDir}" not in Item.get("Target", "")],
|
||||
Configs=[ConfigFile(**Item) for Item in _ForPlatform(Data.get("Configs", []))],
|
||||
IniEdits=[IniEdit(**Item) for Item in _ForPlatform(Data.get("IniEdits", []))],
|
||||
Services=[Service(**Item) for Item in _ForPlatform(Data.get("Services", []))],
|
||||
|
||||
Reference in new issue
Block a user