From 55660621394a1b4c4e727dfed6eb320256d35e2e Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 16 Mar 2015 19:00:47 +0100 Subject: [PATCH] add debian support to __consul_agent Signed-off-by: Nico Schottelius --- .../__consul_agent/files/consul.sysv-debian | 76 +++++++++++++++++++ .../files/{consul.sysv => consul.sysv-redhat} | 0 cdist/conf/type/__consul_agent/manifest | 72 +++++++++++++----- 3 files changed, 130 insertions(+), 18 deletions(-) create mode 100644 cdist/conf/type/__consul_agent/files/consul.sysv-debian rename cdist/conf/type/__consul_agent/files/{consul.sysv => consul.sysv-redhat} (100%) diff --git a/cdist/conf/type/__consul_agent/files/consul.sysv-debian b/cdist/conf/type/__consul_agent/files/consul.sysv-debian new file mode 100644 index 00000000..f4498041 --- /dev/null +++ b/cdist/conf/type/__consul_agent/files/consul.sysv-debian @@ -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 . +# + +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 diff --git a/cdist/conf/type/__consul_agent/files/consul.sysv b/cdist/conf/type/__consul_agent/files/consul.sysv-redhat similarity index 100% rename from cdist/conf/type/__consul_agent/files/consul.sysv rename to cdist/conf/type/__consul_agent/files/consul.sysv-redhat diff --git a/cdist/conf/type/__consul_agent/manifest b/cdist/conf/type/__consul_agent/manifest index 1489c19d..198b83d6 100755 --- a/cdist/conf/type/__consul_agent/manifest +++ b/cdist/conf/type/__consul_agent/manifest @@ -1,6 +1,7 @@ #!/bin/sh # # 2015 Steven Armstrong (steven-cdist at armstrong.cc) +# 2015 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -22,7 +23,7 @@ os=$(cat "$__global/explorer/os") case "$os" in - centos|redhat|ubuntu) + centos|debian|redhat|ubuntu) # whitelist safeguard : ;; @@ -139,6 +140,32 @@ require="__directory${conf_dir}" \ --onchange 'service consul status >/dev/null && service consul reload || true' \ --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 case "$os" in @@ -146,29 +173,38 @@ case "$os" in os_version="$(sed 's/[^0-9.]//g' "$__global/explorer/os_version")" major_version="${os_version%%.*}" case "$major_version" in + [456]) + init_sysvinit redhat + ;; 7) - __file /lib/systemd/system/consul.service \ - --owner root --group root --mode 0555 \ - --state "$state" \ - --source "$__type/files/consul.systemd" - export require="__file/lib/systemd/system/consul.service" + init_systemd ;; *) - __file /etc/init.d/consul \ - --owner root --group root --mode 0555 \ - --state "$state" \ - --source "$__type/files/consul.sysv" - export require="__file/etc/init.d/consul" + echo "Unsupported CentOS/Redhat version: $os_version" >&2 + exit 1 ;; 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) - __file /etc/init/consul.conf \ - --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" + init_upstart ;; esac