Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

supervisor can't get linux environment variable #1044

Closed
631068264 opened this issue Jan 12, 2018 · 4 comments
Closed

supervisor can't get linux environment variable #1044

631068264 opened this issue Jan 12, 2018 · 4 comments

Comments

@631068264
Copy link

631068264 commented Jan 12, 2018

I have wrote export PROJECT_ENV='PRODUCTION' in /etc/profile and source it

my conf is in /etc/supervisor/conf.d

[supervisord]
environment=PROJECT_ENV=%(ENV_PROJECT_ENV)s

[program:cb_depth_aug]

command = /home/fibo/project/coinbell/.env/bin/python depth.py aug
directory = /home/fibo/project/coinbell/tools
user = fibo
autostart = true
autorestart = true
startsecs = 5
startretries = 3
redirect_stderr         = true
stdout_logfile_maxbytes = 50MB
stdout_logfile_backups  = 10
stdout_logfile          = /home/fibo/project/coinbell/tools/logs/supervisor.log

error: <class 'xmlrpclib.Fault'>, <Fault 92: "CANT_REREAD: Format string 'PROJECT_ENV=%(ENV_PROJECT_ENV)s' for 'supervisord.environment' contains names ('ENV_PROJECT_ENV') which cannot be expanded. Available names: ENV_LANG, ENV_PATH, here">: file: /usr/lib/python2.7/xmlrpclib.py line: 800

In my code I use

import os
code = os.getenv('PROJECT_ENV', 'TEST')

get environment variable but I only get 'TEST'

if I remove

[supervisord]
environment=PROJECT_ENV=%(ENV_PROJECT_ENV)s

I only get 'TEST' and I can't get 'PRODUCTION'

[program:cb_depth_aug]

command = /home/fibo/project/coinbell/.env/bin/python depth.py aug
directory = /home/fibo/project/coinbell/tools
user = fibo
autostart = true
autorestart = true
startsecs = 5
startretries = 3
environment=PROJECT_ENV=%(ENV_PYTHONPATH)s
redirect_stderr         = true
stdout_logfile_maxbytes = 50MB
stdout_logfile_backups  = 10
stdout_logfile          = /home/fibo/project/coinbell/tools/logs/supervisor.log

This can't not work too

@mnaberez
Copy link
Member

Please ask questions about using Supervisor on the supervisor-users mailing list. We use this issue tracker mainly for bugs in Supervisor itself.

error: <class 'xmlrpclib.Fault'>, <Fault 92: "CANT_REREAD: Format string 'PROJECT_ENV=%(ENV_PROJECT_ENV)s' for 'supervisord.environment' contains names ('ENV_PROJECT_ENV') which cannot be expanded. Available names: ENV_LANG, ENV_PATH, here">: file: /usr/lib/python2.7/xmlrpclib.py line: 800

You are trying to use an environment variable called PROJECT_ENV, but that variable isn't set in supervisord's environment. If you want to use this variable, it needs to be present in the environment at the time that supervisord is started.

Here is an example that shows PROJECT_ENV will be available to the subprocess if it is available in the environment at the time that supervisord is started:

$ export PROJECT_ENV=foo

$ cat supervisord.conf 
[supervisord]
loglevel = debug

[program:env]
command = /usr/bin/env
startsecs = 0
autorestart = false

$ supervisord -n -c supervisord.conf 
2018-01-13 16:56:45,187 INFO Increased RLIMIT_NOFILE limit to 1024
2018-01-13 16:56:45,192 INFO supervisord started with pid 69336
2018-01-13 16:56:46,198 INFO spawned: 'env' with pid 69341
2018-01-13 16:56:46,207 DEBG 'env' stdout output:
... many variables elided ...
PROJECT_ENV=foo

2018-01-13 16:56:46,208 INFO success: env entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2018-01-13 16:56:46,208 DEBG fd 7 closed, stopped monitoring <POutputDispatcher at 4567162104 for <Subprocess at 4584989640 with name env in state RUNNING> (stdout)>
2018-01-13 16:56:46,208 DEBG fd 9 closed, stopped monitoring <POutputDispatcher at 4585050296 for <Subprocess at 4584989640 with name env in state RUNNING> (stderr)>
2018-01-13 16:56:46,208 INFO exited: env (exit status 0; expected)
2018-01-13 16:56:46,209 DEBG received SIGCHLD indicating a child quit

@No1zzz
Copy link

No1zzz commented Jul 4, 2018

env                              EXITED    Jul 04 04:23 PM
supervisor> tail env
LANG=en_US.UTF-8
SHELL=/bin/sh
SUPERVISOR_ENABLED=1
SUPERVISOR_PROCESS_NAME=env
SUPERVISOR_SERVER_URL=unix:///var/run/supervisor.sock
LOGNAME=root
USER=root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOME=/root
DAEMON_OPTS=
SUPERVISOR_GROUP_NAME=env

@No1zzz
Copy link

No1zzz commented Jul 4, 2018

env from system:

env
SHELL=/bin/bash
TERM=xterm-256color
USER=root
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
SUDO_USER=aiutin
SUDO_UID=1003
USERNAME=root
MAIL=/var/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
PWD=/home/aiutin
LANG=en_US.UTF-8
SHLVL=1
SUDO_COMMAND=/bin/su
HOME=/root
LOGNAME=root
LESSOPEN=| /usr/bin/lesspipe %s
SUDO_GID=1003
LESSCLOSE=/usr/bin/lesspipe %s %s
HISTTIMEFORMAT=%Y/%m/%d %T
_=/usr/bin/env

@wumindc
Copy link

wumindc commented Aug 2, 2021

I encountered the same problem. When the operating system restarts (centos7), it cannot be loaded into the variable set in / etc / profile. must kill the supervisor process and restart, Is there a solution now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants