Question

I'm trying to get Rails 4.1 to receive bounceback emails but it's been really difficult to even get to this point. I can run the command below in an SSH console when logged in as root, but when I put it in my /etc/valiases file, I get a bounceback from the script saying "the following addresses failed".

runuser -l useraccount -c "cd /home/useraccount/rails_deployments/dev.www/current/bin && rails runner -e development 'EBlast.receive(STDIN.read)'"

/etc/valiases/dev.mydomain.com

eblast-bounce@dev.mydomain.com: "|runuser -l useraccount -c "cd /home/useraccount/rails_deployments/dev.www/current/bin && rails runner -e development 'EBlast.receive(STDIN.read)'""

I've also tried escaping the double-quotes to no avail.

I need to run as useraccount because the RVM environment variables don't exist for root. Running the 1st command in an SSH console when logged in as root works, but not when exim receives an email.

Was it helpful?

Solution 2

There are a few things I had to do to work around the problem:

1) Move the runner script into its own file as Todd suggested; nested quotes were causing the script to fail to run.

2) Make the file executable; the permissions were already set to 755.

3) Even though exim was using my username to execute the script, the environment variables such as PATH and HOME were not set at all! This caused ruby to be an unknown command. This caused many other issues because most of the app relies upon RVM and its gemsets. So I couldn't get ruby to run, much less rails. Even if I were to explicitly call the ruby wrapper, spring would break because $HOME wasn't set. Just a cascade of issues because the user environment wasn't being set. I also couldn't just issue su - username -c 'whatever' because the account that exim was using didn't have authority to use su.


So the working setup looks like this:

/etc/valiases/dev.mydomain.com

eblast-bounce@dev.mydomain.com: "|/bin/bash -l -c '/home/useraccount/rails_deployments/dev.www/current/script/receive_eblast_bounce'"
*: ":fail: No Such User Here"

/home/useraccount/rails_deployments/dev.www/current/script/receive_eblast_bounce

D=`pwd`

HOME=/home/useraccount

if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

if [[ -s "/home/useraccount/.rvm/scripts/rvm" ]] ; then
  source "/home/useraccount/.rvm/scripts/rvm"
fi

cd /home/useraccount/rails_deployments/dev.www/current
./bin/rails runner -e development 'EBlast.receive(STDIN.read)'

cd $D

I'm now having problems with ActionMailer using SSL when it shouldn't, and I don't know if that's related to something I did here, but at least it executes the rails script.

OTHER TIPS

You can't doublequote inside of doublequotes without doing some escaping. Once you start escaping quotes, it can get complicated knowing when you also need to escape other characters as well. Your example doesn't appear to get too complicated, but I suggest a different method.

IMHO you should create a shell script, for example eblast-bounce-script, with the piped commands you want to run. Then set your alias to:

eblast-bounce@dev.mydomain.com: "|/path/to/eblast-bounce-script"

Make sure the make the script executable, and runnable by the user that exim will be calling it as. If you make the script mode 755, owned by root, that should be sufficient.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top