Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions cookbooks/ssh_tunnel/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
# Recipe:: default
#

# if you want to have more than one tunnel set up on a given instance
# (which should be fairly rare) then copy the entire cookbook with a
# different top level name (don't change any filenames in it) and change
# this value to match before deploying. Oh, and be sure to add a include_recipe
# line with the new cookbook name to the main cookbook's default.rb recipe file
tunnel_name = 'ssh_tunnel'

# fill in missing information below
tunnel_vars = {
# if you want to have more than one tunnel set up on a given instance
# (which should be fairly rare) then copy the entire cookbook with a
# different top level name (don't change any filenames in it) and change
# this value to match before deploying. Oh, and be sure to add a include_recipe
# line with the new cookbook name to the main cookbook's default.rb recipe file
:name => 'ssh_tunnel',
# the host hostname (an IP will work) to ssh to
:ssh_hostname => '',
# only change this if using a non-default ssh port on the destination host,
Expand All @@ -25,14 +24,14 @@
:ssh_public_key => '',
# the port that will be being forwarded
:connect_port => '',
# the host on the remote side (or local side for a reverse tunnel)
# the host on the remote side (or local side for a reverse tunnel)
# that the :connect_port will be forwarded to
:forward_host => '',
# the port on :forward_host that :connect_port will be forwarded to
:forward_port => '',
# valid values: FWD, REV, DUAL. Determines what kind of tunnel(s) to create
# DUAL means create both a forward and reverse tunnel
:tunnel_direction => '',
:tunnel_direction => '',
# the path to the ssh executable to use when making the ssh connection
:ssh_cmd => '/usr/bin/ssh',
# whether or not to use StrictHostKeyChecking when making the ssh connection
Expand All @@ -41,8 +40,8 @@
# only set if :skip_hostkey_auth is set to false
# note that if :skip_hostkey_auth is set to true then you need to make a
# manual connection to the remote host *before* deploying this recipe
# and use the path to the known_hosts file that the remote host's public
# key is written to here. It's also even better to copy that key entry to
# and use the path to the known_hosts file that the remote host's public
# key is written to here. It's also even better to copy that key entry to
# a file somewhere on an EBS volume and use that file's path here to ensure
# that it won't be wiped after an instance restart (terminate and rebuild)
:ssh_known_hosts => ''
Expand All @@ -52,22 +51,22 @@
# should be set up on
if node[:instance_role] == ''

template "/etc/init.d/#{tunnel_name}" do
template "/etc/init.d/#{tunnel_vars[:name]}" do
source "ssh_tunnel.initd.erb"
owner 'root'
group 'root'
mode 0755
variables(tunnel_vars)
end
template "/etc/monit.d/#{tunnel_name}.monitrc" do

template "/etc/monit.d/#{tunnel_vars[:name]}.monitrc" do
source "ssh_tunnel.monitrc.erb"
owner node[:owner_name]
group node[:owner_name]
mode 0644
variables(tunnel_vars)
end

execute "monit quit"
end

end
10 changes: 5 additions & 5 deletions cookbooks/ssh_tunnel/templates/default/ssh_tunnel.monitrc.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
check process ssh_tunnel
with pidfile /var/run/ssh_tunnel.pid
start program = "/bin/sh -c '/etc/init.d/ssh_tunnel restart'"
stop program = "/bin/sh -c '/etc/init.d/ssh_tunnel stop'"
check process <%= @name %>
with pidfile /var/run/<%= @name %>.pid
start program = "/bin/sh -c '/etc/init.d/<%= @name %> restart'"
stop program = "/bin/sh -c '/etc/init.d/<%= @name %> stop'"
<% if @tunnel_direction != 'REV' %>
if failed host 127.0.0.1 port <%= @connect_port %>
with timeout 15 seconds then restart
<% end %>
<% end %>