https://codeberg.org/amonakov/guildmaster/pulls/1

From 22a4fc1504f547b1f685e43bf36b85abdb3b2b8d Mon Sep 17 00:00:00 2001
Message-ID: <22a4fc1504f547b1f685e43bf36b85abdb3b2b8d.1764304322.git.sam@gentoo.org>
In-Reply-To: <418bfa323cf91c63fbc468568c274388fdf0c383.1764304322.git.sam@gentoo.org>
References: <418bfa323cf91c63fbc468568c274388fdf0c383.1764304322.git.sam@gentoo.org>
From: Sam James <sam@gentoo.org>
Date: Fri, 28 Nov 2025 02:05:02 +0000
Subject: [PATCH 2/2] Add OpenRC, systemd service files

---
 guildmaster.confd   |  1 +
 guildmaster.initd   |  5 ++++
 guildmaster.service |  7 ++++++
 meson.build         | 57 +++++++++++++++++++++++++++++++++++++++++----
 meson.options       |  5 ++++
 5 files changed, 70 insertions(+), 5 deletions(-)
 create mode 100644 guildmaster.confd
 create mode 100644 guildmaster.initd
 create mode 100644 guildmaster.service
 create mode 100644 meson.options

diff --git a/guildmaster.confd b/guildmaster.confd
new file mode 100644
index 0000000..3192f17
--- /dev/null
+++ b/guildmaster.confd
@@ -0,0 +1 @@
+#GUILDMASTER_OPTS=""
diff --git a/guildmaster.initd b/guildmaster.initd
new file mode 100644
index 0000000..b2bf171
--- /dev/null
+++ b/guildmaster.initd
@@ -0,0 +1,5 @@
+#!/sbin/openrc-run
+command="/usr/bin/gm"
+command_args="${GUILDMASTER_OPTS}"
+command_background=true
+pidfile="/run/${RC_SVCNAME}.pid"
diff --git a/guildmaster.service b/guildmaster.service
new file mode 100644
index 0000000..d76a6bb
--- /dev/null
+++ b/guildmaster.service
@@ -0,0 +1,7 @@
+[Service]
+Type=exec
+ExecStart=/usr/bin/gm
+
+[Install]
+WantedBy=multi-user.target
+
diff --git a/meson.build b/meson.build
index 83d2123..c1ade60 100644
--- a/meson.build
+++ b/meson.build
@@ -8,7 +8,14 @@ project(
 )
 
 fuse_dep = dependency('fuse3')
-udev_dep = dependency('udev', required: false)
+
+if get_option('udev')
+    udev_dep = dependency('udev', required: false)
+endif
+
+if get_option('systemd')
+    systemd_dep = dependency('systemd', required: false)
+endif
 
 dependencies = [fuse_dep]
 
@@ -26,7 +33,47 @@ gm_exe = executable(
     install: true,
 )
 
-install_data(
-    ['cuse-guild.rules'],
-    install_dir: join_paths(udev_dep.get_variable('udevdir'), 'rules.d'),
-)
+if get_option('udev')
+    if udev_dep.found()
+        udevrulesdir = join_paths(udev_dep.get_variable('udevdir'), 'rules.d')
+    else
+        udevrulesdir = get_option('udevrulesdir')
+        if udevrulesdir = ''
+            udevrulesdir = '/usr/lib/udev/rules.d'
+        endif
+    endif
+
+    install_data(
+        ['cuse-guild.rules'],
+        install_dir: udevrulesdir,
+    )
+endif
+
+if get_option('openrc')
+    install_data(
+        ['guildmaster.confd'],
+        rename: ['guildmaster'],
+        install_dir: '/etc/conf.d',
+    )
+    install_data(
+        ['guildmaster.initd'],
+        rename: ['guildmaster'],
+        install_dir: '/etc/init.d',
+    )
+endif
+
+if get_option('systemd')
+    if systemd_dep.found()
+        systemdunitdir = systemd_dep.get_variable('systemdsystemunitdir')
+    else
+        systemdunitdir = get_option('systemdunitdir')
+        if systemdunitdir = ''
+            systemdunitdirdir = '/usr/lib/systemd/system'
+        endif
+    endif
+
+    install_data(
+        ['guildmaster.service'],
+        install_dir: systemdunitdir,
+    )
+endif
diff --git a/meson.options b/meson.options
new file mode 100644
index 0000000..4b5dd5d
--- /dev/null
+++ b/meson.options
@@ -0,0 +1,5 @@
+option('openrc', type : 'boolean', value : true, description : 'Install OpenRC service files')
+option('systemd', type : 'boolean', value : true, description : 'Install systemd service files')
+option('systemdunitdir', type: 'string', description: 'systemd services directory (defaults to /usr/lib/systemd/system')
+option('udev', type : 'boolean', value : true, description : 'Install udev rules')
+option('udevrulesdir', type : 'string', description : 'udev rules directory (defaults to /usr/lib/udev/rules.d)')
-- 
2.52.0

