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..2e012cb5 --- /dev/null +++ b/cdist/conf/type/__daemontools/man.rst @@ -0,0 +1,49 @@ +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 +-------- +: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/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..ec1d20ff --- /dev/null +++ b/cdist/conf/type/__daemontools_service/man.rst @@ -0,0 +1,72 @@ +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 +-------- +: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. diff --git a/cdist/conf/type/__daemontools_service/manifest b/cdist/conf/type/__daemontools_service/manifest new file mode 100644 index 00000000..175066af --- /dev/null +++ b/cdist/conf/type/__daemontools_service/manifest @@ -0,0 +1,38 @@ +#!/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") + +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 +} + +[ -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