Merge pull request #392 from telmich/type_consul_agent_debian

Debian Support for __consul_agent
This commit is contained in:
Steven Armstrong 2015-03-16 21:16:17 +01:00
commit c2aa601424
4 changed files with 131 additions and 18 deletions

View file

@ -0,0 +1,76 @@
#!/bin/sh
#
# 2015 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
# cdist is free software: 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.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
if [ -f "/etc/default/consul" ]; then
. /etc/default/consul
fi
. /lib/lsb/init-functions
NAME=consul
CONSUL=/usr/local/bin/consul
CONFIG=/etc/$NAME/conf.d
PID_FILE=/var/run/$NAME/pidfile
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
case "$1" in
start)
log_daemon_msg "Starting consul agent" "consul" || true
if start-stop-daemon --start --quiet --oknodo \
--pidfile "$PID_FILE" --background \
--exec $CONSUL -- agent -pid-file="$PID_FILE" -config-dir "$CONFIG"; then
log_end_msg 0 || true
else
log_end_msg 1 || true
fi
;;
stop)
log_daemon_msg "Stopping consul agent" "consul" || true
if start-stop-daemon --stop --quiet --oknodo --pidfile $PID_FILE; then
log_end_msg 0 || true
else
log_end_msg 1 || true
fi
;;
reload)
log_daemon_msg "Reloading consul agent" "consul" || true
if start-stop-daemon --stop --signal HUP --quiet --oknodo --pidfile $PID_FILE --exec $CONSUL; then
log_end_msg 0 || true
else
log_end_msg 1 || true
fi
;;
restart)
$0 stop && $0 start
;;
status)
status_of_proc -p $PID_FILE $CONSUL consul && exit 0 || exit $?
;;
*)
log_action_msg "Usage: /etc/init.d/consul {start|stop|reload|restart|status}"
exit 1
;;
esac

View file

@ -1,6 +1,7 @@
#!/bin/sh #!/bin/sh
# #
# 2015 Steven Armstrong (steven-cdist at armstrong.cc) # 2015 Steven Armstrong (steven-cdist at armstrong.cc)
# 2015 Nico Schottelius (nico-cdist at schottelius.org)
# #
# This file is part of cdist. # This file is part of cdist.
# #
@ -22,7 +23,7 @@
os=$(cat "$__global/explorer/os") os=$(cat "$__global/explorer/os")
case "$os" in case "$os" in
centos|redhat|ubuntu) centos|debian|redhat|ubuntu)
# whitelist safeguard # whitelist safeguard
: :
;; ;;
@ -139,6 +140,32 @@ require="__directory${conf_dir}" \
--onchange 'service consul status >/dev/null && service consul reload || true' \ --onchange 'service consul status >/dev/null && service consul reload || true' \
--source - --source -
init_sysvinit()
{
__file /etc/init.d/consul \
--owner root --group root --mode 0755 \
--state "$state" \
--source "$__type/files/consul.sysv-$1"
require="__file/etc/init.d/consul" __start_on_boot consul
}
init_systemd()
{
__file /lib/systemd/system/consul.service \
--owner root --group root --mode 0644 \
--state "$state" \
--source "$__type/files/consul.systemd"
require="__file/lib/systemd/system/consul.service" __start_on_boot consul
}
init_upstart()
{
__file /etc/init/consul.conf \
--owner root --group root --mode 0644 \
--state "$state" \
--source "$__type/files/consul.upstart"
require="__file/etc/init/consul.conf" __start_on_boot consul
}
# Install init script to start on boot # Install init script to start on boot
case "$os" in case "$os" in
@ -146,29 +173,38 @@ case "$os" in
os_version="$(sed 's/[^0-9.]//g' "$__global/explorer/os_version")" os_version="$(sed 's/[^0-9.]//g' "$__global/explorer/os_version")"
major_version="${os_version%%.*}" major_version="${os_version%%.*}"
case "$major_version" in case "$major_version" in
[456])
init_sysvinit redhat
;;
7) 7)
__file /lib/systemd/system/consul.service \ init_systemd
--owner root --group root --mode 0555 \
--state "$state" \
--source "$__type/files/consul.systemd"
export require="__file/lib/systemd/system/consul.service"
;; ;;
*) *)
__file /etc/init.d/consul \ echo "Unsupported CentOS/Redhat version: $os_version" >&2
--owner root --group root --mode 0555 \ exit 1
--state "$state" \
--source "$__type/files/consul.sysv"
export require="__file/etc/init.d/consul"
;; ;;
esac esac
__start_on_boot consul --state "$state"
;; ;;
debian)
os_version=$(cat "$__global/explorer/os_version")
major_version="${os_version%%.*}"
case "$major_version" in
[567])
init_sysvinit debian
;;
8)
init_sysvinit
;;
*)
echo "Unsupported Debian version $os_version" >&2
exit 1
;;
esac
;;
ubuntu) ubuntu)
__file /etc/init/consul.conf \ init_upstart
--owner root --group root --mode 0644 \
--state "$state" \
--source "$__type/files/consul.upstart"
export require="__file/etc/init/consul.conf"
__start_on_boot consul --state "$state"
;; ;;
esac esac

View file

@ -4,6 +4,7 @@ Changelog
next: next:
* New type: __firewalld_rule (Nico Schottelius) * New type: __firewalld_rule (Nico Schottelius)
* Type __consul_agent: add support for acl options (Steven Armstrong) * Type __consul_agent: add support for acl options (Steven Armstrong)
* Core: Support object ids '.cdist' (Nico Schottelius)
3.1.11: 2015-02-27 3.1.11: 2015-02-27
* New type: __staged_file: Manage staged files (Steven Armstrong) * New type: __staged_file: Manage staged files (Steven Armstrong)