Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Supervisor and Environment Variables

I really don't know how to get supervisor to work with environment variables.

Below is a configuration snippet.

[program:htNotificationService] priority=2 #autostart=true #autorestart=true directory=/home/ubuntu/workspace/htFrontEnd/heythat/htsite command = /usr/bin/python htNotificationService.py -service stdout_logfile=/var/log/heythat/htNotificationService.log redirect_stderr=true environment=PATH=/home/ubuntu/workspace/htFrontEnd/heythat stopsignal=QUIT 

I have tried the following:

environment=PATH=/home/ubuntu/workspace/htFrontEnd/heythat environment=PYTHONPATH=$PYTHONPATH:/home/ubuntu/workspace/htFrontEnd/heythat environment=PATH=/home/ubuntu/workspace/htFrontEnd/heythat,PYTHONPATH=$PYTHONPATH:/home/ubuntu/workspace/htFrontEnd/heythat 

When I start supervisor I get

htNotificationService: ERROR (abnormal termination) 

I can start from the shell by setting the python path, but not from supervisor. In the logs I get an error that says that an import can't be found. Well, that would be solved if supervisor would work. I even have the path in /etc/environments?

Why will supervisor not work?

like image 339
Tampa Avatar asked Oct 15 '12 16:10

Tampa


2 Answers

In your .conf file under the supervisord block, you can add all the environment key=value pairs as such

[supervisord] environment=CELERY_BROKER_URL="amqp://guest:[email protected]:5672//",FLASK_CONFIG="TESTING"  [program:celeryd] command=celery worker -A celery --loglevel=info -P gevent -c 1000 

If you dont want to hardcode the variables but want to pull it in from the os environment, step 1 on your bash

Export env var

>> sudo export CELERY_BROKER_URL="amqp://guest:[email protected]:5672//" 

Reload Bash

>> . ~/.bashrc 

Check if env vars are set properly

>> env 

Now modify the conf file to read - Note: prepend your env variables with ENV_

[supervisord] environment=CELERY_BROKER_URL="%(ENV_CELERY_BROKER_URL)s",FLASK_CONFIG="%(ENV_FLASK_CONFIG)s"  [program:celeryd] command=celery worker -A celery --loglevel=info -P gevent -c 1000 
like image 26
Shankar ARUL Avatar answered Sep 25 '22 22:09

Shankar ARUL


Referencing existing env vars is done with %(ENV_VARNAME)s

( see https://github.com/Supervisor/supervisor/blob/master/supervisor/skel/sample.conf )

Setting multiple environment variables is done by separating them with commas

( see http://supervisord.org/subprocess.html#subprocess-environment )

Try:

environment=PYTHONPATH=/opt/mypypath:%(ENV_PYTHONPATH)s,PATH=/opt/mypath:%(ENV_PATH)s 
like image 78
edibleEnergy Avatar answered Sep 24 '22 22:09

edibleEnergy