1
0

feat: Add daemon single-instance lock and graceful shutdown to systemd service.

This commit is contained in:
2026-02-28 14:47:17 +01:00
parent dcb2ab3968
commit ac0ac2397b
2 changed files with 15 additions and 0 deletions

View File

@@ -25,8 +25,22 @@ public static class DaemonService
return Path.Combine(runtimeDir, "toak.sock");
}
private static FileStream? _lockFile;
public static async Task StartAsync(bool verbose)
{
var lockPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "toak", "daemon.lock");
try
{
Directory.CreateDirectory(Path.GetDirectoryName(lockPath)!);
_lockFile = new FileStream(lockPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
}
catch (IOException)
{
Console.WriteLine("Toak daemon is already running.");
return;
}
Logger.Verbose = verbose;
var socketPath = GetSocketPath();