Example #1
0
    def __supervisord(self):
        format_vars = {
            "supervisor_state_dir": self.supervisor_state_dir,
            "supervisord_conf_dir": self.supervisord_conf_dir,
        }
        supervisord_pid_path = join(self.supervisor_state_dir, "supervisord.pid")

        try:
            assert exists(supervisord_pid_path)
            os.kill(int(open(supervisord_pid_path).read()), 0)
        except:
            # any time that supervisord is not running, let's rewrite supervisord.conf
            open(self.supervisord_conf_path, "w").write(supervisord_conf_template.format(**format_vars))
            # supervisord detaches, fork so we don't exit here
            pid = os.fork()
            if pid == 0:
                args = ["-c", self.supervisord_conf_path]
                # set sys.argv so if there's an error it doesn't output a
                # misleading message that appears to be coming from galaxy
                sys.argv = ["supervisord"] + args
                setproctitle("supervisord -c %s" % self.supervisord_conf_path)
                supervisord.main(args=args)
            else:
                pid, rc = os.waitpid(pid, 0)
                assert rc == 0, "supervisord exited with code %d" % rc
                log.info("supervisord started as pid %d", pid)
Example #2
0
    def start_server(self, **options):
        from supervisor import supervisord
        args = ['-c', '/etc/antilles/supervisord.conf']
        if options['nodaemon']:
            args.append('--nodaemon')

        supervisord.main(args)
Example #3
0
    def __supervisord(self):
        format_vars = {
            'supervisor_state_dir': self.supervisor_state_dir,
            'supervisord_conf_dir': self.supervisord_conf_dir
        }
        supervisord_pid_path = join(self.supervisor_state_dir,
                                    'supervisord.pid')

        try:
            assert exists(supervisord_pid_path)
            os.kill(int(open(supervisord_pid_path).read()), 0)
        except:
            # any time that supervisord is not running, let's rewrite supervisord.conf
            open(self.supervisord_conf_path,
                 'w').write(supervisord_conf_template.format(**format_vars))
            # supervisord detaches, fork so we don't exit here
            pid = os.fork()
            if pid == 0:
                args = ['-c', self.supervisord_conf_path]
                # set sys.argv so if there's an error it doesn't output a
                # misleading message that appears to be coming from galaxy
                sys.argv = ['supervisord'] + args
                setproctitle('supervisord -c %s' % self.supervisord_conf_path)
                supervisord.main(args=args)
            else:
                pid, rc = os.waitpid(pid, 0)
                assert rc == 0, 'supervisord exited with code %d' % rc
                log.info('supervisord started as pid %d', pid)
Example #4
0
 def main(self):
     """Starts running the supervisor"""
     try:
         from supervisor import supervisord
         self.logger.info("supervisor starting...")
         supervisord.main(("-c", self.config_filepath))
     except:
         self.logger.exception("supervisor starting failed")
Example #5
0
    def handle(self, *args, **options):
        #  We basically just construct the merged supervisord.conf file
        #  and forward it on to either supervisord or supervisorctl.
        cfg = get_merged_config(**options)

        # If --dump was passed, just print the combined config file and exit
        if options.get('dump'):
            print cfg
            return

        #  Due to some very nice engineering on behalf of supervisord authors,
        #  you can pass it a StringIO instance for the "-c" command-line
        #  option.  Saves us having to write the config to a tempfile.
        cfg_file = StringIO(cfg)
        #  With no arguments, we launch the processes under supervisord.
        if not args:
            return supervisord.main(("-c", cfg_file))
        #  With arguments, the first arg specifies the sub-command
        #  Some commands we implement ourself with _handle_<command>.
        #  The rest we just pass on to supervisorctl.
        assert args[0].isalnum()
        methname = "_handle_%s" % (args[0], )
        try:
            method = getattr(self, methname)
        except AttributeError:
            return supervisorctl.main(("-c", cfg_file) + args)
        else:
            return method(cfg_file, *args[1:], **options)
    def handle(self, *args, **options):
        args = args or tuple(options.pop('ctl-command'))

        #  We basically just construct the merged supervisord.conf file
        #  and forward it on to either supervisord or supervisorctl.
        #  Due to some very nice engineering on behalf of supervisord authors,
        #  you can pass it a StringIO instance for the "-c" command-line
        #  option.  Saves us having to write the config to a tempfile.
        cfg_file = OnDemandStringIO(get_merged_config, **options)
        #  With no arguments, we launch the processes under supervisord.
        if not args:
            return supervisord.main(("-c", cfg_file))
        #  With arguments, the first arg specifies the sub-command
        #  Some commands we implement ourself with _handle_<command>.
        #  The rest we just pass on to supervisorctl.
        if not args[0].isalnum():
            raise ValueError("Unknown supervisor command: %s" % (args[0], ))
        methname = "_handle_%s" % (args[0], )
        try:
            method = getattr(self, methname)
        except AttributeError:
            return supervisorctl_main(("-c", cfg_file) + args,
                                      stdout=self.stdout,
                                      stdin=options.get('stdin', sys.stdin),
                                      stderr=self.stderr)
        else:
            return method(cfg_file, *args[1:], **options)
