We are running the Postfix mail transit program. We've specified that when an incoming email comes in, to send it to a Ruby script.
The commands in postfix are:
flags=Xhq user=vmail argv=/usr/local/rvm/rubies/ruby-2.1.1/bin/ruby /home/usera/rails/project/lib/email_receiver_script
When we receive an email, the mail.log has an error in it saying:
Apr 6 20:02:48 railsdev postfix/pipe[25961]: B447A282D01: to=<rr@myapp.com>, relay=send_to_ruby_filter, delay=0.06, delays=0.01/0/0/0.05, dsn=5.3.0, status=bounced (Command died with status 1: "/usr/local/rvm/rubies/ruby-2.1.1/bin/ruby". Command output: /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- mail (LoadError) from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /home/usera/rails/project/lib/email_receiver_script:4:in `<main>' )
However the command runs just fine using the command line. If I take email.txt and pipe it to the same command the mail gets delivered to the script properly. Like so:
cat email.txt | /usr/local/rvm/rubies/ruby-2.1.1/bin/ruby /home/usera /rails/project/lib/email_receiver_script
The first few lines of our script are:
#!/usr/bin/env ruby
require 'rubygems'
require 'mail'
require 'redis'
require 'resque'
RVM was used as root to install Ruby globally.
It seems like the postfix user 'vmail' cannot find the Rubygems installed. Any ideas how we can make it execute the script properly?