Add dinit support

Co-authored-by: Simon Pflaumer <s.pflaumer@murena.io>
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion 2024-07-27 15:59:02 +02:00
parent e775827c8b
commit b7934e42d1
No known key found for this signature in database
GPG Key ID: 3E85EB44F610AD7F
3 changed files with 39 additions and 2 deletions

View File

@ -111,6 +111,10 @@ pub fn build(b: *std.Build) !void {
installs6_step.makeFn = ServiceInstaller(.S6).make; installs6_step.makeFn = ServiceInstaller(.S6).make;
installs6_step.dependOn(installexe_step); 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"); const uninstallall_step = b.step("uninstallall", "Uninstall Ly and all services");
uninstallall_step.makeFn = uninstallall; uninstallall_step.makeFn = uninstallall;
} }
@ -128,6 +132,7 @@ const InitSystem = enum {
Openrc, Openrc,
Runit, Runit,
S6, S6,
Dinit,
}; };
pub fn ServiceInstaller(comptime init_system: InitSystem) type { pub fn ServiceInstaller(comptime init_system: InitSystem) type {
return struct { 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/run", service_dir, "run", .{ .override_mode = 0o755 });
try std.fs.cwd().copyFile("res/ly-s6/type", service_dir, "type", .{}); 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", .{}); 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" }); 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_file) catch { std.fs.cwd().deleteFile(s6_admin_service_path) catch {
std.debug.print("warn: s6 admin service not found.\n", .{}); 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 { fn getVersionStr(b: *std.Build, name: []const u8, version: std.SemanticVersion) ![]const u8 {

View File

@ -163,6 +163,16 @@ Finally, enable the service:
# s6-rc -u change ly-srv # 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 ### Updating
You can also install Ly without copying the system service and the configuration file. That's You can also install Ly without copying the system service and the configuration file. That's
called *updating*. To update, simply run: called *updating*. To update, simply run:

9
res/ly-dinit Normal file
View File

@ -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