From ca1ad6e5210735053d93df840910af03a9b2a4ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hu=CC=88sch?= Date: Mon, 28 Apr 2014 14:47:54 +0200 Subject: [PATCH] Make the port for Node.js apps configurable and make it available to apps as PORT environment variable. --- deploy/attributes/deploy.rb | 1 + opsworks_nodejs/templates/default/node_web_app.monitrc.erb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/deploy/attributes/deploy.rb b/deploy/attributes/deploy.rb index d5b90128b0..0303231c90 100644 --- a/deploy/attributes/deploy.rb +++ b/deploy/attributes/deploy.rb @@ -107,6 +107,7 @@ # nodejs default[:deploy][application][:nodejs][:restart_command] = "monit restart node_web_app_#{application}" default[:deploy][application][:nodejs][:stop_command] = "monit stop node_web_app_#{application}" + default[:deploy][application][:nodejs][:port] = 80 end default[:opsworks][:skip_uninstall_of_other_rails_stack] = false diff --git a/opsworks_nodejs/templates/default/node_web_app.monitrc.erb b/opsworks_nodejs/templates/default/node_web_app.monitrc.erb index 5e17d47cba..72f71e4c78 100644 --- a/opsworks_nodejs/templates/default/node_web_app.monitrc.erb +++ b/opsworks_nodejs/templates/default/node_web_app.monitrc.erb @@ -1,7 +1,7 @@ check host node_web_app_<%= @application_name %> with address 127.0.0.1 - start program = "/bin/sh -c 'cd <%= @deploy[:deploy_to] %>/current; /usr/bin/env NODE_PATH=<%= @deploy[:deploy_to] %>/current/node_modules:<%= @deploy[:deploy_to] %>/current /usr/local/bin/node <%= @monitored_script %>'" + start program = "/bin/sh -c 'cd <%= @deploy[:deploy_to] %>/current; /usr/bin/env PORT=<%= @deploy[:nodejs][:port] %> NODE_PATH=<%= @deploy[:deploy_to] %>/current/node_modules:<%= @deploy[:deploy_to] %>/current /usr/local/bin/node <%= @monitored_script %>'" stop program = "/usr/bin/pkill -f 'node <%= @monitored_script %>'" - if failed port 80 protocol HTTP + if failed port <%= @deploy[:nodejs][:port] %> protocol HTTP request / with timeout 10 seconds then restart