1

I have a webapp (nginx, gunicorn, python) that receives git post hooks and triggers a command line tool (ruby, capistrano). Everything is run via a user named deployer. The command line tool runs very well and can connect via ssh to remote servers.

When the webapp triggers it, it can't connect via ssh. A password is required. I think I know how to circumvent it (i had a similar problem with cronjobs here: Server gets killed due to increasing number of ssh-agent processes) but somehow the user is empty in the webabb.

Given this script:

#!/bin/bash
echo "$(whoami)"

When I run deployer@tools:/srv/deployment$ ./test > test.txt then test.txt contains "deployer" and the file test.txt is owned by deployer:deployer.

When I run the very same command from within my webapp then test.txt is empty (only containing a line break) but owned by deployer:www-data (as expected and configured in gunicorn).

How is that even possible and what may I do about that?

  • 2
    But.. why are you running echo $(whoami) instead of just whoami? And when you say you ran the very same command from the app, how did you do that? – muru Oct 11 '15 at 14:33
  • whoami brings the same result (without the linebreak, just an empty file and i run it with os.system('cd /srv/deployment && ./test > test.txt') from within the python app. – shredding Oct 11 '15 at 14:35
  • What if you run os.system('whoami > test.txt'), or use id -u instead of whoami, or use echo $USER? – muru Oct 11 '15 at 14:37
  • Interestingly whoami pure returns 127 instead of 0 as return code. – shredding Oct 11 '15 at 14:39
  • 2
    What's the PATH in your webapp? What if you give full path to whoami (/usr/bin/whoami, IIRC)? – muru Oct 11 '15 at 14:40
1

So the problem turned out to be a different path setting.

Gunicorn was using the python virtualenv as PATH and therefore did not know whoami at all. Pushing in absolute path worked!

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.