Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

supervisord refuses to run command as user (always runs as root)

For some reason, supervisor refuses to start the command as user - it always runs it as root - and this is an issue for me since I am activating a virtualenv and running commands specific to that particulat virtualenv.

So, my conf looks like so:

[program:site]

command = /home/some/virtual/env/dir/run/start.sh
user = some
stdout_logfile = /home/some/etc/supervisor/logs/logging.log
redirect_stderr = true
environment=LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8
stopsignal=KILL
killasgroup=true
autostart=true

start.sh looks like so:

#!/bin/bash
echo $USER >> /home/some/user.txt
cd
source /home/foo/some/virtual/env/bin/activate
cd /home/foo/some/virtual/env
SOCKFILE01=/home/some/etc/supervisor/site.sock
exec /home/some/virtual/env/bin/gunicorn -b unix:$SOCKFILE01  site.wsgi:application -w 2 -k gevent --worker-connections=2000 
exit 0

when I inspect the log, I see:

start.sh: line 2: cd: /root: Permission denied

which means this is still running as root.

I am totally baffled by this. I start supervisor as root. The even weirder part is that the above code works totally fine on my local machine, but shows me the above log on a server.

I have run out of ideas... :((

EDIT:

added echo to the .sh script and user.txt spits out:

root

..totally puzzled!

like image 877
JohnJ Avatar asked Sep 03 '25 09:09

JohnJ


1 Answers

You need to set the environment variables as below and update the command:

[program:site]

command=bash -c "/home/some/virtual/env/dir/run/start.sh"
user=some
stdout_logfile=/home/some/etc/supervisor/logs/logging.log
redirect_stderr=true
environment=LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8,HOME="/home/some",USER="some"
stopsignal=KILL
killasgroup=true
autostart=true

This is described in http://supervisord.org/subprocess.html#subprocess-environment and solved this issue for me when trying to run npm scripts.

like image 127
Will Avatar answered Sep 04 '25 21:09

Will