From 2038244ec4de3497fda1ffb430cf206991150002 Mon Sep 17 00:00:00 2001 From: Evilham Date: Sat, 30 Oct 2021 10:40:01 +0200 Subject: [PATCH] [__runit*] Add support for Debian/Devuan Apparently these types were only supporting FreeBSD, this brings in support for Debian and Devuan by taking advantage of https://packages.debian.org/bullseye/runit-run --- type/__runit/gencode-remote | 7 ++++++ type/__runit/manifest | 25 +++++++++++++++----- type/__runit_service/man.rst | 5 ++++ type/__runit_service/manifest | 21 ++++++++++++++-- type/__runit_service/parameter/default/state | 1 + type/__runit_service/parameter/optional | 1 + 6 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 type/__runit_service/parameter/default/state create mode 100644 type/__runit_service/parameter/optional diff --git a/type/__runit/gencode-remote b/type/__runit/gencode-remote index fd2a3e0..d4e4fe8 100755 --- a/type/__runit/gencode-remote +++ b/type/__runit/gencode-remote @@ -1,5 +1,12 @@ #!/bin/sh -e + +os="$(cat "${__global}/explorer/os")" +if [ "${os}" != "freebsd" ]; then + exit +fi + +# FreeBSD-specific svdir="/var/service" svdir_exists="$(cat "${__object}/explorer/svdir-exists")" runit_etc="$(cat "${__object}/explorer/runit-etc")" diff --git a/type/__runit/manifest b/type/__runit/manifest index 195a70e..6ba174c 100755 --- a/type/__runit/manifest +++ b/type/__runit/manifest @@ -2,9 +2,22 @@ __package "runit" -__key_value \ - --file "/etc/rc.conf" \ - --key "runsvdir_enable" \ - --delimiter "=" \ - --value "yes" \ - "runsvdir_enable" +os="$(cat "${__global}/explorer/os")" +case "${os}" in + debian|devuan) + # zero-config sysvinit and systemd compatibility + __package runit-run + ;; + freebsd) + __key_value \ + --file "/etc/rc.conf" \ + --key "runsvdir_enable" \ + --delimiter "=" \ + --value "yes" \ + "runsvdir_enable" + ;; + *) + echo "Your OS '${os}' is currently not supported." >&2 + exit 1 + ;; +esac diff --git a/type/__runit_service/man.rst b/type/__runit_service/man.rst index 7b1db84..edd19e3 100644 --- a/type/__runit_service/man.rst +++ b/type/__runit_service/man.rst @@ -27,6 +27,11 @@ BOOLEAN PARAMETERS log Setup logging with `svlogd -tt ./main`. +OPTIONAL PARAMETERS +------------------- +state + Whether this service is to be 'present' (default) or 'absent'. + EXAMPLES -------- diff --git a/type/__runit_service/manifest b/type/__runit_service/manifest index 29f3312..83114fd 100755 --- a/type/__runit_service/manifest +++ b/type/__runit_service/manifest @@ -1,8 +1,21 @@ #!/bin/sh -e -svdir="/var/service" +os="$(cat "${__global}/explorer/os")" +case "${os}" in + debian|devuan) + svdir="/etc/service" + ;; + *bsd) + svdir="/var/service" + ;; + *) + echo "Your OS '${OS}' is currently not supported." >&2 + exit 1 + ;; +esac + sv="${__object_id}" -state="present" +state="$(cat "${__object}/parameter/state")" run_file="${svdir}/${sv}/run" source="$(cat "$__object/parameter/source")" @@ -15,6 +28,10 @@ __directory --state "${state}" "${svdir}/${sv}" export require="__directory${svdir}/${sv}" +if [ "${state}" != "present" ]; then + # We are done here, the service gets removed + exit +fi if [ -f "${__object}/parameter/log" ]; then # Setup logger if requested diff --git a/type/__runit_service/parameter/default/state b/type/__runit_service/parameter/default/state new file mode 100644 index 0000000..568612b --- /dev/null +++ b/type/__runit_service/parameter/default/state @@ -0,0 +1 @@ +present \ No newline at end of file diff --git a/type/__runit_service/parameter/optional b/type/__runit_service/parameter/optional new file mode 100644 index 0000000..ff72b5c --- /dev/null +++ b/type/__runit_service/parameter/optional @@ -0,0 +1 @@ +state