forked from ungleich-public/cdist
update __process to new style, warn if not present/absent
Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
This commit is contained in:
parent
e0f80f0103
commit
0f649577ad
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# 2011 Nico Schottelius (nico-cdist at schottelius.org)
|
||||
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||
#
|
||||
# This file is part of cdist.
|
||||
#
|
||||
|
@ -25,33 +25,44 @@ else
|
|||
name="$__object_id"
|
||||
fi
|
||||
|
||||
runs="$(cat "$__object/explorer/runs")"
|
||||
state_should="$(cat "$__object/parameter/state")"
|
||||
case "$state_should" in
|
||||
running)
|
||||
echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2
|
||||
state_should="present"
|
||||
;;
|
||||
stopped)
|
||||
echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2
|
||||
state_should="absent"
|
||||
;;
|
||||
esac
|
||||
|
||||
runs="$(cat "$__object/explorer/runs")"
|
||||
if [ "$runs" ]; then
|
||||
state_is="present"
|
||||
else
|
||||
state_is="absent"
|
||||
fi
|
||||
|
||||
[ "$state_is" = "$state_should" ] && exit 0
|
||||
|
||||
case "$state_should" in
|
||||
running|present)
|
||||
# Does not run, start it!
|
||||
if [ -z "$runs" ]; then
|
||||
if [ -f "$__object/parameter/start" ]; then
|
||||
present)
|
||||
if [ -f "$__object/parameter/start" ]; then
|
||||
cat "$__object/parameter/start"
|
||||
else
|
||||
else
|
||||
echo "$name"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
stopped|absent)
|
||||
# Runs, kill it!
|
||||
if [ "$runs" ]; then
|
||||
fi
|
||||
;;
|
||||
absent)
|
||||
if [ -f "$__object/parameter/stop" ]; then
|
||||
cat "$__object/parameter/stop"
|
||||
else
|
||||
echo kill "${runs}"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Unknown state: $state_should" >&2
|
||||
exit 1
|
||||
;;
|
||||
|
||||
;;
|
||||
*)
|
||||
echo "Unknown state: $state_should" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
|
|
@ -16,7 +16,9 @@ This cdist type allows you to define the state of a process.
|
|||
REQUIRED PARAMETERS
|
||||
-------------------
|
||||
state::
|
||||
State of the process: Either stopped or running.
|
||||
State of the process: Either present or absent
|
||||
(old values "stopped" and "running" are deprecated and will be removed in
|
||||
cdist 2.1).
|
||||
|
||||
|
||||
OPTIONAL PARAMETERS
|
||||
|
@ -40,23 +42,23 @@ EXAMPLES
|
|||
|
||||
--------------------------------------------------------------------------------
|
||||
# Start if not running
|
||||
__process /usr/sbin/syslog-ng --state running
|
||||
__process /usr/sbin/syslog-ng --state present
|
||||
|
||||
# Start if not running with a different binary
|
||||
__process /usr/sbin/nginx --state running --start "/etc/rc.d/nginx start"
|
||||
__process /usr/sbin/nginx --state present --start "/etc/rc.d/nginx start"
|
||||
|
||||
# Stop the process using kill (the type default) - DO NOT USE THIS
|
||||
__process /usr/sbin/sshd --state stopped
|
||||
__process /usr/sbin/sshd --state absent
|
||||
|
||||
# Stop the process using /etc/rc.d/sshd stop - THIS ONE NOT AS WELL
|
||||
__process /usr/sbin/sshd --state stopped --stop "/etc/rc.d/sshd stop"
|
||||
__process /usr/sbin/sshd --state absent --stop "/etc/rc.d/sshd stop"
|
||||
|
||||
# Ensure cups is running, which runs with -C ...:
|
||||
__process cups --start "/etc/rc.d/cups start" --state running \
|
||||
__process cups --start "/etc/rc.d/cups start" --state present \
|
||||
--name "/usr/sbin/cupsd -C /etc/cups/cupsd.conf"
|
||||
|
||||
# Ensure rpc.statd is running (which usually runs with -L) using a regexp
|
||||
__process rpcstatd --state running --start "/etc/init.d/statd start" \
|
||||
__process rpcstatd --state present --start "/etc/init.d/statd start" \
|
||||
--name "rpc.statd.*"
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
@ -68,5 +70,5 @@ SEE ALSO
|
|||
|
||||
COPYING
|
||||
-------
|
||||
Copyright \(C) 2011 Nico Schottelius. Free use of this software is
|
||||
Copyright \(C) 2011-2012 Nico Schottelius. Free use of this software is
|
||||
granted under the terms of the GNU General Public License version 3 (GPLv3).
|
||||
|
|
Loading…
Reference in a new issue