Merge branch 'service' into 'master'

Add simple __service type

See merge request ungleich-public/cdist!847
This commit is contained in:
poljakowski 2020-02-23 09:21:29 +01:00
commit e1b80f7222
5 changed files with 84 additions and 0 deletions

View file

@ -0,0 +1,8 @@
#!/bin/sh
# Assume systemd if systemctl is in PATH.
if [ "$(command -v systemctl)" ]; then
printf "systemd"
else
printf "unknown"
fi

View file

@ -0,0 +1,9 @@
#!/bin/sh
manager="$(cat "$__object/explorer/service-manager")"
name=$__object_id
action="$(cat "$__object/parameter/action")"
if [ "$manager" = "unknown" ]; then
echo "service '$name' '$action'"
fi

View file

@ -0,0 +1,51 @@
cdist-type__service(7)
======================
NAME
----
cdist-type__service - Run action on a system service
DESCRIPTION
-----------
This type allows you to run an action against a system service.
REQUIRED PARAMETERS
-------------------
action
Arbitrary parameter passed as action. Usually 'start', 'stop', 'reload' or 'restart'.
OPTIONAL PARAMETERS
-------------------
None.
BOOLEAN PARAMETERS
------------------
None.
EXAMPLES
--------
.. code-block:: sh
# Restart nginx service.
__service nginx --action restart
# Stop postfix service.
__service postfix --action stop
AUTHORS
-------
Timothée Floure <timothee.floure@ungleich.ch>
COPYING
-------
Copyright \(C) 2019 Timothée Floure. 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,15 @@
#!/bin/sh
manager="$(cat "$__object/explorer/service-manager")"
name=$__object_id
action="$(cat "$__object/parameter/action")"
case "$manager" in
systemd)
__systemd_service "$name" --action "$action"
;;
*)
# Unknown: handled by `service $NAME $action` in gencode-remote.
;;
esac

View file

@ -0,0 +1 @@
action