alexsilva / supervisor

Supervisor process control system for Windows
http://supervisord.org
Other
118 stars 26 forks source link

Environment not working #14

Closed maxstrobel closed 4 years ago

maxstrobel commented 4 years ago

Hi,

I tried to set and use environment variables as described in the documentation Environment Variables / Section Example. However, it does not work to set the variables and they are not found afterwards. Does anyone have a clue, where I did a mistake or is this a general bug?

supervisord.conf

[inet_http_server]         ; inet (TCP) server disabled by default
port=127.0.0.1:9001        ; ip_address:port specifier, *:port for all iface

[supervisord]
logfile=C:\\etc\\supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB               ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10                  ; (num of main logfile rotation backups;default 10)
loglevel=info                       ; (log level;default info; others: debug,warn,trace)
pidfile=C:\\etc\\supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false                      ; (start in foreground if true;default false)
minfds=1024                         ; (min. avail startup file descriptors;default 1024)
minprocs=200                        ; (min. avail process descriptors;default 200)
environment=TESTVAR="C:\data\test.py"

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket

[include]
files = conf.d/*.conf

conf.d/test.conf

[program:test]
command="C:\python_tools\venv\Scripts\python.exe" %(ENV_TESTVAR)s

Log

2020-04-29 10:04:29,714 [INFO] supervisor config path: C:\etc\supervisor\supervisord.conf
2020-04-29 10:04:30,073 [INFO] supervisor starting...
2020-04-29 10:04:30,088 [ERROR] supervisor starting failed
Traceback (most recent call last):
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\options.py", line 1973, in expand
    return s % expansions
KeyError: 'ENV_TESTVAR'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\options.py", line 810, in processes_from_section
    parser, section, group_name, klass)
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\options.py", line 939, in _processes_from_section
    command = get(section, 'command', None, expansions=expansions)
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\options.py", line 836, in get
    return parser.saneget(section, opt, *args, **kwargs)
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\options.py", line 1540, in saneget
    "%s.%s" % (section, option))
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\options.py", line 1980, in expand
    (s, name, str(ex), ", ".join(available)))
ValueError: Format string '"C:\\python_tools\\venv\\Scripts\\python.exe" %(ENV_TESTVAR)s' for 'program:test.command' contains names ('ENV_TESTVAR') which cannot be expanded. Available names: ENV_ALLUSERSPROFILE, ENV_APPDATA, ENV_CAMEXPERTDIR, ENV_COMMONPROGRAMFILES, ENV_COMMONPROGRAMFILES(X86), ENV_COMMONPROGRAMW6432, ENV_COMPUTERNAME, ENV_COMSPEC, ENV_CORSNIDDIR, ENV_CVB, ENV_CVBCONFIG, ENV_CVBDATA, ENV_CVGENICAM_REGISTRY, ENV_DRIVERDATA, ENV_GENICAM_CACHE_V2_4, ENV_GENICAM_CACHE_V3_1, ENV_GENICAM_GENTL64_PATH, ENV_GENICAM_LOG_CONFIG_V2_4, ENV_GENICAM_ROOT_V2_4, ENV_HOMEDRIVE, ENV_HOMEPATH, ENV_LOCALAPPDATA, ENV_LOGONSERVER, ENV_NUMBER_OF_PROCESSORS, ENV_ONEDRIVE, ENV_OS, ENV_PATH, ENV_PATHEXT, ENV_PROCESSOR_ARCHITECTURE, ENV_PROCESSOR_IDENTIFIER, ENV_PROCESSOR_LEVEL, ENV_PROCESSOR_REVISION, ENV_PROGRAMDATA, ENV_PROGRAMFILES, ENV_PROGRAMFILES(X86), ENV_PROGRAMW6432, ENV_PSMODULEPATH, ENV_PUBLIC, ENV_PYTHONPATH, ENV_SAPERADIR, ENV_SYSTEMDRIVE, ENV_SYSTEMROOT, ENV_TELEDYNE_DALSA_GENICAM_ROOT, ENV_TEMP, ENV_TMP, ENV_USERDOMAIN, ENV_USERDOMAIN_ROAMINGPROFILE, ENV_USERNAME, ENV_USERPROFILE, ENV_WINDIR, group_name, here, host_node_name, process_num, program_name

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\options.py", line 349, in process_config_file
    self.read_config(self.configfile)
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\options.py", line 644, in read_config
    section.process_group_configs = self.process_groups_from_parser(parser)
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\options.py", line 702, in process_groups_from_parser
    ProcessConfig)
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\options.py", line 814, in processes_from_section
    % (e, section, filename))
ValueError: Format string '"C:\\python_tools\\venv\\Scripts\\python.exe" %(ENV_TESTVAR)s' for 'program:test.command' contains names ('ENV_TESTVAR') which cannot be expanded. Available names: ENV_ALLUSERSPROFILE, ENV_APPDATA, ENV_CAMEXPERTDIR, ENV_COMMONPROGRAMFILES, ENV_COMMONPROGRAMFILES(X86), ENV_COMMONPROGRAMW6432, ENV_COMPUTERNAME, ENV_COMSPEC, ENV_CORSNIDDIR, ENV_CVB, ENV_CVBCONFIG, ENV_CVBDATA, ENV_CVGENICAM_REGISTRY, ENV_DRIVERDATA, ENV_GENICAM_CACHE_V2_4, ENV_GENICAM_CACHE_V3_1, ENV_GENICAM_GENTL64_PATH, ENV_GENICAM_LOG_CONFIG_V2_4, ENV_GENICAM_ROOT_V2_4, ENV_HOMEDRIVE, ENV_HOMEPATH, ENV_LOCALAPPDATA, ENV_LOGONSERVER, ENV_NUMBER_OF_PROCESSORS, ENV_ONEDRIVE, ENV_OS, ENV_PATH, ENV_PATHEXT, ENV_PROCESSOR_ARCHITECTURE, ENV_PROCESSOR_IDENTIFIER, ENV_PROCESSOR_LEVEL, ENV_PROCESSOR_REVISION, ENV_PROGRAMDATA, ENV_PROGRAMFILES, ENV_PROGRAMFILES(X86), ENV_PROGRAMW6432, ENV_PSMODULEPATH, ENV_PUBLIC, ENV_PYTHONPATH, ENV_SAPERADIR, ENV_SYSTEMDRIVE, ENV_SYSTEMROOT, ENV_TELEDYNE_DALSA_GENICAM_ROOT, ENV_TEMP, ENV_TMP, ENV_USERDOMAIN, ENV_USERDOMAIN_ROAMINGPROFILE, ENV_USERNAME, ENV_USERPROFILE, ENV_WINDIR, group_name, here, host_node_name, process_num, program_name in section 'program:test' (file: 'C:\\etc\\supervisor\\conf.d\\test.conf')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\services.py", line 159, in main
    supervisord.main(("-c", self.config_filepath))
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\supervisord.py", line 388, in main
    options.realize(args, doc=__doc__)
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\options.py", line 487, in realize
    Options.realize(self, *arg, **kw)
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\options.py", line 311, in realize
    self.process_config()
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\options.py", line 525, in process_config
    Options.process_config(self, do_usage=do_usage)
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\options.py", line 319, in process_config
    self.process_config_file(do_usage)
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\options.py", line 353, in process_config_file
    self.usage(str(msg))
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\options.py", line 149, in usage
    self.stderr.write("Error: %s\n" % str(msg))
AttributeError: 'NoneType' object has no attribute 'write'
alexsilva commented 4 years ago

Only operating system variables can be expanded. environment-variables

Environment variables that are present in the environment at the time that supervisord is started.

environment are variables passed to the process. This option does not affect the formatting of the supervisor.conf subprocess-environment

I made a fix for this failure only

Traceback (most recent call last):
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\services.py", line 159, in main
    supervisord.main(("-c", self.config_filepath))
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\supervisord.py", line 388, in main
    options.realize(args, doc=__doc__)
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\options.py", line 487, in realize
    Options.realize(self, *arg, **kw)
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\options.py", line 311, in realize
    self.process_config()
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\options.py", line 525, in process_config
    Options.process_config(self, do_usage=do_usage)
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\options.py", line 319, in process_config
    self.process_config_file(do_usage)
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\options.py", line 353, in process_config_file
    self.usage(str(msg))
  File "C:\Users\DAL\AppData\Local\Programs\Python\Python36\lib\site-packages\supervisor\options.py", line 149, in usage
    self.stderr.write("Error: %s\n" % str(msg))
AttributeError: 'NoneType' object has no attribute 'write'
maxstrobel commented 4 years ago

Ah, I see. Then I misunderstood respectively mixed up both concepts.

Is there another option to organize configurations in a hierarchical way, e.g. define something in the global supervisord.conf and reuse this configurations from ther [include] section?

alexsilva commented 4 years ago

The configuration file is basically a configparser

In python 3 with configparser it is possible but due to the implementation of the supervisor there are some incompatibilities. Unfortunately it is not possible with a supervisor at the moment.