Skip to content

Commit

Permalink
add environment variables via upstart and switch from su to sudo
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Blumenthal committed Dec 7, 2014
1 parent fbc10ae commit 95a59db
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 1 addition & 3 deletions recipes/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

Chef::Log.info("Configuring resque for application #{application}")

env = (deploy[:environment] || {}).map{|k,v| "#{k}='#{v}'"}.join(' ')

settings = node[:resque][application]
# configure rails_env in case of non-rails app
deploy[:rails_env] ||= settings[:rails_env]
Expand All @@ -31,7 +29,7 @@
template "/etc/init/resque-#{application}-#{idx}.conf" do
source "resque-n.conf.erb"
mode '0644'
variables env: env, application: application, deploy: deploy, queue: queue, instance: idx
variables application: application, deploy: deploy, queue: queue, instance: idx
end
end
end
Expand Down
9 changes: 7 additions & 2 deletions templates/default/resque-n.conf.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#!upstart
description "Resque worker <%= @instance %> <%= @queue %>"
respawn

start on starting resque
stop on stopping resque

exec su - deploy -c 'cd <%= @deploy[:deploy_to] %>/current/; QUEUE=<%= @queue %> VERBOSE=1 RAILS_ENV=<%= @deploy[:rails_env] %> <%= @env %> bundle exec rake resque:work >> /var/log/resque/<%= @application %>-<%= @instance %>.log 2>&1'
env QUEUE=<%= @queue %>
env RAILS_ENV=<%= @deploy[:rails_env] %>
env TERM_CHILD=1

chdir <%= @deploy[:deploy_to] %>/current

exec sudo -u deploy -E -- bundle exec rake resque:work >> /var/log/resque/<%= @application %>-<%= @instance %>.log 2>&1
5 changes: 5 additions & 0 deletions templates/default/resque.conf.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!upstart
description "Resque workers"

<% @deploy[:environment].each do |k,v| %>
env <%= k %>=<%= v %>
export <%= k %>
<% end %>

pre-start script

bash << "EOF"
Expand Down

0 comments on commit 95a59db

Please sign in to comment.