I'm running Ubuntu 10.04 with Rails 3.2.2.
I just installed and configured sendmail. When mail is sent through terminal it worked perfectly.
But when i try to call it through Rails, no success.
Although it doesn't really looks like it's failing though. I get no errors, and see this in my console:
#<Mail::Message:40338240, Multipart: false, Headers: <From: alert#email.com>, <To: chris#email.com>, <Subject: Hi chris, a testmail too you!>, <Mime-Version: 1.0>, <Content-Type: text/html>, <importance: High>, <X-Priority: 1>>
I am in development have the following settings in my development.rb:
config.action_mailer.delivery_method = :sendmail
config.action_mailer.sendmail_settings = {
:location => '/usr/sbin/sendmail',
:arguments => '-i -t'
}
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
I have setup an actionmailer, with the corresponding alert_mail.html.erb:
class UserMailer < ActionMailer::Base
default from: "alert#email.com"
def alert_mail(site)
#site = site
#user = site.user
#url = "http://example.com/login"
mail(:to => #user.email_address, :subject => "Hi chris, a testmail too you!", :importance => "High", 'X-Priority' => '1')
end
end
And this is what I call:
UserMailer.alert_mail(site)
Could it be something with permissions?
Things i've tried
- Tried running in production mode
- chmod'd the sendmail executables to 777
- Tried removing the priority settings
- Running it with rails server instead of nginx
I hope someone can help me, thanks in advance!
(email.com is just a replacement, i use a valid domain)
EDIT:
sadiqxs answer does indeed solve the problem when I try to execute the mail function through rails console. But it still doesn't work when it is supposed to, through my browser. Strange thing is, this seems to be happening in nginx only. When I stop nginx, and start rails server, then it works. But when I when nginx is the server, it doesnt send any mail.
I think you need to call
UserMailer.alert_mail(site).deliver
sadiqxs solution is the part of the answer to my question. It fixes the problem that I was calling the function wrong. But it was still not sending email for me. After a while i manage to get it working.
One of the things I found out is that there was actually another mail log which I did oversee:
/var/log/mail.log.1
It showed me the following error:
sendmail[4453]: NOQUEUE: SYSERR(nobody): can not chdir(/var/spool/mqueue-client/): Permission denied
I used ls -ld /var/spool/mqueue-client/ to see that the directory is restricted by the smmsp group:
drwxrws--- 2 smmsp smmsp 4096 2013-01-12 17:51 /var/spool/mqueue-client/
So I added the nobody user (from the error SYSERR(nobody)) to the smmsp group:
usermod -a -G smmsp nobody
I tested again, and it doesn't work yet. After checking the log I got the same error. To be sure I rebooted my server and now the error message changed a little bit:
NOQUEUE: SYSERR(nobody): can not write to queue directory /var/spool/mqueue-client/ (RunAsGid=65534, required=115): Permission denied
After searching and trying useless stuff for a while i decide to change the primary group of nobody to 115 (smmsp) the /etc/psswd file and saw the following settings:
nobody:x:65534:65534:nobody:/nonexistent:/bin/sh
to
nobody:x:65534:115:nobody:/nonexistent:/bin/sh
This solved my problem and it's sending mails now. I understand that this is not the best solution, but I don't really know how else I would give nobody access, since it's requiring the specific GID. I hope someone else here does.
Related
I am trying to connect to the XMLRPC API of a dokuwiki website.
I am successfully doing that from my own laptop, with a SSL connection, however, when I try to do it from my production server (which hosts both the wiki and the rails app from which the ruby code is executed), I run into a
Runtime Error
Wrong size. Was 163, should be 113
Here's how I initialize the connection :
#wiki = ::XMLRPC::Client.new3(
host: "wiki.example.com",
path: "/lib/exe/xmlrpc.php",
use_ssl: true)
# Temp Hack because SSL Fails
#wiki.instance_variable_get(:#http).instance_variable_set(:#verify_mode, OpenSSL::SSL::VERIFY_NONE)
end
#authenticated = false
authenticate!
end
def authenticate!
# Fails at below line :
#authenticated = #wiki.call("dokuwiki.login", ENV['WIKI_USER'], ENV['WIKI_PASSWORD'])
Rails.logger.info (#authenticated ? "Authenticated on Wiki !" : "Authentication failed on wiki !")
end
I've read many posts saying that there is a bug in the XMLRPC lib of Ruby. I was running ruby 2.1.5pxx on my laptop and ruby 1.9.xx at my server so I did a rvm install 2.1.5, yet the problem is still here
(btw, I assumed it was enough to do a rvm use 2.1.5 and then touch restart to restart my rails server, but how can I check which version of ruby it's using ?)
What is wrong ?
EDIT
On my laptop, I am running ruby 2.1.5p273 (2014-11-13 revision 48405) [x64-mingw32]
On my production server, I am running ruby-2.1.5 [ i686 ]
I tried another library, libxml-xmlrpc, and I get the following error when running the same command:
Net::HTTPBadResponse: wrong status line: "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">"
But again, the same code is running fine with the default ruby xmlrpc client on my Windows + rubyx64 2.1.5, so I really don't get it!
Edit2 : I tried adding
#wiki.http_header_extra = { "accept-encoding" => "identity" }
But then I get a
Authorization failed. HTTP-Error: 401 Unauthorized
The first call #wiki.call("dokuwiki.login", "myUsr", "myPwd") worked, but apparently it failed to authenticate me (Of course I am still using the same login information that should work)
EDIT 3
After investigation, a successful login from any other computer than localhost will set a cookie like
#cookie="DokuWiki=[small string] ; [very big string]
Whereas if I do it on localhost :
I will write [...] for random strings
#cookie="[small string 2]=deleted; DokuWiki=[small string]; [very big string]"
So I have an extra variable info stored in my cookie, which is "[small string 2]=deleted;
I believe this is what makes my authentication fails. Anyone knows what this is ???
So this localhost connection was messing up with the cookie. Apparently, even the ruby library doesn't know why, and the "Wrong size" comes from this unexpected string [random string]=deleted added at the beginning of the cookie.
Unless someone can explain WHY such a string is added, I will accept my solution of simply adding
#wiki.http_header_extra = { "accept-encoding" => "identity" }
which removes the "Wrong size" error, then
if /deleted/.match(#wiki.cookie)
#wiki.cookie = #wiki.cookie.gsub(/.*deleted; /, '')
end
To remove the beginning of the cookie
I've tried various solutions that are intuitive and then have tried the solutions that have apparently helped others. I've spun up and terminated my Rails 4 app about 10 times. So...I thought I'd turn here to see if anyone knew an answer.
Here is the log file:
[ 2015-03-06 06:12:27.0070 2619/7fa0f6d60740 agents/Watchdog/Main.cpp:538 ]:
Options: { 'analytics_log_user' => 'webapp', 'cleanup_pidfiles' =>
'L3RtcC9wYXNzZW5nZX*********************yL3RlbXBfZGlyX3RvdWNoZXIucGlk',
'default_group' => 'webapp', 'default_python' => 'python', 'default_ruby' =>
'/opt/rubies/ruby-2.1.5/bin/ruby', 'default_user' => 'webapp', 'log_level' =>
'0', 'max_pool_size' => '6', 'passenger_root' => '/tmp/passenger-
standalone.1fcb7jr/locations.ini', 'passenger_version' => '4.0.53',
'pool_idle_time' => '300', 'prestart_urls' => 'aHR0cDovLzAuMC4wLjA6ODAA',
'temp_dir' => '/tmp', 'union_station_gateway_address' =>
'gateway.unionstationapp.com', 'union_station_gateway_port' => '443',
'user_switching' => 'false', 'web_server_passenger_version' => '4.0.53',
'web_server_pid' => '2618', 'web_server_type' => 'nginx',
'web_server_worker_gid' => '496', 'web_server_worker_uid' => '497' }
[ 2015-03-06 06:12:27.3877 2622/7fac802f6740 agents/HelperAgent/Main.cpp:650]:
PassengerHelperAgent online, listening at
unix:/tmp/passenger.1.0.2618/generation-0/request
[ 2015-03-06 06:12:28.2222 2630/7fe1e0b67740 agents/LoggingAgent/Main.cpp:321
]: PassengerLoggingAgent online, listening at
unix:/tmp/passenger.1.0.2618/generation-0/logging
[ 2015-03-06 06:12:28.2223 2619/7fa0f6d60740 agents/Watchdog/Main.cpp:728 ]:
All Phusion Passenger agents started!
2015/03/06 06:12:29 [error] 2638#0: *3 "/var/app/current/public/index.html" is
not found (2: No such file or directory), client: 127.0.0.1, server: _,
request: "HEAD / HTTP/1.1", host: "0.0.0.0"
2015/03/06 06:13:35 [error] 2638#0: *7 "/var/app/current/public/index.html" is
not found (2: No such file or directory), client: 172.3*.**.***, server: _,
request: "GET / HTTP/1.1", host: "****************-env.elasticbeanstalk.com"
I have gem 'passenger' in my gem file...I have tried in both development (because I've seen a number of errors with production and passenger) and production and I swear I have never had this kind of trouble uploading to elastic beanstalk. In fact this is a very stripped down app with only a static page and both devise for a user and devise for active admin. No errors or problem in either environment on my local machine.
I've never even realized I needed the index.html file...I always assumed that was only in php and other languages and that Rails took care of that for you with root. And like I said I've never seen this problem before. So to test that I put in an index.html file in the public folder and I could see that ahead of my root route on my local machine, but still no dice in AWS. I'd prefer to be able to drop this in and one of the other configs like just Puma. And I see a Puma and Nginx config available, but not in the GUI which is what I was planning to just "drop" this in and be done with it for the time being. I'm using a t2.small instance.
Any help or direction would be greatly appreciated. Thanks.
UPDATE: I've now tried this pushing through Git using Puma...etc. Trouble everywhere. It makes no sense. I even moved it to a "Hello World" app and still nothing. I'm about done with AWS. This is ridiculous. Nearly worse than an iOS release that has massive problems every year.
Ok. After today I have gotten this taken care of and hosted properly. In case this helps someone out...here were the key takeaways:
1) There is a Puma option if you are using CLI that is obvious. There is ALSO an option in the GUI, however it reads like a sentence instead of a logical select box. It DOES exist on the front page underneath the selection of the language to be installed. If you are getting a Passenger Error and expect to be using Puma, this is something you need to change.
2) I had installed a User model that contained an ActiveAdmin role as well. ActiveAdmin was pulling the gem from GitHub and I am using a machine with GitHub installed already. This really was the problem...switching to production and onto ElasticBeanstalk I forgot that git wasn't already installed. After going back through the errors many times, the common error was
# :github => 'activeadmin/activeadmin'+ '[' -d /vendor/cache ']'
+ bundle install
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
You need to install git to be able to use gems from git repositories.
[CMD-Startup/StartupStage0/AppDeployPreHook/10_bundle_install.sh] : Activity failed.
This is located in the eb-activity.log.
So, if this is similar to anything happening to you, you can do as follows:
1) start up your instance with the correct server.
2) if you get an error, look through that activity log mentioned above. (All the logs for that matter)
3) If the error fails similarly there is NO NEED to delete the instance. Leave it running.
4) SSH into the server instance that you just created. Run
sudo yum update
that is more than likely recommended. And then run
sudo yum install git
5) Upload the same exact file and name the version 0.1 and when it's through it should be green if this was your only error. Click the link and Voila.
For the git binary problem: It will fail again, if more instances are spinning up. You can avoid that by adding a config under $ROOT/.ebextensions which will be used for any new instance.
# Install git in order to be able to bundle gems from git
packages:
yum:
git: []
I'm trying to make X-Sendfile work for serving my heavy attachments with capistrano. I found that X-Sendfile is not working with symlinks. How could I handle the files inside a folder symlinked by Capistrano so?
my web server is apache2 + passenger
in my production.rb:
config.action_dispatch.x_sendfile_header = "X-Sendfile"
in my controller action:
filename = File.join([Rails.root, "private/videos", #lesson.link_video1 + ".mp4"])
response.headers["X-Sendfile"]= filename
send_file filename, :disposition => :inline, :stream => true, :x_sendfile => true
render nothing: true
my filesystem structure (where a "->" stands for "symlink" and indentation means subfolder):
/var/www/myproject
releases/
....
current/ -> /var/www/myproject/releases/xxxxxxxxxxxx
app/
public/
private/
videos/ -> /home/ftp_user/videos
my apache config
XSendFile on
XSendFilePath / #also tried /home/ftp_user/videos
My application is able to serve small files, but with big ones it gives a NoMemoryError(failed to allocate memory)
I think it's not using x-sendfile, because the behavior is the same if I don't use it.
Here are the response headers of the file i'm trying to serve
Accept-Ranges:bytes
Cache-Control:private
Connection:Keep-Alive
Content-Disposition:inline
Content-Range:bytes 0-1265/980720989
Content-Transfer-Encoding:binary
Content-Type:video/mp4
Date:Sat, 01 Mar 2014 13:24:19 GMT
ETag:"70b7da582d090774f6e42d4e44ae3ba5"
Keep-Alive:timeout=5, max=97
Server:Apache/2.4.6 (Ubuntu)
Status:200 OK
Transfer-Encoding:chunked
X-Content-Type-Options:nosniff
X-Frame-Options:SAMEORIGIN
X-Powered-By:Phusion Passenger 4.0.37
X-Request-Id:22ff0a30-c2fa-43fe-87c6-b9a5e7da12f2
X-Runtime:0.008150
X-UA-Compatible:chrome=1
X-XSS-Protection:1; mode=block
I really don't know how to debug it, if it's a x-sendfile issue or if I'm trying to do something impossible for the symlinks problem
EDIT:
Following the suggested answer in the accepted one, it "magically" started working!
I created a capistrano task this way:
task :storage_links do
on roles(:web), in: :sequence, wait: 2 do
#creo i link simbolici alle risorse
within "/var/www/my_application/current/private" do
execute :ln, "-nFs", "/home/ftp_user/videos"
end
end
end
I didn't manage to run it after finalize_update, so i run it after the restart, by hand.
And i corrected my apache configuration in this way:
XSendFilePath /var/www/my_application
(before i was pointing x-sendfile to the ftp folder)
In my response headers also now X-Sendfile is not appearing, and i got a 206 - partial content, but everything seems to work and apache is serving files in the right way (also very heavy files).
I know this can be a security issue, but i will try to point it to the last release of my application cause pointing it to the current symlink is not working.
Maybe I found a solution. How did you make your symlinks?
maybe you did ln -s, and it's not enough
Here they suggest using ln -nFs, so he recognizes it's a directory that you are linking in
I would like to connect to a remote computer via another using ruby.
This scheme is the following :
Local -> proxy -> remote
I have this code which is doing the work for a direct access :
require 'net/ssh'
Net::SSH.start(remote_host, remote_user) do |ssh|
puts ssh.exec!'hostname'
end
However, when I try with the proxy, the command 'hostname' is executed and correct, but then the code freezes, same if I call ssh.close.
Here is the code :
require 'net/ssh'
require 'net/ssh/proxy/command'
proxy_cmd = Net::SSH::Proxy::Command.new('ssh proxy_user#proxy_host nc %h %p')
Net::SSH.start(remote_host, remote_user, :proxy => proxy) do |ssh|
puts ssh.exec!'hostname'
end
The loggin is done without password thanks to a rsa key. And the proxycommand is working (I was using it in bash before)
Would someone knows what I am doing wrong ?
Thank you very much for your interest,
EDIT : here is the last line in the logs, it blocks there :
I, [2013-10-16T23:01:19.304778 #3785] INFO -- net.ssh.connection.session[4555128]: closing remaining channels (0 open)
I've just bumped in the same issue - command line ssh was working and net/ssh was hanging on me when using proxycommand.
Debuging net/ssh brought me as far as: https://github.com/net-ssh/net-ssh/blob/master/lib/net/ssh/transport/session.rb#L113 and the whole thing was hanging on the .close call of the socket.
I'm not sure what caused this, but adding timeout to nc command seems to have solved it:
ProxyCommand ssh proxy_server#proxy_server nc -q 1 %h %p
I am using rails 2.3.8. I am trying to send mail through action mailer. When i call the mailer function it does not throw any error and completes successfully even the log shows that the mail is sent. But when i check the mail box there is not mail sent actually Is there any problem with sendmail configuration or something else. Please help me out with it.
Thanks
Here are my setting in development.rb
config.action_mailer.raise_delivery_errors = false
ActionMailer::Base.delivery_method = :sendmail
ActionMailer::Base.sendmail_settings = {
:location => "path/to/sendmail",
:arguments => "-i"
}
if
config.action_mailer.perform_deliveries = true
dont work
maybe a sendmail misconfiguration , try to send a mail from bash and check the output
touch file.log;
cat - file.log << EOF | sendmail -t
to:email#address.com
from:you#address.com
subject:Testing 123
TEST
EOF
otherwise
I find useful to use this program (a fake smtp server) to test outgoing mail
http://www.aboutmyip.com/AboutMyXApp/DevNullSmtp.jsp
add this to your development.rb file
config.action_mailer.perform_deliveries = true
because i don't see it in your configuration