From 367cbde75b81373d125ea128daaab5e1de8b38c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Mon, 11 Jan 2021 14:10:55 +0100 Subject: [PATCH] Import evilham's runit types as it --- type/__evilham_runit/explorer/runit-etc | 7 +++ type/__evilham_runit/explorer/svdir-exists | 7 +++ type/__evilham_runit/gencode-remote | 21 +++++++ type/__evilham_runit/man.rst | 46 +++++++++++++++ type/__evilham_runit/manifest | 10 ++++ type/__evilham_runit/singleton | 0 type/__evilham_runit_service/man.rst | 58 +++++++++++++++++++ type/__evilham_runit_service/manifest | 33 +++++++++++ .../__evilham_runit_service/parameter/boolean | 1 + .../parameter/required | 1 + 10 files changed, 184 insertions(+) create mode 100755 type/__evilham_runit/explorer/runit-etc create mode 100755 type/__evilham_runit/explorer/svdir-exists create mode 100755 type/__evilham_runit/gencode-remote create mode 100644 type/__evilham_runit/man.rst create mode 100755 type/__evilham_runit/manifest create mode 100644 type/__evilham_runit/singleton create mode 100644 type/__evilham_runit_service/man.rst create mode 100755 type/__evilham_runit_service/manifest create mode 100644 type/__evilham_runit_service/parameter/boolean create mode 100644 type/__evilham_runit_service/parameter/required diff --git a/type/__evilham_runit/explorer/runit-etc b/type/__evilham_runit/explorer/runit-etc new file mode 100755 index 0000000..4511621 --- /dev/null +++ b/type/__evilham_runit/explorer/runit-etc @@ -0,0 +1,7 @@ +#!/bin/sh -e + +runit_etc_dir="/etc/runit" + +if [ -d "${runit_etc_dir}" ]; then + echo "YES" +fi diff --git a/type/__evilham_runit/explorer/svdir-exists b/type/__evilham_runit/explorer/svdir-exists new file mode 100755 index 0000000..4eca3d4 --- /dev/null +++ b/type/__evilham_runit/explorer/svdir-exists @@ -0,0 +1,7 @@ +#!/bin/sh -e + +svdir="/var/service" + +if [ -d "${svdir}" ]; then + echo "YES" +fi diff --git a/type/__evilham_runit/gencode-remote b/type/__evilham_runit/gencode-remote new file mode 100755 index 0000000..fd2a3e0 --- /dev/null +++ b/type/__evilham_runit/gencode-remote @@ -0,0 +1,21 @@ +#!/bin/sh -e + +svdir="/var/service" +svdir_exists="$(cat "${__object}/explorer/svdir-exists")" +runit_etc="$(cat "${__object}/explorer/runit-etc")" + +if [ -z "${svdir_exists}" ]; then + echo "mkdir '${svdir}'" + sv_restart="YES" +fi +if [ -z "${runit_etc}" ]; then + echo "cp -R '/usr/local/etc/runit' '/etc/runit'" + sv_restart="YES" +fi +if grep -q "^__key_value/runsvdir_enable" "${__messages_in}"; then + sv_restart="YES" +fi + +if [ -n "${sv_restart}" ]; then + echo "service runsvdir restart || service runsvdir start" +fi diff --git a/type/__evilham_runit/man.rst b/type/__evilham_runit/man.rst new file mode 100644 index 0000000..bd1b80c --- /dev/null +++ b/type/__evilham_runit/man.rst @@ -0,0 +1,46 @@ +cdist-type__evilham_runit(7) +============================ + +NAME +---- +cdist-type__evilham_runit - Install and configure runit + + +DESCRIPTION +----------- +This is a singleton type. + +Install and configure runit, not as an init system, but as a service monitor. +It configures and if necessary starts runsvdir as documented for the +Operating System. + +This type currently heavily focuses on FreeBSD, support for other Operating +Systems can be achieved but no effort whatsoever has been put into it. + + +REQUIRED PARAMETERS +------------------- +None. + + +EXAMPLES +-------- + +.. code-block:: sh + + __evilham_runit + +SEE ALSO +-------- +:strong:`cdist-type__evilham_runit_service`\ (7) + +AUTHORS +------- +Evilham + +COPYING +------- +Copyright \(C) 2020 Evilham. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/type/__evilham_runit/manifest b/type/__evilham_runit/manifest new file mode 100755 index 0000000..195a70e --- /dev/null +++ b/type/__evilham_runit/manifest @@ -0,0 +1,10 @@ +#!/bin/sh -e + +__package "runit" + +__key_value \ + --file "/etc/rc.conf" \ + --key "runsvdir_enable" \ + --delimiter "=" \ + --value "yes" \ + "runsvdir_enable" diff --git a/type/__evilham_runit/singleton b/type/__evilham_runit/singleton new file mode 100644 index 0000000..e69de29 diff --git a/type/__evilham_runit_service/man.rst b/type/__evilham_runit_service/man.rst new file mode 100644 index 0000000..98bbc35 --- /dev/null +++ b/type/__evilham_runit_service/man.rst @@ -0,0 +1,58 @@ +cdist-type__evilham_runit_service(7) +==================================== + +NAME +---- +cdist-type__evilham_runit_service - Create a runit-compatible service dir. + + +DESCRIPTION +----------- +Create a directory structure compatible with runit-like service management. + +Note that sv(8) and runsvdir(8) must be present on the target system, this can +be achieved with e.g. `__runit`. + +The `__object_id` will be used as the service name. + + +REQUIRED PARAMETERS +------------------- +source + File to save as /run. If set to '-', standard input will be used. + + +BOOLEAN PARAMETERS +------------------ +log + Setup logging with `svlogd -tt ./main`. + + +EXAMPLES +-------- + +.. code-block:: sh + + require="__evilham_runit" __evilham_runit_service tasksched \ + --source - << EOF + #!/bin/sh -e + cd "${HOME}/.local/share/tasksched" + exec ./server.js 2>&1 + EOF + + +SEE ALSO +-------- +:strong:`cdist-type__evilham_runit`\ (7) + + +AUTHORS +------- +Evilham + +COPYING +------- +Copyright \(C) 2020 Evilham. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/type/__evilham_runit_service/manifest b/type/__evilham_runit_service/manifest new file mode 100755 index 0000000..29f3312 --- /dev/null +++ b/type/__evilham_runit_service/manifest @@ -0,0 +1,33 @@ +#!/bin/sh -e + +svdir="/var/service" +sv="${__object_id}" +state="present" +run_file="${svdir}/${sv}/run" + +source="$(cat "$__object/parameter/source")" +if [ "$source" = "-" ]; then + source="$__object/stdin" +fi + +# Create this service's directory +__directory --state "${state}" "${svdir}/${sv}" + +export require="__directory${svdir}/${sv}" + + +if [ -f "${__object}/parameter/log" ]; then + # Setup logger if requested + __directory --parents "${svdir}/${sv}/log/main" + export require="${require} __directory${svdir}/${sv}/log/main" + __file "${svdir}/${sv}/log/run" \ + --state "${state}" \ + --mode 0755 \ + --source "-" <