Import evilham's runit types as it

This commit is contained in:
fnux 2021-01-11 14:10:55 +01:00
parent d3bf8512ec
commit 367cbde75b
No known key found for this signature in database
GPG Key ID: 4502C902C00A1E12
10 changed files with 184 additions and 0 deletions

View File

@ -0,0 +1,7 @@
#!/bin/sh -e
runit_etc_dir="/etc/runit"
if [ -d "${runit_etc_dir}" ]; then
echo "YES"
fi

View File

@ -0,0 +1,7 @@
#!/bin/sh -e
svdir="/var/service"
if [ -d "${svdir}" ]; then
echo "YES"
fi

View File

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

View File

@ -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 <cvs--@--evilham.com>
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.

10
type/__evilham_runit/manifest Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh -e
__package "runit"
__key_value \
--file "/etc/rc.conf" \
--key "runsvdir_enable" \
--delimiter "=" \
--value "yes" \
"runsvdir_enable"

View File

View File

@ -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 <servicedir>/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 <cvs--@--evilham.com>
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.

View File

@ -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 "-" <<EOF
#!/bin/sh
exec svlogd -tt ./main
EOF
fi
# Setup run file
__file --state "${state}" --mode 0755 --source "${source}" "${run_file}"

View File

@ -0,0 +1 @@
log

View File

@ -0,0 +1 @@
source