Example #7
0
    def handle(self, *args, **options):
        #  We basically just construct the merged supervisord.conf file
        #  and forward it on to either supervisord or supervisorctl.
        cfg = get_merged_config(**options)

        # If --dump was passed, just print the combined config file and exit
        if options.get('dump'):
            print cfg
            return

        #  Due to some very nice engineering on behalf of supervisord authors,
        #  you can pass it a StringIO instance for the "-c" command-line
        #  option.  Saves us having to write the config to a tempfile.
        cfg_file = StringIO(cfg)
        #  With no arguments, we launch the processes under supervisord.
        if not args:
            return supervisord.main(("-c",cfg_file))
        #  With arguments, the first arg specifies the sub-command
        #  Some commands we implement ourself with _handle_<command>.
        #  The rest we just pass on to supervisorctl.
        assert args[0].isalnum()
        methname = "_handle_%s" % (args[0],)
        try:
            method = getattr(self,methname)
        except AttributeError:
            return supervisorctl.main(("-c",cfg_file) + args)
        else:
            return method(cfg_file,*args[1:],**options)
Example #8
0
 def test_main_noprofile(self):
     from supervisor.supervisord import main
     conf = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                         'fixtures', 'donothing.conf')
     new_stdout = StringIO()
     old_stdout = sys.stdout
     try:
         tempdir = tempfile.mkdtemp()
         log = os.path.join(tempdir, 'log')
         pid = os.path.join(tempdir, 'pid')
         sys.stdout = new_stdout
         main(args=['-c', conf, '-l', log, '-j', pid, '-n'], test=True)
     finally:
         sys.stdout = old_stdout
         shutil.rmtree(tempdir)
     output = new_stdout.getvalue()
     self.assertTrue(output.find('supervisord started') != 1, output)
 def test_main_noprofile(self):
     from supervisor.supervisord import main
     conf = os.path.join(
         os.path.abspath(os.path.dirname(__file__)), 'fixtures',
         'donothing.conf')
     new_stdout = StringIO()
     old_stdout = sys.stdout
     try:
         tempdir = tempfile.mkdtemp()
         log = os.path.join(tempdir, 'log')
         pid = os.path.join(tempdir, 'pid')
         sys.stdout = new_stdout
         main(args=['-c', conf, '-l', log, '-j', pid, '-n'],
              test=True)
     finally:
         sys.stdout = old_stdout
         shutil.rmtree(tempdir)
     output = new_stdout.getvalue()
     self.assertTrue(output.find('supervisord started') != 1, output)
    def test_silent_on(self):
        from supervisor.supervisord import main
        conf = os.path.join(
            os.path.abspath(os.path.dirname(__file__)), 'fixtures',
            'donothing.conf')
        new_stdout = StringIO()
        new_stdout.fileno = lambda: 1
        old_stdout = sys.stdout

        try:
            tempdir = tempfile.mkdtemp()
            log = os.path.join(tempdir, 'log')
            pid = os.path.join(tempdir, 'pid')
            sys.stdout = new_stdout
            main(args=['-c', conf, '-l', log, '-j', pid, '-n', '-s'], test=True)
        finally:
            sys.stdout = old_stdout
            shutil.rmtree(tempdir)
        output = new_stdout.getvalue()
        self.assertEqual(len(output), 0)
 def test_main_profile(self):
     from supervisor.supervisord import main
     conf = os.path.join(
         os.path.abspath(os.path.dirname(__file__)), 'fixtures',
         'donothing.conf')
     new_stdout = StringIO()
     new_stdout.fileno = lambda: 1
     old_stdout = sys.stdout
     try:
         tempdir = tempfile.mkdtemp()
         log = os.path.join(tempdir, 'log')
         pid = os.path.join(tempdir, 'pid')
         sys.stdout = new_stdout
         main(args=['-c', conf, '-l', log, '-j', pid, '-n',
                    '--profile_options=cumulative,calls'], test=True)
     finally:
         sys.stdout = old_stdout
         shutil.rmtree(tempdir)
     output = new_stdout.getvalue()
     self.assertTrue('cumulative time, call count' in output, output)
