From b7934e42d1f8304448e214e73a58eb35e480e0f0 Mon Sep 17 00:00:00 2001 From: AnErrupTion Date: Sat, 27 Jul 2024 15:59:02 +0200 Subject: [PATCH] Add dinit support Co-authored-by: Simon Pflaumer Signed-off-by: AnErrupTion --- build.zig | 22 ++++++++++++++++++++-- readme.md | 10 ++++++++++ res/ly-dinit | 9 +++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 res/ly-dinit diff --git a/build.zig b/build.zig index 8f9b8c3..43a4987 100644 --- a/build.zig +++ b/build.zig @@ -111,6 +111,10 @@ pub fn build(b: *std.Build) !void { installs6_step.makeFn = ServiceInstaller(.S6).make; installs6_step.dependOn(installexe_step); + const installdinit_step = b.step("installdinit", "Install the Ly dinit service"); + installdinit_step.makeFn = ServiceInstaller(.Dinit).make; + installdinit_step.dependOn(installexe_step); + const uninstallall_step = b.step("uninstallall", "Uninstall Ly and all services"); uninstallall_step.makeFn = uninstallall; } @@ -128,6 +132,7 @@ const InitSystem = enum { Openrc, Runit, S6, + Dinit, }; pub fn ServiceInstaller(comptime init_system: InitSystem) type { return struct { @@ -177,6 +182,14 @@ pub fn ServiceInstaller(comptime init_system: InitSystem) type { try std.fs.cwd().copyFile("res/ly-s6/run", service_dir, "run", .{ .override_mode = 0o755 }); try std.fs.cwd().copyFile("res/ly-s6/type", service_dir, "type", .{}); }, + .Dinit => { + const service_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, "/etc/dinit.d" }); + std.fs.cwd().makePath(service_path) catch {}; + var service_dir = std.fs.cwd().openDir(service_path, .{}) catch unreachable; + defer service_dir.close(); + + try std.fs.cwd().copyFile("res/ly-dinit", service_dir, "ly", .{}); + }, } } }; @@ -286,10 +299,15 @@ pub fn uninstallall(step: *std.Build.Step, _: ProgressNode) !void { std.debug.print("warn: s6 service not found.\n", .{}); }; - const s6_admin_service_file = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, "/etc/s6/adminsv/default/contents.d/ly-srv" }); - std.fs.cwd().deleteFile(s6_admin_service_file) catch { + const s6_admin_service_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, "/etc/s6/adminsv/default/contents.d/ly-srv" }); + std.fs.cwd().deleteFile(s6_admin_service_path) catch { std.debug.print("warn: s6 admin service not found.\n", .{}); }; + + const dinit_service_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, "/etc/dinit.d/ly" }); + std.fs.cwd().deleteFile(dinit_service_path) catch { + std.debug.print("warn: dinit service not found.\n", .{}); + }; } fn getVersionStr(b: *std.Build, name: []const u8, version: std.SemanticVersion) ![]const u8 { diff --git a/readme.md b/readme.md index 1ab5b27..a4d542e 100644 --- a/readme.md +++ b/readme.md @@ -163,6 +163,16 @@ Finally, enable the service: # s6-rc -u change ly-srv ``` +### dinit +``` +# zig build installdinit +# dinitctl enable ly +``` + +In addition to the steps above, you will also have to keep a TTY free within `/etc/dinit.d/config/console.conf`. + +To do that, change `ACTIVE_CONSOLES` so that the tty that ly should use in `/etc/ly/config.ini` is free. + ### Updating You can also install Ly without copying the system service and the configuration file. That's called *updating*. To update, simply run: diff --git a/res/ly-dinit b/res/ly-dinit new file mode 100644 index 0000000..cb2c620 --- /dev/null +++ b/res/ly-dinit @@ -0,0 +1,9 @@ +type = process +restart = true +smooth-recovery = true +# note: /usr/bin/ly-dm when installing from pacman on artix, /usr/bin/ly when building from source +command = /usr/bin/ly +depends-on = loginready +termsignal = HUP +# ly needs access to the console while loginready already occupies it +options = shares-console