How to initialize the ejabberd module inside other module - erlang

I Need to connect the AWS elastic search from ejabberd.So, I found the below module to connect after started to integrate as per instruction given in the module i get some errror
Call this function : elasticsearch:index(<<"my_index">>, <<"_doc">>, <<"id">>, #{<<"my_key">> => <<"my_value">>})
Link : https://github.com/Qualia91/elasticsearch-erlang
Erro{{noproc,{gen_server,call,[elasticsearch_workers,{checkout,#Ref<0.623895423.2148532225.144069>,true}, 5000]}},

I applied this patch to ejabberd git, started it interactively using "make relive", and in the console I tried this:
elasticsearch:index(<<"my_index">>, <<"_doc">>, <<"id">>, #{<<"my_key">> => <<"my_value">>}).
{error,{failed_connect,[{to_address,{"localhost",9200}},
{inet,[inet],econnrefused}]}}
Patch:
diff --git a/rebar.config b/rebar.config
index 746f62fb7..bb4829a07 100644
--- a/rebar.config
+++ b/rebar.config
## -20,6 +20,7 ##
{deps, [{base64url, ".*", {git, "https://github.com/dvv/base64url", {tag, "1.0.1"}}},
{cache_tab, ".*", {git, "https://github.com/processone/cache_tab", {tag, "1.0.30"}}},
+ {elasticsearch, ".*", {git, "https://github.com/Qualia91/elasticsearch-erlang", {branch, "master"}}},
{eimp, ".*", {git, "https://github.com/processone/eimp", {tag, "1.0.22"}}},
{if_var_true, tools,
{ejabberd_po, ".*", {git, "https://github.com/processone/ejabberd-po", {branch, "main"}}}},
diff --git a/rel/relive.config b/rel/relive.config
index 7e3901fd4..301342ca6 100644
--- a/rel/relive.config
+++ b/rel/relive.config
## -1,3 +1,16 ##
[{mnesia, [{dir, "_build/relive/database"}]},
+ {elasticsearch, [
+ {pools, [
+ {elasticsearch_workers, [
+ {size, 10},
+ {max_overflow, 20}
+ ], [
+ {worker_impl, elasticsearch_worker},
+ {url, "localhost"},
+ {port, 9200},
+ {http_options, []}
+ ]}
+ ]}
+ ]},
{ejabberd, [{config, "_build/relive/conf/ejabberd.yml"},
{log_path, "_build/relive/logs/ejabberd.log"}]}].
diff --git a/src/ejabberd.app.src.script b/src/ejabberd.app.src.script
index 4c8745146..1f83289ef 100644
--- a/src/ejabberd.app.src.script
+++ b/src/ejabberd.app.src.script
## -19,6 +19,7 ## Vars = case file:consult(filename:join([filename:dirname(SCRIPT), "..", "vars.co
[compiler, inets, mnesia, os_mon,
cache_tab,
eimp,
+ elasticsearch,
fast_tls,
fast_xml,
fast_yaml,

Related

Elixir OTP 24 doesn’t apply custom Logger backend

I have an umbrella application which has logger configuration in the root config.exs file:
config :logger,
compile_time_purge_level: :debug,
backends: [
{LoggerFileBackend, :backends_log}
]
config :logger, :backends_log,
path: "path/to/awesome.log",
level: :debug,
metadata: :all
After updating OTP from 22 to 24 version (elixir 1.12.3, erlang 24.1), backends_log is not starting and all logs are going to STDOUT with default :console backend. But configuration is still same:
Application.get_all_env(:kernel)
=> [
logger: [
{:handler, :default, :logger_std_h,
%{
config: %{type: :standard_io},
formatter: {:logger_formatter,
%{legacy_header: true, single_line: false}}
}}
],
logger_sasl_compatible: false,
logger_level: :notice,
shell_docs_ansi: :auto
]
Application.get_all_env(:logger)
=> [
handle_sasl_reports: true,
discard_threshold: 5000,
compile_time_purge_matching: [],
sync_threshold: 10000,
utc_log: false,
console: [],
backends_log: [path: "path/to/awesome.log", level: :debug, metadata: :all],
start_options: [],
pdu_format_reviewer_error_count: [level: :error],
compile_time_application: nil,
backends: [
{LoggerFileBackend, :backends_log}
],
discard_threshold_periodic_check: 30000,
translators: [
{Plug.Cowboy.Translator, :translate},
{Logger.Translator, :translate}
],
compile_time_purge_level: :debug,
truncate: 8096,
log_counter: [level: :debug],
handle_otp_reports: true,
discard_threshold_for_error_logger: 500,
translator_inspect_opts: []
]
:logger.get_primary_config()
=> %{
filter_default: :log,
filters: [process_disabled: {&Logger.Filter.process_disabled/2, []}],
level: :debug,
metadata: %{}
}
I can fix this problem with Runtime Configuration
Logger.add_backend({LoggerFileBackend, :backends_log})
Logger.configure_backend(
{LoggerFileBackend, :backends_log},
path: "path/to/awesome.log",
level: :debug,
metadata: :all
)
Logger.remove_backend(Logger.Backends.Console)
but I think Application Configuration is more proper way.
How should I fix this problem?
Your config works for me. My configuration is: Ubuntu2004, Elixir 1.12.2, Erlang 24.1 (ESL Erlang). I tried to recreate your problem. Take a look at it, it might help.
https://github.com/z5ottu/elixir_12_logger_test

Devise Login working on Localhost but not Production

I am facing an issue that drives me crazy - mostly because there are no logs or error messages and the fact that it works on localhost but not production.
The issue:
I go to login page - enter the credentials (100% correct) and hit the login button. Not logged on and no message, no log entries, not logged on. It works as expected on localhost.
There is little I can give you despite the configuration I am working with- and I am hoping someone else faced this issue and was able to resolve it.
Ubuntu version:
Distributor ID: Ubuntu
Description: Ubuntu 14.04.3 LTS
Release: 14.04
Codename: trusty
Rails version:
Rails 5.0.1
Ruby version:
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]
Devise version:
devise (4.2.0)
Nginx version:
nginx version: nginx/1.10.2
Passenger version:
Phusion Passenger 5.1.2
Production Log:
I, [2017-02-19T16:42:34.671850 #12709] INFO -- : [2c7d1cea-31d4-414f-a3bf-0ca1f0434a66] Processing by StaticPagesController#teaser as HTML
I, [2017-02-19T16:42:34.672014 #12709] INFO -- : [2c7d1cea-31d4-414f-a3bf-0ca1f0434a66] Parameters: {"locale"=>"en"}
I, [2017-02-19T16:42:34.678782 #12709] INFO -- : [2c7d1cea-31d4-414f-a3bf-0ca1f0434a66] Rendering static_pages/teaser.html.haml within layouts/teaser
I, [2017-02-19T16:42:34.719835 #12709] INFO -- : [2c7d1cea-31d4-414f-a3bf-0ca1f0434a66] Rendered static_pages/teaser.html.haml within layouts/teaser (40.8ms)
I, [2017-02-19T16:42:34.729883 #12709] INFO -- : [2c7d1cea-31d4-414f-a3bf-0ca1f0434a66] Rendered layouts/tracking/_google_analytics.html.haml (1.7ms)
I, [2017-02-19T16:42:34.737139 #12709] INFO -- : [2c7d1cea-31d4-414f-a3bf-0ca1f0434a66] Rendered layouts/navs/_navigation_teaser.html.haml (6.4ms)
I, [2017-02-19T16:42:34.740481 #12709] INFO -- : [2c7d1cea-31d4-414f-a3bf-0ca1f0434a66] Rendered layouts/footers/_bottom.html.haml (2.4ms)
I, [2017-02-19T16:42:34.741421 #12709] INFO -- : [2c7d1cea-31d4-414f-a3bf-0ca1f0434a66] Completed 200 OK in 69ms (Views: 66.8ms)
D, [2017-02-19T16:42:34.743712 #12709] DEBUG -- : [2c7d1cea-31d4-414f-a3bf-0ca1f0434a66] DEBUG: Chewy strategies stack: [2] -> atomic # /usr/local/lib/ruby/gems/2.4.0/gems/chewy-0.9.0/lib/chewy/railtie.rb:17
I, [2017-02-19T16:42:38.140233 #12709] INFO -- : [efa8a6ab-c0a9-40c5-ad5c-efc5fea35ff2] Started GET "/en/users/login/" for 213.225.34.85 at 2017-02-19 16:42:38 +0100
D, [2017-02-19T16:42:38.140679 #12709] DEBUG -- : [efa8a6ab-c0a9-40c5-ad5c-efc5fea35ff2] DEBUG: Chewy strategies stack: [2] <- atomic # /usr/local/lib/ruby/gems/2.4.0/gems/chewy-0.9.0/lib/chewy/railtie.rb:17
I, [2017-02-19T16:42:38.143560 #12709] INFO -- : [efa8a6ab-c0a9-40c5-ad5c-efc5fea35ff2] Processing by Devise::SessionsController#new as HTML
I, [2017-02-19T16:42:38.143632 #12709] INFO -- : [efa8a6ab-c0a9-40c5-ad5c-efc5fea35ff2] Parameters: {"locale"=>"en"}
I, [2017-02-19T16:42:38.181675 #12709] INFO -- : [efa8a6ab-c0a9-40c5-ad5c-efc5fea35ff2] Rendering devise/sessions/new.html.haml within layouts/devise
I, [2017-02-19T16:42:38.189833 #12709] INFO -- : [efa8a6ab-c0a9-40c5-ad5c-efc5fea35ff2] Rendered devise/sessions/new.html.haml within layouts/devise (8.0ms)
I, [2017-02-19T16:42:38.196498 #12709] INFO -- : [efa8a6ab-c0a9-40c5-ad5c-efc5fea35ff2] Rendered layouts/tracking/_google_analytics.html.haml (0.3ms)
I, [2017-02-19T16:42:38.199537 #12709] INFO -- : [efa8a6ab-c0a9-40c5-ad5c-efc5fea35ff2] Rendered layouts/_error_messages.html.haml (2.2ms)
I, [2017-02-19T16:42:38.201012 #12709] INFO -- : [efa8a6ab-c0a9-40c5-ad5c-efc5fea35ff2] Rendered layouts/footers/_bottom_devise.html.haml (0.8ms)
I, [2017-02-19T16:42:38.201777 #12709] INFO -- : [efa8a6ab-c0a9-40c5-ad5c-efc5fea35ff2] Completed 200 OK in 58ms (Views: 23.5ms | ActiveRecord: 2.2ms)
D, [2017-02-19T16:42:38.202966 #12709] DEBUG -- : [efa8a6ab-c0a9-40c5-ad5c-efc5fea35ff2] DEBUG: Chewy strategies stack: [2] -> atomic # /usr/local/lib/ruby/gems/2.4.0/gems/chewy-0.9.0/lib/chewy/railtie.rb:17
I, [2017-02-19T16:42:42.616812 #12709] INFO -- : [3d15563f-bb6c-4a4e-84b4-46e473e237be] Started GET "/en/users/login/" for 213.225.34.85 at 2017-02-19 16:42:42 +0100
D, [2017-02-19T16:42:42.617237 #12709] DEBUG -- : [3d15563f-bb6c-4a4e-84b4-46e473e237be] DEBUG: Chewy strategies stack: [2] <- atomic # /usr/local/lib/ruby/gems/2.4.0/gems/chewy-0.9.0/lib/chewy/railtie.rb:17
I, [2017-02-19T16:42:42.618504 #12709] INFO -- : [3d15563f-bb6c-4a4e-84b4-46e473e237be] Processing by Devise::SessionsController#new as HTML
I, [2017-02-19T16:42:42.618574 #12709] INFO -- : [3d15563f-bb6c-4a4e-84b4-46e473e237be] Parameters: {"locale"=>"en"}
I, [2017-02-19T16:42:42.620779 #12709] INFO -- : [3d15563f-bb6c-4a4e-84b4-46e473e237be] Rendering devise/sessions/new.html.haml within layouts/devise
I, [2017-02-19T16:42:42.622348 #12709] INFO -- : [3d15563f-bb6c-4a4e-84b4-46e473e237be] Rendered devise/sessions/new.html.haml within layouts/devise (1.5ms)
I, [2017-02-19T16:42:42.624039 #12709] INFO -- : [3d15563f-bb6c-4a4e-84b4-46e473e237be] Rendered layouts/tracking/_google_analytics.html.haml (0.3ms)
I, [2017-02-19T16:42:42.624547 #12709] INFO -- : [3d15563f-bb6c-4a4e-84b4-46e473e237be] Rendered layouts/_error_messages.html.haml (0.2ms)
I, [2017-02-19T16:42:42.624961 #12709] INFO -- : [3d15563f-bb6c-4a4e-84b4-46e473e237be] Rendered layouts/footers/_bottom_devise.html.haml (0.2ms)
I, [2017-02-19T16:42:42.625530 #12709] INFO -- : [3d15563f-bb6c-4a4e-84b4-46e473e237be] Completed 200 OK in 7ms (Views: 5.0ms | ActiveRecord: 0.0ms)
D, [2017-02-19T16:42:42.626717 #12709] DEBUG -- : [3d15563f-bb6c-4a4e-84b4-46e473e237be] DEBUG: Chewy strategies stack: [2] -> atomic # /usr/local/lib/ruby/gems/2.4.0/gems/chewy-0.9.0/lib/chewy/railtie.rb:17
Nginx Log (error.log):
[ 2017-02-19 16:39:22.3744 11673/7fbd8cdd47c0 age/Ust/UstRouterMain.cpp:492 ]: Received command to shutdown gracefully. Waiting until all clients have disconnected...
[ 2017-02-19 16:39:22.3744 11673/7fbd85dca700 Ser/Server.h:817 ]: [UstRouterApiServer] Freed 0 spare client objects
[ 2017-02-19 16:39:22.3745 11673/7fbd85dca700 Ser/Server.h:464 ]: [UstRouterApiServer] Shutdown finished
[ 2017-02-19 16:39:22.3747 11673/7fbd865cb700 Ser/Server.h:464 ]: [UstRouter] Shutdown finished
[ 2017-02-19 16:39:22.3748 11673/7fbd8cdd47c0 age/Ust/UstRouterMain.cpp:523 ]: Passenger UstRouter shutdown finished
[ 2017-02-19 16:39:22.6189 11663/7f5c6c8fe7c0 age/Cor/CoreMain.cpp:1055 ]: Passenger core shutdown finished
[ 2017-02-19 16:39:23.4450 12221/7fbf2251a7c0 age/Wat/WatchdogMain.cpp:1281 ]: Starting Passenger watchdog...
[ 2017-02-19 16:39:23.4539 12224/7f409d5e37c0 age/Cor/CoreMain.cpp:1070 ]: Starting Passenger core...
[ 2017-02-19 16:39:23.4541 12224/7f409d5e37c0 age/Cor/CoreMain.cpp:245 ]: Passenger core running in multi-application mode.
[ 2017-02-19 16:39:23.4585 12224/7f409d5e37c0 age/Cor/CoreMain.cpp:820 ]: Passenger core online, PID 12224
[ 2017-02-19 16:39:23.4675 12230/7f8a2efc77c0 age/Ust/UstRouterMain.cpp:529 ]: Starting Passenger UstRouter...
[ 2017-02-19 16:39:23.4685 12230/7f8a2efc77c0 age/Ust/UstRouterMain.cpp:342 ]: Passenger UstRouter online, PID 12230
[ 2017-02-19 16:39:25.6619 12224/7f409d4cb700 age/Cor/SecurityUpdateChecker.h:464 ]: Security update check: no update found (next check in 24 hours)
App 12257 stdout:
App 12382 stdout:
2017/02/19 16:42:21 [info] 12537#12537: Using 32768KiB of shared memory for nchan in /etc/nginx/nginx.conf:74
[ 2017-02-19 16:42:21.7235 12224/7f4096e14700 age/Cor/CoreMain.cpp:585 ]: Signal received. Gracefully shutting down... (send signal 2 more time(s) to force shutdown)
[ 2017-02-19 16:42:21.7236 12224/7f409d5e37c0 age/Cor/CoreMain.cpp:989 ]: Received command to shutdown gracefully. Waiting until all clients have disconnected...
[ 2017-02-19 16:42:21.7236 12224/7f409d5e37c0 age/Cor/CoreMain.cpp:907 ]: Checking whether to disconnect long-running connections for process 12382, application /home/sandbox/rails/windhagermediahub/public (production)
[ 2017-02-19 16:42:21.7239 12224/7f4096592700 Ser/Server.h:817 ]: [ServerThr.2] Freed 128 spare client objects
[ 2017-02-19 16:42:21.7239 12224/7f4096592700 Ser/Server.h:464 ]: [ServerThr.2] Shutdown finished
[ 2017-02-19 16:42:21.7242 12224/7f4096e14700 Ser/Server.h:817 ]: [ServerThr.1] Freed 128 spare client objects
[ 2017-02-19 16:42:21.7242 12224/7f4096e14700 Ser/Server.h:464 ]: [ServerThr.1] Shutdown finished
[ 2017-02-19 16:42:21.7243 12224/7f4095d10700 Ser/Server.h:817 ]: [ApiServer] Freed 0 spare client objects
[ 2017-02-19 16:42:21.7243 12224/7f4095d10700 Ser/Server.h:464 ]: [ApiServer] Shutdown finished
[ 2017-02-19 16:42:21.7244 12224/7f409d5e37c0 age/Cor/CoreMain.cpp:907 ]: Checking whether to disconnect long-running connections for process 12382, application /home/sandbox/rails/windhagermediahub/public (production)
[ 2017-02-19 16:42:21.7265 12230/7f8a23fff700 age/Ust/UstRouterMain.cpp:422 ]: Signal received. Gracefully shutting down... (send signal 2 more time(s) to force shutdown)
[ 2017-02-19 16:42:21.7266 12230/7f8a2efc77c0 age/Ust/UstRouterMain.cpp:492 ]: Received command to shutdown gracefully. Waiting until all clients have disconnected...
[ 2017-02-19 16:42:21.7266 12230/7f8a237fe700 Ser/Server.h:817 ]: [UstRouterApiServer] Freed 0 spare client objects
[ 2017-02-19 16:42:21.7266 12230/7f8a237fe700 Ser/Server.h:464 ]: [UstRouterApiServer] Shutdown finished
[ 2017-02-19 16:42:21.7268 12230/7f8a23fff700 Ser/Server.h:464 ]: [UstRouter] Shutdown finished
[ 2017-02-19 16:42:21.7272 12230/7f8a2efc77c0 age/Ust/UstRouterMain.cpp:523 ]: Passenger UstRouter shutdown finished
[ 2017-02-19 16:42:21.9690 12224/7f409d5e37c0 age/Cor/CoreMain.cpp:1055 ]: Passenger core shutdown finished
[ 2017-02-19 16:42:22.7904 12548/7f4dcba4d7c0 age/Wat/WatchdogMain.cpp:1281 ]: Starting Passenger watchdog...
[ 2017-02-19 16:42:22.8003 12551/7f388a8967c0 age/Cor/CoreMain.cpp:1070 ]: Starting Passenger core...
[ 2017-02-19 16:42:22.8005 12551/7f388a8967c0 age/Cor/CoreMain.cpp:245 ]: Passenger core running in multi-application mode.
[ 2017-02-19 16:42:22.8053 12551/7f388a8967c0 age/Cor/CoreMain.cpp:820 ]: Passenger core online, PID 12551
[ 2017-02-19 16:42:22.8155 12557/7fd30e4537c0 age/Ust/UstRouterMain.cpp:529 ]: Starting Passenger UstRouter...
[ 2017-02-19 16:42:22.8165 12557/7fd30e4537c0 age/Ust/UstRouterMain.cpp:342 ]: Passenger UstRouter online, PID 12557
[ 2017-02-19 16:42:24.9877 12551/7f388a77e700 age/Cor/SecurityUpdateChecker.h:464 ]: Security update check: no update found (next check in 24 hours)
App 12582 stdout:
App 12709 stdout:
UPDATE:
After replacing devise with Clearance, the issue persists. According to logs it is trying to issue a GET request, whilst it is supposed to be POST. The form works on localhost and everything looks correct. I even specified the method in the login form but it is still issuing a GET. I am biting dust here.
UPDATE2:
I removed Devise altogether and any references to it in the code and subsequently set it up again - No modifications or customisations are made to Devise. Standard views and Forms are being used.
SignIn Form (Session New)
<h2>Log in</h2>
<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="form-inputs">
<%= f.input :email, required: false, autofocus: true %>
<%= f.input :password, required: false %>
<%= f.input :remember_me, as: :boolean if devise_mapping.rememberable? %>
</div>
<div class="form-actions">
<%= f.button :submit, "Log in" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
UPDATE 3
routes.rb
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
root to: 'static_pages#redirect'
localized do
match '', to: 'static_pages#teaser', :as => 'teaser', via: 'get'
scope 'legal' do
match 'data-privacy', to: 'static_pages#data_privacy', :as => 'data-privacy', via: 'get'
match 'terms-of-use', to: 'static_pages#terms_of_use', :as => 'terms_of_use', via: 'get'
match 'cookie-policy', to: 'static_pages#cookie_policy', :as => 'cookie_policy', via: 'get'
end
devise_for :users, :path_names => {:sign_in => 'login', :sign_out => 'logout'}
scope 'dashboard' do
match 'wh-a-seo-at', to: 'dashboards#seo_at', :as => 'dashboard_seo_at', via: 'get'
match 'wh-a-seo-de', to: 'dashboards#seo_de', :as => 'dashboard_seo_de', via: 'get'
match 'wh-a-uiux', to: 'dashboards#uiux', :as => 'dashboard_uiux', via: 'get'
resources :links
resources :key_performance_indicators
resources :keyword_lists do
resources :keyword_dates
resources :keyword_groups do
resources :keywords do
resources :keyword_rankings
end
end
end
end
end
end
Output: RAILS_ENV=production bundle exec rake
georg$ RAILS_ENV=production bundle exec rake routes
Prefix Verb URI Pattern Controller#Action
root GET / static_pages#redirect
teaser_en GET /en static_pages#teaser {:locale=>"en"}
data_privacy_en GET /en/legal/data-privacy(.:format) static_pages#data_privacy {:locale=>"en"}
terms_of_use_en GET /en/legal/terms-of-use(.:format) static_pages#terms_of_use {:locale=>"en"}
cookie_policy_en GET /en/legal/cookie-policy(.:format) static_pages#cookie_policy {:locale=>"en"}
new_user_session_en GET /en/users/login(.:format) devise/sessions#new {:locale=>"en"}
user_session_en POST /en/users/login(.:format) devise/sessions#create {:locale=>"en"}
destroy_user_session_en DELETE /en/users/logout(.:format) devise/sessions#destroy {:locale=>"en"}
etc.
production.rb
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Mount Action Cable outside main process or domain
# config.action_cable.mount_path = nil
# config.action_cable.url = 'wss://example.com/cable'
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :debug
# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "PRODEV0007_#{Rails.env}"
config.action_mailer.perform_caching = false
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Use a different logger for distributed setups.
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
config.active_record.dump_schema_after_migration = false
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif *.svg application_split2.css )
# Tested force_ssl with true and false
config.force_ssl = true
config.i18n.fallbacks = true
end
Formatted Version of Form
<form novalidate="novalidate" class="simple_form new_user" id="new_user" action="/en/users/login" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="✓"><input type="hidden" name="authenticity_token" value="R5dzqGlWWGhP5UD6QvR9TEZatNgot8UYtfOwQbQO+Ksv7DEgoVNDL/LSk7cRcZsxUSHnn8T/XQLkDr9B+y0weQ==">
<div class="form-inputs">
<div class="input email optional user_email"><label class="email optional" for="user_email">Email</label><input class="string email optional" autofocus="autofocus" type="email" value="" name="user[email]" id="user_email"></div>
<div class="input password optional user_password"><label class="password optional" for="user_password">Password</label><input class="password optional" type="password" name="user[password]" id="user_password"></div>
<div class="input boolean optional user_remember_me"><input value="0" type="hidden" name="user[remember_me]"><label class="boolean optional checkbox" for="user_remember_me"><input class="boolean optional" type="checkbox" value="1" name="user[remember_me]" id="user_remember_me">Remember me</label></div>
</div>
<div class="form-actions">
<input type="submit" name="commit" value="Log in" class="btn" data-disable-with="Log in">
</div>
</form>
user.rb
class User < ApplicationRecord
#include Clearance::User
extend FriendlyId
friendly_id :slug_candidates, use: :slugged
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :rememberable, :trackable
private
def slug_candidates
[
SecureRandom.hex(4).to_s + "-" + self.email[/[^#]+/]
]
end
end
UPDATE 4
For full HTML Markup - see
here
This is the form that is being produced.
layouts/devise.html.haml
!!! 5
%html
%head
%meta{:charset => "utf-8"}
%title= title
= csrf_meta_tags
%script{:src => "https://use.fontawesome.com/89c3729707.js"}
%meta{:name => "viewport", :content => "width=device-width, initial-scale=1.0"}
%meta{:name => "viewport", :content => "width=device-width, initial-scale=1, maximum-scale=1"}
%meta{:name => "description", :content => "#{meta_description}"}
/ Le HTML5 shim, for IE6-8 support of HTML elements
/[if lt IE 9]
%script{:src => "http://html5shim.googlecode.com/svn/trunk/html5.js", :type => "text/javascript"}
/ Le styles
= stylesheet_link_tag "application", :media => "all", :"data-turbolinks" => false
= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js"
= javascript_include_tag "application", :"data-turbolinks" => false
/ Le fav and touch icons
= favicon_link_tag
= render 'layouts/tracking/google_analytics'
%body.home
%div.home_overlay
/= cookie_law!
= render "layouts/navs/navigation_teaser"
= yield
- if params[:action] == "teaser" && !user_signed_in?
= render "layouts/footers/bottom"
UPDATE 6
The issue was my nginx configuration. The one that works is the following:
server {
listen 80;
server_name win-marketing.sciencesupercrew.com www.win-marketing.sciencesupercrew.com;
return 301 https://www.win-marketing.sciencesupercrew.com$request_uri;
}
server {
listen 443 ssl;
server_name win-marketing.sciencesupercrew.com;
passenger_enabled on;
rails_env production;
root /home/demo/windhagermediahub/public;
ssl on;
ssl_certificate /home/demo/ssl/ssl-bundle.crt;
ssl_certificate_key /home/demo/ssl/ssc.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
After adding these lines it started working:
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
This sounds like an SSL issue to me.
Your form is definitely POSTing to the route. You can confirm this by adding data-remote="true" to your form HTML in the browser, then watching the console as you make the request:
XHR finished loading: POST "https://win-marketing.sciencesupercrew.com/en/users/login"
When you POST, however, you are immediately redirected. You can see this if you curl the route:
$ curl -i -X POST https://win-marketing.sciencesupercrew.com/en/users/login
HTTP/1.1 301 Moved Permanently
Server: nginx/1.10.2
Date: Thu, 23 Feb 2017 14:58:04 GMT
Content-Type: text/html
Content-Length: 185
Location: https://win-marketing.sciencesupercrew.com/en/users/login/
Connection: keep-alive
Here's where SSL comes in. Rails returns a 301 (moved permanently) error when a request is not SSL but it should be:
def force_ssl_redirect(host_or_options = nil)
unless request.ssl?
options = {
:protocol => 'https://',
:host => request.host,
:path => request.fullpath,
:status => :moved_permanently
}
I'm not sure how you've set up SSL on your server. Are you terminating SSL in a load balancer, for example? Whatever you're doing, it seems like SSL is the culprit. To confirm temporarily try:
# config/production.rb
config.force_ssl = false
and see if that solves it.
Glad you figured it out! Posting my last comment as an answer below.
Thanks for the live example. So, I click on the submit button and I can see the browser sending a POST request. The server responds successfully, but with a redirect.
POST https://win-marketing.sciencesupercrew.com/en/users/login -> 301 Moved Permanently with Location: https://win-marketing.sciencesupercrew.com/en/users/login/. The form data are sent correctly as user[email] and user[password].
If you say that this request does not reach Rails, then you need to check your nginx configuration.
UPDATED SOLUTION
The issue was my nginx configuration. The one that works is the following:
server {
listen 80;
server_name win-marketing.sciencesupercrew.com www.win-marketing.sciencesupercrew.com;
return 301 https://www.win-marketing.sciencesupercrew.com$request_uri;
}
server {
listen 443 ssl;
server_name win-marketing.sciencesupercrew.com;
passenger_enabled on;
rails_env production;
root /home/demo/windhagermediahub/public;
ssl on;
ssl_certificate /home/demo/ssl/ssl-bundle.crt;
ssl_certificate_key /home/demo/ssl/ssc.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
After adding these lines it started working:
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
The first thing I notice is that you have two GETs, instead of a GET and then a POST (as you noticed yourself).
But let's assume the HTML form is correct, since it works in development. That makes me suspect there is some Javascript that is throwing things off. One common problem when moving things from development to production is the Asset Pipeline. So I would open your browser's console, refresh the page, and see if you get any Javascript errors, especially about files failing to load.
You should also share how you are including Javascript files. Can you share that part of your layout (or whatever)? I would make sure that you use asset_path and friends, and not just /assets/application.js, because the latter will break when you go to production. Even better, use javascript_include_tag.
I am no expert but since your code is working on local just try the following to get an idea where the problem might be:
a) Run production environment on your local, see if the problem persists there.
b) Try to test run without any javascript enabled or atleast disable custom ones on the production server.
c) Try to redirect after devise authentication to an existing/static page.
I am sure you will get some hints or ideas

Vagrant: Passing docker run arguments to multiple containers using vagrant

I'm using vagrant to deploy a multiple VM environment, for research purposes, and it was great so far. But now i need to pin each docker container to a specific CPU core, but i don't know how to do that using vagrant. I know i can use the "args" clause on the Vagrantfile to pass the "--cpuset" parameter to the docker run command, but i don't know how to use it in a loop, since i'm launching multiple containers and i need to pin each container to a different CPU core (eg. node1 pins to core #0, node2 pins to core #1, etc).
My current Vagrantfile is as follows, without the CPU Pinning thing:
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
# choose how many machines the cluster will contain
N_VMS = 32
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "tknerr/baseimage-ubuntu-14.04"
config.vm.network "private_network", ip: "192.168.121.2"
config.vm.provider "docker" do |v|
v.has_ssh = true
end
hosts_file = []
1.upto(N_VMS) do |i|
config.vm.define vm_name = "node#{i}" do |config|
config.vm.hostname = vm_name
end
end
script = <<-SCRIPT
apt-get -y update
apt-get -y install libcr-dev mpich2 mpich2-doc arp-scan openssh-server nano make
SCRIPT
script.sub! 'N_VMS', N_VMS.to_s
config.vm.provision "shell", inline: script
end
In the end, i was looking in the wrong place. The correct spot to add the "--cpuset-cpus" was in the config.vm.define block.
The code ended being like this:
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
# choose how many machines the cluster will contain
N_VMS = 32
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "tknerr/baseimage-ubuntu-14.04"
config.vm.network "private_network", ip: "192.168.121.2"
config.vm.provider "docker" do |v|
v.has_ssh = true
end
2.upto(N_VMS+1) do |i|
config.vm.define vm_name = "node#{i}" do |config|
# CPU PINNING CONFIG
config.vm.provider "docker" do |docker|
docker.create_args = ['--cpuset-cpus=' + ((i/2)-1).to_s]
end
config.vm.hostname = vm_name
end
end
script = <<-SCRIPT
apt-get -y update
apt-get -y install libcr-dev mpich2 mpich2-doc arp-scan openssh-server nano make
SCRIPT
script.sub! 'N_VMS', N_VMS.to_s
i=1
config.vm.provision "shell", inline: script
end
Suppose you want to config the vagrant vm in the loop, as the vagrantfile is based on the ruby language, so you can involve the development availablty to the vagrantfile, here is an example, you can add your "--cpuset" config in the vm define.
# -*- mode: ruby -*-
# vi: set ft=ruby :
# read vm and chef configurations from JSON files
nodes_config = (JSON.parse(File.read("nodes.json")))['nodes']
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
nodes_config.each do |node|
node_name = node[0] # name of node
node_values = node[1] # content of node
# puts node_name
# puts node_values['box']
config.vm.define node_name do |config|
config.vm.box = node_values['box']
config.vm.hostname = node_name
config.vm.network :private_network, ip: node_values['ip']
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", node_values['memory']]
vb.customize ["modifyvm", :id, "--name", node_name]
end
end
end
nodes.json to define the vm, you can define your
{
"nodes": {
"jenkins.example.com": {
"info": "jenkins master server",
"box": "../Vgrant-boxes/centos65_virtualbox_50G.box",
"ip": "192.168.35.101",
"ports": [],
"memory": 512
},
"node01.example.com": {
"info": "tomcat app host server",
"box": "../Vgrant-boxes/centos65_virtualbox_50G.box",
"ip": "192.168.35.121",
"ports": [],
"memory": 512
},
"node02.example.com": {
"info": "jboss app host server",
"box": "../Vgrant-boxes/centos65_virtualbox_50G.box",
"ip": "192.168.35.122",
"ports": [],
"memory": 512
},
"node03.example.com": {
"info": "oracle xe server",
"box": "../Vgrant-boxes/centos65_virtualbox_50G.box",
"ip": "192.168.35.123",
"ports": [],
"memory": 512
},
"node04.example.com": {
"info": "artifactory server",
"box": "../Vgrant-boxes/centos65_virtualbox_50G.box",
"ip": "192.168.35.124",
"ports": [],
"memory": 512
}
}
}

Unable to load rspec configuration

When trying to run rspec spec/controllers/api_controller_spec.rb:406 --color command on linux machine. We already have redis server running at port 6379 but as below error Unable to load rspec spec_helper configuration & getting error:
Code:
REDIS_PID = "/var/run/redis.pid"
REDIS_CACHE_PATH = "tmp/cache/"
Dir.mkdir "#{Rails.root}/tmp" unless Dir.exists? "#{Rails.root}/tmp"
Dir.mkdir "#{Rails.root}/tmp/pids" unless Dir.exists? "#{Rails.root}/tmp/pids"
Dir.mkdir "#{Rails.root}/tmp/cache" unless Dir.exists? "#{Rails.root}/tmp/cache"
config.before(:suite) do
redis_options = {
"daemonize" => 'yes',
"pidfile" => 7528,
"port" => 6379,
"timeout" => 300,
"save 900" => 1,
"save 300" => 1,
"save 60" => 10000,
"dbfilename" => "dump.rdb",
"dir" => REDIS_CACHE_PATH,
"loglevel" => "debug",
"logfile" => "stdout",
"databases" => 16
}.map { |k, v| "#{k} #{v}" }.join("\n")
`echo '#{redis_options}' | redis-server -`
end
config.after(:suite) do
%x{
cat #{REDIS_PID} | xargs kill -QUIT
rm -f #{REDIS_CACHE_PATH}dump.rdb
}
end
Error:
------------
------------
------------
Finished searching in 0.09762763977050781 seconds.
Request#<ActionController::TestRequest:0x00000004139f58>
^[[?1;2c^[[?1;2c^[[?1;2c^[[?1;2c^[[?1;2c^[[?1;2cFcat: /var/run/redis.pid: No such file or directory
usage: kill [ -s signal | -p ] [ -a ] pid ...
kill -l [ signal ]
------------
------------
------------
Restart the redis server redis-server stop/start. The redis.pid file generated and rspec is able to access the redis configuration during background processing.

Elixir exrm release crashes on eredis start_link

I'm fairly new to Elixir and this is the first app that I'm attempting to release using exrm. My app interacts with a Redis database for consuming jobs from a queue (using exq), and also stores results of processed jobs in Redis using eredis.
My app works perfectly when I run it via iex -S mix, and it also runs great when compiled into an escript. However when I use exrm, the application compiles without any issue, but it crashes when I run it.
This is the crash output:
$ ./rel/my_app/bin/my_app console
{"Kernel pid terminated",application_controller,"{application_start_failure,my_app,{bad_return,{{'Elixir.MyApp',start,[normal,[]]},{'EXIT',{{badmatch,{error,{{'EXIT',{{badmatch,{error,{undef,[{eredis,start_link,[],[]},{'Elixir.MyApp.Cache',init,1,[{file,\"lib/my_app/cache.ex\"},{line,8}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,306}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,237}]}]}}},[{'Elixir.MyApp.Cache',start_link,1,[{file,\"lib/my_app/cache.ex\"},{line,21}]},{supervisor,do_start_child,2,[{file,\"supervisor.erl\"},{line,314}]},{supervisor,handle_start_child,2,[{file,\"supervisor.erl\"},{line,685}]},{supervisor,handle_call,3,[{file,\"supervisor.erl\"},{line,394}]},{gen_server,try_handle_call,4,[{file,\"gen_server.erl\"},{line,607}]},{gen_server,handle_msg,5,[{file,\"gen_server.erl\"},{line,639}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,237}]}]}},{child,undefined,'Elixir.MyApp.Cache',{'Elixir.MyApp.Cache',start_link,[[{host,\"127.0.0.1\"},{port,6379},{database,0},{password,[]},{reconnect_timeout,100},{namespace,<<>>},{queues,[<<\"elixir\">>]}]]},permanent,5000,worker,['Elixir.MyApp.Cache']}}}},[{'Elixir.MyApp.Supervisor',start_cache,1,[{file,\"lib/my_app/supervisor.ex\"},{line,17}]},{'Elixir.MyApp.Supervisor',start_link,0,[{file,\"lib/my_app/supervisor.ex\"},{line,9}]},{'Elixir.MyApp',start,2,[{file,\"lib/my_app.ex\"},{line,10}]},{application_master,start_it_old,4,[{file,\"application_master.erl\"},{line,272}]}]}}}}}"}
Here is the mix.exs for my application:
defmodule MyApp.Mixfile do
use Mix.Project
def project do
[
app: :my_app,
version: "0.0.1",
name: "MyApp",
elixir: "~> 1.0",
escript: escript_config,
deps: deps
]
end
def application do
[
applications: app_list(Mix.env),
mod: { MyApp, [] },
env: [ queue: 'elixir']
]
end
def included_applications do
[ :logger, :httpoison, :eredis, :exq, :dotenv, :exjsx, :ex_doc, :oauth2, :sweet_xml ]
end
defp app_list(:dev), do: [:dotenv | app_list]
defp app_list(_), do: app_list
defp app_list, do: [:logger, :httpoison]
def escript_config do
[ main_module: MyApp ]
end
defp deps do
[
{ :dotenv, github: "avdi/dotenv_elixir" },
{ :eredis, github: "wooga/eredis", tag: "v1.0.5" },
{ :exjsx, "~> 3.1.0" },
{ :exq, "~> 0.1.0", app: false },
{ :exrm, "~> 0.16.0" },
{ :ex_doc, github: "elixir-lang/ex_doc" },
{ :httpoison, "~> 0.4" },
{ :oauth2, "~> 0.1.1" },
{ :sweet_xml, "~> 0.2.1" }
]
end
end
The crash appears to be happening in the following init function, where I call :eredis.start_link:
defmodule MyApp.Cache do
use GenServer
require Logger
def init(client_opts) do
{ :ok, client } = :eredis.start_link(
client_opts[:host],
client_opts[:port],
client_opts[:database],
client_opts[:password],
client_opts[:reconnect_timeout])
end
end
Could it be because eredis is an Erlang library as opposed to Elixir?
You need to add :eredis to your app_list function, so that it is packaged with the release, that goes for the rest of your dependencies as well.

Resources