Supervisord launches with wrong setuid

supervisorduwsgi

I am trying to test a pilot system with nginx connecting to uwsgi served application controlled by supervisord running on ubuntu-server. Application is written in python with Flask in virtualenv, although I'm not sure if that is relevant. To test the system I have created a simple hello world with flask. I want nginx and uwsgi both to run as www-data user.
If I launch uwsgi "manually" from root shell I can see uwsgi processes runing as appropriate user (www-data). Although, if I let supervisor launch the application something strange happens – uwsgi processes are runing under my user (friendzis). Consequently, socket file gets created under wrong user and nginx cannot communicate with my applicaion.
note: the linux server runs as Hyper-V VM, under Windows Server 2008.

Relevant configuration:

[uwsgi]

socket = /var/www/sockets/cowsay.sock
chmod-socket = 666
abstract-socket = false

master = true
workers = 2

uid = www-data
gid = www-data

chdir = /var/www/cowsay/cowsay
pp = /var/www/cowsay/cowsay
pyhome = /var/www/cowsay
module = cowsay
callable = app

supervisor

[program:cowsay]
command = /var/www/cowsay/bin/uwsgi -s /var/www/sockets/cowsay.sock -w cowsay:app
directory = /var/www/cowsay/cowsay
user = www-data
autostart = true
autorestart = true
stdout_logfile = /var/www/cowsay/log/supervisor.log
redirect_stderr = true
stopsignal = QUIT

I'm sure I'm missing some minor detail, but I'm unable to notice it. Would appreciate any suggestions.

Best Answer

You should specify an environment option in the program section. For example:

user=chrism
environment=HOME="/home/chrism",USER="chrism"

See Subprocess Environment for details.

Also, a similar solution is proposed on stackoverflow