Merge pull request #525 from ungleich/daemontools

new type: __daemontools_service
This commit is contained in:
Darko Poljak 2017-06-01 23:06:12 +02:00 committed by GitHub
commit 3a25fc74b9
16 changed files with 252 additions and 0 deletions

View File

@ -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 <adam@debian.org>
# edited by Kamila Součková <kamila@ksp.sk>
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

View File

@ -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á <kamila--@--ksp.sk>
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.

View File

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

View File

@ -0,0 +1 @@
install-init-script

View File

@ -0,0 +1 @@
daemontools

View File

@ -0,0 +1 @@
from-package

View File

View File

@ -0,0 +1 @@
command -v svc

View File

@ -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 <servicedir>/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á <kamila--@--ksp.sk>
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.

View File

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

View File

@ -0,0 +1 @@
multilog t ./main

View File

@ -0,0 +1 @@
/service

View File

@ -0,0 +1,4 @@
log-run
run
run-file
servicedir