Пример #1
0
from redisqueue import RedisQueue

from LogConfigParser import Config

import sys

from time import sleep

if __name__ == "__main__":
  c = Config()
  redis_section = "redis"
  worker_number = sys.argv[1]
  worker_section = sys.argv[2]
  if len(sys.argv) == 4:
    if "redis_%s" % sys.argv[3] in c.sections():
      redis_section = "redis_%s" % sys.argv[3]

  rq = RedisQueue(c.get(worker_section, "listento"), "logger_%s" % worker_number,
                  db=c.get(redis_section, "db"), 
                  host=c.get(redis_section, "host"), 
                  port=c.get(redis_section, "port")
                  )

  with open(c.get(worker_section, "logfile"), "a+") as logfile:
    while(True):
      line = rq.pop()
      if line:
        try:
          if line.endswith("\n"):
            logfile.write(line)
  else:
    # clear out the enabled directory
    for conf in os.listdir("workers_enabled"):
      if os.path.isfile(os.path.join("workers_enabled", conf)):
        os.remove(os.path.join("workers_enabled", conf))

  if not os.path.exists("workers_available"):
    os.mkdir("workers_available")
  c = Config()
  base_superv_conf = "supervisord.conf.base"
  if len(sys.argv) == 2:
    # use a different base supervisor file
    base_superv_conf = sys.argv[1]
  supervisord_config = Config(base_superv_conf)

  if 'supervisor' in c.sections():
    supervisord_config.add_section('inet_http_server')
    params = {'username':'******',
              'password':'******',
              'port':'127.0.0.1:9001'}
    for key in params:
      if c.has_option('supervisor', key):
        supervisord_config.set('inet_http_server', key, c.get('supervisor', key))
      else:
        supervisord_config.set('inet_http_server', key, params['key'])

  with open("supervisord.conf", "w") as cfgfile:
    supervisord_config.write(cfgfile)
    
  # process_* for simple, single use processes that don't require additional configuration
  #     aside from the 'command' instruction