#!/bin/sh

export rvm_dir=<%= @options[:rvm_dir] %>
export RUBY_BIN=<%= @options[:ruby_bin] %>
export RAILS_ENV=production  # by default

<%= @options[:env_vars].map { |name, value| "export #{name}=#{value}" }.join("\n") %>

# While app is not installed, wait. Unfortunately, Chef will
# get errors if the app just isn't here, but we try to run it,
# so it won't initially run successfully. This avoids that
# problem by hanging until Capistrano is run, then finally
# running the app.

#i="0"
while ! [ -h <%= @options[:app_dir] %>/releases/current ]
do
  sleep 5
  #i=$[$i+1]
done

cd <%= @options[:app_dir] %>/releases/current

<%= @options[:extra_code] %>

export rvm_ignore_rvmrc=1
exec 2>&1
exec chpst -v -u <%= @options[:user] %>:<%= @options[:group] %> <%= @options[:chpst_arguments] %> <%= @options[:wrapper_dir] %>/bundle exec unicorn <%= @options[:unicorn_arguments] %>

#!/bin/sh

export rvm_dir=<%= @options[:rvm_dir] %>
export RUBY_BIN=<%= @options[:ruby_bin] %>
export RAILS_ENV=production  # by default

<%= @options[:env_vars].map { |name, value| "export #{name}=#{value}" }.join("\n") %>

# While app is not installed, wait. Unfortunately, Chef will
# get errors if the app just isn't here, but we try to run it,
# so it won't initially run successfully. This avoids that
# problem by hanging until Capistrano is run, then finally
# running the app.

#i="0"
while ! [ -h <%= @options[:app_dir] %>/current ]
do
  sleep 5
  #i=$[$i+1]
done

cd <%= @options[:app_dir] %>/current

<%= @options[:extra_code] %>

export rvm_ignore_rvmrc=1
exec 2>&1
exec chpst -v -u <%= @options[:user] %>:<%= @options[:group] %> <%= @options[:chpst_arguments] %> <%= @options[:wrapper_dir] %>/bundle exec unicorn <%= @options[:unicorn_arguments] %>

Fix path to correct Capistrano current release.
Fix path to correct Capistrano current release.
