-
-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from bellycard/default-recipe-with-service
Add default recipe which installs and starts consul as a service
- Loading branch information
Showing
9 changed files
with
184 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Determine servers to connect to | ||
server_conn = node[:consul][:servers].map{|s| "-join=#{s}"}.join(' ') | ||
|
||
# Determine service params | ||
case node[:consul][:service_mode] | ||
when 'bootstrap' | ||
service_params = '-server -bootstrap' | ||
when 'server' | ||
service_params = "-server #{server_conn}" | ||
when 'client' | ||
service_params = server_conn | ||
else | ||
raise 'node[:consul][:service_mode] must be "bootstrap", "server", or "client"' | ||
end | ||
|
||
template '/etc/init.d/consul' do | ||
source 'consul-init.erb' | ||
mode 0755 | ||
variables( | ||
consul_binary: "#{node[:consul][:install_dir]}/consul", | ||
data_dir: node[:consul][:data_dir], | ||
service_params: service_params | ||
) | ||
end | ||
|
||
service 'consul' do | ||
supports status: true, restart: true | ||
action [:enable, :start] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/bin/sh | ||
### BEGIN INIT INFO | ||
# Provides: consul | ||
# Required-Start: $network $remote_fs $syslog | ||
# Required-Stop: $network $remote_fs $syslog | ||
# Default-Start: 2 3 4 5 | ||
# Default-Stop: 0 1 6 | ||
# Short-Description: Consul Service Discovery Platform | ||
# Description: Consul is a tool for discovering and configuring services | ||
# in your infrastructure. It provides several key features: | ||
# * Service Discovery | ||
# * Health Checking | ||
# * Key/Valuye Store | ||
# * Multi Datacenter | ||
### END INIT INFO | ||
|
||
CMD="<%= @consul_binary %> agent <%= @service_params %> -data-dir <%= @data_dir %>" | ||
NAME="consul" | ||
|
||
PIDFILE="/var/run/$NAME.pid" | ||
LOGFILE="/var/log/$NAME.log" | ||
|
||
get_pid() { | ||
cat "$PIDFILE" | ||
} | ||
|
||
is_running() { | ||
[ -f "$PIDFILE" ] && ps `get_pid` > /dev/null 2>&1 | ||
} | ||
|
||
case "$1" in | ||
start) | ||
if is_running; then | ||
echo "$NAME already running" | ||
else | ||
echo "Starting $NAME" | ||
$CMD >> "$LOGFILE" & | ||
echo $! > "$PIDFILE" | ||
if ! is_running; then | ||
echo "Unable to start $NAME, see $LOGFILE" | ||
exit 1 | ||
fi | ||
fi | ||
;; | ||
stop) | ||
if is_running; then | ||
echo -n "Stopping $NAME..." | ||
kill `get_pid` | ||
for i in {1..10} | ||
do | ||
if ! is_running; then | ||
break | ||
fi | ||
|
||
echo -n "." | ||
sleep 1 | ||
done | ||
echo | ||
|
||
if is_running; then | ||
echo "$NAME not stopped; may still be shutting down or shutdown may have failed" | ||
exit 1 | ||
else | ||
echo "$NAME stopped" | ||
if [ -f "$PIDFILE" ]; then | ||
rm "$PIDFILE" | ||
fi | ||
fi | ||
else | ||
echo "$NAME not running" | ||
fi | ||
;; | ||
restart) | ||
$0 stop | ||
if is_running; then | ||
echo "Unable to stop $NAME, will not attempt to start" | ||
exit 1 | ||
fi | ||
$0 start | ||
;; | ||
status) | ||
if is_running; then | ||
echo "$NAME is running" | ||
else | ||
echo "$NAME is stopped" | ||
exit 1 | ||
fi | ||
;; | ||
*) | ||
echo "Usage: $0 {start|stop|restart|status}" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
export PATH=$PATH:/usr/local/bin | ||
@test "consul is installed and in the PATH" { | ||
which consul | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'spec_helper' | ||
|
||
describe service('consul') do | ||
it { should be_enabled } | ||
it { should be_running } | ||
end | ||
|
||
[8300, 8400, 8500, 8600].each do |p| | ||
describe port(p) do | ||
it { should be_listening } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'serverspec' | ||
|
||
include SpecInfra::Helper::Exec | ||
include SpecInfra::Helper::DetectOS | ||
|
||
RSpec.configure do |c| | ||
c.path = '/usr/local/bin:/sbin:/bin:/usr/bin' | ||
end |