Example #12
0
 def test_main_profile(self):
     from supervisor.supervisord import main
     conf = os.path.join(
         os.path.abspath(os.path.dirname(__file__)), 'fixtures',
         'donothing.conf')
     new_stdout = StringIO()
     new_stdout.fileno = lambda: 1
     old_stdout = sys.stdout
     try:
         tempdir = tempfile.mkdtemp()
         log = os.path.join(tempdir, 'log')
         pid = os.path.join(tempdir, 'pid')
         sys.stdout = new_stdout
         main(args=['-c', conf, '-l', log, '-j', pid, '-n',
                    '--profile_options=cumulative,calls'], test=True)
     finally:
         sys.stdout = old_stdout
         shutil.rmtree(tempdir)
     output = new_stdout.getvalue()
     self.assertTrue('cumulative time, call count' in output, output)
Example #13
0
def scrape(monitor, source):
    """

    Parameters
    ----------
    monitor: bool
        Start supervisord monitoring server

    source: str
        'all', 'gdax', 'reddit', 'twitter'

    Returns
    -------

    """

    ProjectManager.set_path('.')
    main([
        '-c',
        os.path.join(ProjectManager.KRYPTOFLOW_DIR,
                     ProjectManager.get_value('supervisor'))
    ])
    if monitor:
        print('monitoring')
Example #14
0
    def handle(self, *args, **options):
        args = args or tuple(options.pop('ctl-command'))

        #  We basically just construct the merged supervisord.conf file
        #  and forward it on to either supervisord or supervisorctl.
        #  Due to some very nice engineering on behalf of supervisord authors,
        #  you can pass it a StringIO instance for the "-c" command-line
        #  option.  Saves us having to write the config to a tempfile.
        cfg_file = OnDemandStringIO(get_merged_config, **options)
        #  With no arguments, we launch the processes under supervisord.
        if not args:
            return supervisord.main(("-c",cfg_file))
        #  With arguments, the first arg specifies the sub-command
        #  Some commands we implement ourself with _handle_<command>.
        #  The rest we just pass on to supervisorctl.
        if not args[0].isalnum():
            raise ValueError("Unknown supervisor command: %s" % (args[0],))
        methname = "_handle_%s" % (args[0],)
        try:
            method = getattr(self,methname)
        except AttributeError:
            return supervisorctl.main(("-c",cfg_file) + args)
        else:
            return method(cfg_file,*args[1:],**options)
Example #15
0
from supervisor.supervisord import main
"""
supervisor与supervisorctl基于rpc通信 
子进程与主进程的管道通信
"""

if __name__ == "__main__":
    main()
# should probably make this a multi-call binary with symlinks... but for now:
from supervisor.supervisord import main
main()
Example #17
0
#!/usr/bin/env python
#

from supervisor import supervisord

supervisord.main()
Example #18
0
 def run_supervisor(self):
     cfg_file = OnDemandStringIO(self.get_merged_config)
     newpid = os.fork()
     if newpid == 0:
         supervisord.main(("-c",cfg_file))
     exit()