From ae9828bc3bc8154d4bfeea6cd48317bbee9ac911 Mon Sep 17 00:00:00 2001 From: Dan Tehranian Date: Wed, 15 Oct 2014 11:44:27 -0700 Subject: [PATCH] Add support for SLES * Tested against SLES 11 SP3 --- manifests/install.pp | 8 ++++ manifests/params.pp | 1 + templates/consul.sles.erb | 94 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 templates/consul.sles.erb diff --git a/manifests/install.pp b/manifests/install.pp index 42de3f59..4bb6032c 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -101,6 +101,14 @@ content => template('consul/consul.debian.erb') } } + 'sles' : { + file { '/etc/init.d/consul': + mode => '0555', + owner => 'root', + group => 'root', + content => template('consul/consul.sles.erb') + } + } default : { fail("I don't know how to create an init script for style $init_style") } diff --git a/manifests/params.pp b/manifests/params.pp index ee30e62a..815eeab7 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -33,6 +33,7 @@ default => 'systemd', }, 'Debian' => 'debian', + 'SLES' => 'sles', default => undef } } diff --git a/templates/consul.sles.erb b/templates/consul.sles.erb new file mode 100644 index 00000000..b8f85c13 --- /dev/null +++ b/templates/consul.sles.erb @@ -0,0 +1,94 @@ +#!/bin/bash +# +# /etc/rc.d/init.d/consul +# +# Daemonize the consul agent. +# +### BEGIN INIT INFO +# Provides: consul +# Required-Start: network +# Should-Start: $null +# Required-Stop: $null +# Should-Stop: $null +# Default-Start: 3 5 +# Default-Stop: 0 1 2 6 +# Short-Description: Service discovery and configuration made easy. +# Description: Service discovery and configuration made easy. +### END INIT INFO + +. /etc/rc.status + +rc_reset + +CONSUL_BIN=<%= scope.lookupvar('consul::bin_dir') %>/consul +CONFIG_DIR=<%= scope.lookupvar('consul::config_dir') %> +LOG_FILE=/var/log/consul + + +case "$1" in + start) + echo -n "Starting consul " + ## Start daemon with startproc(8). If this fails + ## the return value is set appropriately by startproc. + startproc $CONSUL_BIN agent -config-dir "$CONFIG_DIR" <%= scope.lookupvar('consul::extra_options') %> >> "$LOG_FILE" + + # Remember status and be verbose + rc_status -v + ;; + stop) + echo -n "Shutting down consul " + ## Stop daemon with killproc(8) and if this fails + ## killproc sets the return value according to LSB. + + killproc -TERM $CONSUL_BIN + + # Remember status and be verbose + rc_status -v + ;; + restart) + ## Stop the service and regardless of whether it was + ## running or not, start it again. + $0 stop + $0 start + + # Remember status and be quiet + rc_status + ;; + reload) + # If it supports signaling: + echo -n "Reload service consul " + killproc -HUP $CONSUL_BIN + #touch /var/run/consul.pid + rc_status -v + + ## Otherwise if it does not support reload: + #rc_failed 3 + #rc_status -v + ;; + status) + echo -n "Checking for service consul " + ## Check status with checkproc(8), if process is running + ## checkproc will return with exit status 0. + + # Return value is slightly different for the status command: + # 0 - service up and running + # 1 - service dead, but /var/run/ pid file exists + # 2 - service dead, but /var/lock/ lock file exists + # 3 - service not running (unused) + # 4 - service status unknown :-( + # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.) + + # NOTE: checkproc returns LSB compliant status values. + checkproc $CONSUL_BIN + # NOTE: rc_status knows that we called this init script with + # "status" option and adapts its messages accordingly. + rc_status -v + ;; + *) + ## If no parameters are given, print which are avaiable. + echo "Usage: $0 {start|stop|status|restart|reload}" + exit 1 + ;; +esac + +rc_exit \ No newline at end of file