From cf0ab2a5bdcd68e1804dd9270f55bd91bd5184e8 Mon Sep 17 00:00:00 2001 From: Kamila Souckova Date: Mon, 29 May 2017 16:23:24 +0200 Subject: [PATCH 1/5] new type: __daemontools_service --- .../conf/type/__daemontools_service/manifest | 31 +++++++++++++++++++ .../parameter/default/log-run | 1 + .../parameter/default/run | 0 .../parameter/default/run-file | 0 .../parameter/default/servicedir | 1 + .../__daemontools_service/parameter/optional | 4 +++ 6 files changed, 37 insertions(+) create mode 100644 cdist/conf/type/__daemontools_service/manifest create mode 100644 cdist/conf/type/__daemontools_service/parameter/default/log-run create mode 100644 cdist/conf/type/__daemontools_service/parameter/default/run create mode 100644 cdist/conf/type/__daemontools_service/parameter/default/run-file create mode 100644 cdist/conf/type/__daemontools_service/parameter/default/servicedir create mode 100644 cdist/conf/type/__daemontools_service/parameter/optional diff --git a/cdist/conf/type/__daemontools_service/manifest b/cdist/conf/type/__daemontools_service/manifest new file mode 100644 index 00000000..34f45545 --- /dev/null +++ b/cdist/conf/type/__daemontools_service/manifest @@ -0,0 +1,31 @@ +#!/bin/sh + +RUN_PREFIX="#!/bin/sh +exec 2>&1 +exec " # mind the space :D + +name=$__object_id +servicedir=$(cat "$__object/parameter/servicedir") +run=$(cat "$__object/parameter/run") +runfile=$(cat "$__object/parameter/run-file") +logrun=$(cat "$__object/parameter/log-run") + +badusage() { + echo "__daemontools_service/$__object_id: exactly one of --run, --run-file must be set" >&2 + exit 1 +} + +[ -z "$run$runfile" ] && badusage +[ -n "$run" ] && [ -n "$runfile" ] && badusage + +__directory $servicedir/$name/log/main --parents + +echo "$RUN_PREFIX$run" | require="__directory/$servicedir/$name/log/main" __config_file "$servicedir/$name/run" \ + --onchange "svc -t '$servicedir/$name' 2>/dev/null" \ + --mode 755 \ + --source "${runfile:--}" + +echo "$RUN_PREFIX$logrun" | require="__directory/$servicedir/$name/log/main" __config_file $servicedir/$name/log/run \ + --onchange "svc -t '$servicedir/$name/log' 2>/dev/null" \ + --mode 755 \ + --source "-" diff --git a/cdist/conf/type/__daemontools_service/parameter/default/log-run b/cdist/conf/type/__daemontools_service/parameter/default/log-run new file mode 100644 index 00000000..80d57a74 --- /dev/null +++ b/cdist/conf/type/__daemontools_service/parameter/default/log-run @@ -0,0 +1 @@ +multilog t ./main diff --git a/cdist/conf/type/__daemontools_service/parameter/default/run b/cdist/conf/type/__daemontools_service/parameter/default/run new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__daemontools_service/parameter/default/run-file b/cdist/conf/type/__daemontools_service/parameter/default/run-file new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__daemontools_service/parameter/default/servicedir b/cdist/conf/type/__daemontools_service/parameter/default/servicedir new file mode 100644 index 00000000..b74e27f6 --- /dev/null +++ b/cdist/conf/type/__daemontools_service/parameter/default/servicedir @@ -0,0 +1 @@ +/service diff --git a/cdist/conf/type/__daemontools_service/parameter/optional b/cdist/conf/type/__daemontools_service/parameter/optional new file mode 100644 index 00000000..7e54985f --- /dev/null +++ b/cdist/conf/type/__daemontools_service/parameter/optional @@ -0,0 +1,4 @@ +log-run +run +run-file +servicedir From d30103e9d2ea55013517ebd25029a5ab7292c6b5 Mon Sep 17 00:00:00 2001 From: Kamila Souckova Date: Thu, 1 Jun 2017 17:43:43 +0200 Subject: [PATCH 2/5] __daemontools*: add/improve; + add man pages --- .../type/__daemontools/files/init.d-svscan | 63 +++++++++++++++++++ cdist/conf/type/__daemontools/man.rst | 42 +++++++++++++ cdist/conf/type/__daemontools/manifest | 20 ++++++ .../conf/type/__daemontools/parameter/boolean | 1 + .../parameter/default/from-package | 1 + .../parameter/default/install-init-script | 0 .../type/__daemontools/parameter/optional | 1 + cdist/conf/type/__daemontools/singleton | 0 .../type/__daemontools_service/explorer/svc | 1 + cdist/conf/type/__daemontools_service/man.rst | 63 +++++++++++++++++++ .../conf/type/__daemontools_service/manifest | 7 +++ 11 files changed, 199 insertions(+) create mode 100644 cdist/conf/type/__daemontools/files/init.d-svscan create mode 100644 cdist/conf/type/__daemontools/man.rst create mode 100644 cdist/conf/type/__daemontools/manifest create mode 100644 cdist/conf/type/__daemontools/parameter/boolean create mode 100644 cdist/conf/type/__daemontools/parameter/default/from-package create mode 100644 cdist/conf/type/__daemontools/parameter/default/install-init-script create mode 100644 cdist/conf/type/__daemontools/parameter/optional create mode 100644 cdist/conf/type/__daemontools/singleton create mode 100644 cdist/conf/type/__daemontools_service/explorer/svc create mode 100644 cdist/conf/type/__daemontools_service/man.rst diff --git a/cdist/conf/type/__daemontools/files/init.d-svscan b/cdist/conf/type/__daemontools/files/init.d-svscan new file mode 100644 index 00000000..127dfdb3 --- /dev/null +++ b/cdist/conf/type/__daemontools/files/init.d-svscan @@ -0,0 +1,63 @@ +#!/bin/bash +### BEGIN INIT INFO +# Provides: svscan +# Required-Start: +# Required-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: svscan +# Description: djb svscan +### END INIT INFO +# from https://gist.githubusercontent.com/pacojp/5766990/raw/2ed009ab19515afc9e58291b636d673c5ca864b3/init.d.svscan +# written by Adam McKenna +# edited by Kamila Součková + +export PATH=$PATH:/usr/local/bin + +l=/var/log/svscan + +if [ ! -d $l ]; then + mkdir $l + chown daemon $l +fi + +case "$1" in + start) + echo -n "Starting daemontools: " + if [ ! `pidof svscan` ]; then + echo -n "svscan " + env - PATH="$PATH" svscan /service 2>&1 | setuidgid daemon multilog t /var/log/svscan & + echo "." + else + echo "already running." + fi + ;; + stop) + echo -n "Stopping daemontools: " + if [ `pidof svscan` ]; then + echo -n "svscan" + while [ `pidof svscan` ]; do + kill `pidof svscan` + echo -n "." + done + fi + echo -n " services" + for i in `ls -d /service/*`; do + svc -dx $i + echo -n "." + done + echo -n " logging " + for i in `ls -d /service/*/log`; do + svc -dx $i + echo -n "." + done + echo "" + ;; + restart|force-reload) + $0 stop + $0 start + ;; + *) + echo 'Usage: /etc/init.d/svscan {start|stop|restart|force-reload}' + exit 1 +esac diff --git a/cdist/conf/type/__daemontools/man.rst b/cdist/conf/type/__daemontools/man.rst new file mode 100644 index 00000000..62dc5681 --- /dev/null +++ b/cdist/conf/type/__daemontools/man.rst @@ -0,0 +1,42 @@ +cdist-type__daemontools(7) +========================== + +NAME +---- +cdist-type__daemontools - Install daemontools + + +DESCRIPTION +----------- +Install djb daemontools and (optionally) an init script. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +from-package + Package to install. Must be compatible with the original daemontools. Example: daemontools-encore. Default: daemontools. + +BOOLEAN PARAMETERS +------------------ +install-init-script + Add an init script and set it to start on boot. Default yes. + +EXAMPLES +-------- + +.. code-block:: sh + + __daemontools --from-package daemontools-encore # if you prefer + +SEE ALSO +-------- +cdist-type__daemontools_service + +AUTHORS +------- +Kamila Součková diff --git a/cdist/conf/type/__daemontools/manifest b/cdist/conf/type/__daemontools/manifest new file mode 100644 index 00000000..550994a7 --- /dev/null +++ b/cdist/conf/type/__daemontools/manifest @@ -0,0 +1,20 @@ +#!/bin/sh + +pkg=$(cat "$__object/parameter/from-package") + +__package $pkg + +if [ -f "$__object/parameter/install-init-script" ]; then + init=$(cat "$__global/explorer/init") + case $init in + init) + __config_file /etc/init.d/svscan --mode 755 --source "$__type/files/init.d-svscan" + require="$require __config_file/etc/init.d/svscan" __start_on_boot svscan + require="$require __start_on_boot/svscan" __process svscan --start 'service svscan start' + ;; + *) + echo "Your init system ($init) is not supported by this type. Submit a patch at github.com/ungleich/cdist!" + exit 1 + ;; + esac +fi diff --git a/cdist/conf/type/__daemontools/parameter/boolean b/cdist/conf/type/__daemontools/parameter/boolean new file mode 100644 index 00000000..99a1cefd --- /dev/null +++ b/cdist/conf/type/__daemontools/parameter/boolean @@ -0,0 +1 @@ +install-init-script diff --git a/cdist/conf/type/__daemontools/parameter/default/from-package b/cdist/conf/type/__daemontools/parameter/default/from-package new file mode 100644 index 00000000..598dd40a --- /dev/null +++ b/cdist/conf/type/__daemontools/parameter/default/from-package @@ -0,0 +1 @@ +daemontools diff --git a/cdist/conf/type/__daemontools/parameter/default/install-init-script b/cdist/conf/type/__daemontools/parameter/default/install-init-script new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__daemontools/parameter/optional b/cdist/conf/type/__daemontools/parameter/optional new file mode 100644 index 00000000..8eca305b --- /dev/null +++ b/cdist/conf/type/__daemontools/parameter/optional @@ -0,0 +1 @@ +from-package diff --git a/cdist/conf/type/__daemontools/singleton b/cdist/conf/type/__daemontools/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__daemontools_service/explorer/svc b/cdist/conf/type/__daemontools_service/explorer/svc new file mode 100644 index 00000000..4a867485 --- /dev/null +++ b/cdist/conf/type/__daemontools_service/explorer/svc @@ -0,0 +1 @@ +command -v svc diff --git a/cdist/conf/type/__daemontools_service/man.rst b/cdist/conf/type/__daemontools_service/man.rst new file mode 100644 index 00000000..aa15a826 --- /dev/null +++ b/cdist/conf/type/__daemontools_service/man.rst @@ -0,0 +1,63 @@ +cdist-type__daemontools_service(7) +================================== + +NAME +---- +cdist-type__daemontools_service - Create a daemontools-compatible service dir. + + +DESCRIPTION +----------- +Create a directory structure compatible with daemontools-like service management. + +Note that svc must be present on the target system. + +The object ID will be used as the service name. + +REQUIRED PARAMETERS +------------------- +None. + +OPTIONAL PARAMETERS +------------------- +run + Command to run. exec-ing and stderr redirection will be added. One of run, run-file must be specified. + + Example: `my-program` + +run-file + File to save as /run. One of run, run-file must be specified. + + Example: +.. code-block:: sh + #!/bin/sh + exec 2>&1 + exec my_program + + +log-run + Command to run for log consumption. Default: `multilog t ./main` + +servicedir + Directory to install into. Default: `/service` + +BOOLEAN PARAMETERS +------------------ +None. + +EXAMPLES +-------- + +.. code-block:: sh + + require="__daemontools" __daemontools_service prometheus --run "setuidgid prometheus $GOBIN/prometheus $FLAGS" + + +SEE ALSO +-------- +cdist-type__daemontools + + +AUTHORS +------- +Kamila Součková diff --git a/cdist/conf/type/__daemontools_service/manifest b/cdist/conf/type/__daemontools_service/manifest index 34f45545..175066af 100644 --- a/cdist/conf/type/__daemontools_service/manifest +++ b/cdist/conf/type/__daemontools_service/manifest @@ -10,6 +10,13 @@ run=$(cat "$__object/parameter/run") runfile=$(cat "$__object/parameter/run-file") logrun=$(cat "$__object/parameter/log-run") +svc=$(cat "$__type/explorer/svc") + +if [ -z "$svc" ]; then + echo "svc not found! Install daemontools first: see __daemontools" + exit 1 +fi + badusage() { echo "__daemontools_service/$__object_id: exactly one of --run, --run-file must be set" >&2 exit 1 From 5ac324cd91c12c088c531f69661f076421959e40 Mon Sep 17 00:00:00 2001 From: Kamila Souckova Date: Thu, 1 Jun 2017 22:26:18 +0200 Subject: [PATCH 3/5] sacrifice to the evil manpage demons --- cdist/conf/type/__daemontools/man.rst | 9 ++++++++- cdist/conf/type/__daemontools_service/man.rst | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__daemontools/man.rst b/cdist/conf/type/__daemontools/man.rst index 62dc5681..2e012cb5 100644 --- a/cdist/conf/type/__daemontools/man.rst +++ b/cdist/conf/type/__daemontools/man.rst @@ -35,8 +35,15 @@ EXAMPLES SEE ALSO -------- -cdist-type__daemontools_service +:strong:`cdist-type__daemontools_service`\ (7) AUTHORS ------- Kamila Součková + +COPYING +------- +Copyright \(C) 2017 Kamila Součková. 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/cdist/conf/type/__daemontools_service/man.rst b/cdist/conf/type/__daemontools_service/man.rst index aa15a826..0d75917e 100644 --- a/cdist/conf/type/__daemontools_service/man.rst +++ b/cdist/conf/type/__daemontools_service/man.rst @@ -55,9 +55,16 @@ EXAMPLES SEE ALSO -------- -cdist-type__daemontools +:strong:`cdist-type__daemontools`\ (7) AUTHORS ------- Kamila Součková + +COPYING +------- +Copyright \(C) 2017 Kamila Součková. 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. From c16277bb8fc36f207fdabc533ce01406ff609188 Mon Sep 17 00:00:00 2001 From: Kamila Souckova Date: Thu, 1 Jun 2017 22:55:58 +0200 Subject: [PATCH 4/5] =?UTF-8?q?manpage=20d=C3=A6mons=20won't=20stop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cdist/conf/type/__daemontools_service/man.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/cdist/conf/type/__daemontools_service/man.rst b/cdist/conf/type/__daemontools_service/man.rst index 0d75917e..66360361 100644 --- a/cdist/conf/type/__daemontools_service/man.rst +++ b/cdist/conf/type/__daemontools_service/man.rst @@ -29,6 +29,7 @@ run-file File to save as /run. One of run, run-file must be specified. Example: + .. code-block:: sh #!/bin/sh exec 2>&1 From 42bc5e28b90d4143c8f7318773bd601f8b54f3c7 Mon Sep 17 00:00:00 2001 From: Kamila Souckova Date: Thu, 1 Jun 2017 23:01:03 +0200 Subject: [PATCH 5/5] WHY can't I write a man page? --- cdist/conf/type/__daemontools_service/man.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/cdist/conf/type/__daemontools_service/man.rst b/cdist/conf/type/__daemontools_service/man.rst index 66360361..ec1d20ff 100644 --- a/cdist/conf/type/__daemontools_service/man.rst +++ b/cdist/conf/type/__daemontools_service/man.rst @@ -31,6 +31,7 @@ run-file Example: .. code-block:: sh + #!/bin/sh exec 2>&1 exec my_program