Ejemplo n.º 1
0
def handle_start_command(options):
    arguments = [
        'twistd', '--pidfile={}'.format(options.subOptions.opts['pidfile'])
    ]

    port = options.subOptions.opts['port'] or get_available_port()
    host = options.subOptions.opts['host'] or get_host_address()['ipv4']
    broker_host = options.subOptions.opts['broker_host']
    if not broker_host:
        print('You are missing the broker_host paramater'.ljust(73), end='')
        print('[{}]'.format(darkred('Fail')))
        print(options)
        sys.exit(1)

    nodaemon = options.subOptions.opts['nodaemon']
    if nodaemon:
        arguments.append('--nodaemon')
    else:
        arguments.append('--syslog')
        arguments.append('--prefix=pinky-node')

    arguments.append(SERVICE)
    arguments.append('--port={}'.format(port))
    arguments.append('--host={}'.format(host))
    arguments.append('--broker_host={}'.format(broker_host))

    if options.subOptions.opts['debug']:
        arguments.append('--debug')

    print('Starting pinky-node service'.ljust(73), end='')
    if nodaemon:
        os.execlp('twistd', *arguments)
    else:
        proc = subprocess.Popen(
            arguments,
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE
        )
        out, err = proc.communicate()
        if not err:
            if 'exception' in out:
                result = darkred('Fail')
                exit_code = -1
            else:
                result = darkgreen('Ok')
                exit_code = 0
        else:
            result = darkred('Fail')
            exit_code = -1

        print('[{}]'.format(result))
        print(err if exit_code == -1 else out)
        sys.exit(exit_code)
Ejemplo n.º 2
0
def handle_start_command(options):
    arguments = [
        'twistd', '--pidfile={}'.format(options.subOptions.opts['pidfile'])
    ]

    port = options.subOptions.opts['port'] or get_available_port()
    host = options.subOptions.opts['host'] or get_host_address()['ipv4']
    broker_host = options.subOptions.opts['broker_host']
    if not broker_host:
        print('You are missing the broker_host paramater'.ljust(73), end='')
        print('[{}]'.format(darkred('Fail')))
        print(options)
        sys.exit(1)

    nodaemon = options.subOptions.opts['nodaemon']
    if nodaemon:
        arguments.append('--nodaemon')
    else:
        arguments.append('--syslog')
        arguments.append('--prefix=pinky-node')

    arguments.append(SERVICE)
    arguments.append('--port={}'.format(port))
    arguments.append('--host={}'.format(host))
    arguments.append('--broker_host={}'.format(broker_host))

    if options.subOptions.opts['debug']:
        arguments.append('--debug')

    print('Starting pinky-node service'.ljust(73), end='')
    if nodaemon:
        os.execlp('twistd', *arguments)
    else:
        proc = subprocess.Popen(arguments,
                                stdin=subprocess.PIPE,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        out, err = proc.communicate()
        if not err:
            if 'exception' in out:
                result = darkred('Fail')
                exit_code = -1
            else:
                result = darkgreen('Ok')
                exit_code = 0
        else:
            result = darkred('Fail')
            exit_code = -1

        print('[{}]'.format(result))
        print(err if exit_code == -1 else out)
        sys.exit(exit_code)
Ejemplo n.º 3
0
def handle_start_command(options):
    arguments = [
        'twistd', '--pidfile={}'.format(options.subOptions.opts['pidfile'])
    ]

    nodaemon = options.subOptions.opts['nodaemon']
    if nodaemon:
        arguments.append('--nodaemon')
    else:
        arguments.append('--syslog')
        arguments.append('--prefix=pinky-broker')

    arguments.append(SERVICE)

    if options.subOptions.opts['debug']:
        arguments.append('--debug')

    if options.subOptions.opts['activate-ssh-server']:
        _handle_manhole(
            options.subOptions.opts['ssh-user'],
            options.subOptions.opts['ssh-password'],
            options.subOptions.opts['ssh-port'],
            arguments
        )

    print('Starting pinky-broker service'.ljust(73), end='')
    if nodaemon:
        os.execlp('twistd', *arguments)
    else:
        proc = subprocess.Popen(
            arguments,
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE
        )
        out, err = proc.communicate()
        if not err:
            if 'exception' in out:
                result = darkred('Fail')
                exit_code = -1
            else:
                result = darkgreen('Ok')
                exit_code = 0
        else:
            result = darkred('Fail')
            exit_code = -1

        print('[{}]'.format(result))
        print(err if exit_code == -1 else out)
        sys.exit(exit_code)
Ejemplo n.º 4
0
def handle_start_command(options):
    arguments = [
        'twistd', '--pidfile={}'.format(options.subOptions.opts['pidfile'])
    ]

    nodaemon = options.subOptions.opts['nodaemon']
    if nodaemon:
        arguments.append('--nodaemon')
    else:
        arguments.append('--syslog')
        arguments.append('--prefix=pinky-broker')

    arguments.append(SERVICE)

    if options.subOptions.opts['debug']:
        arguments.append('--debug')

    if options.subOptions.opts['activate-ssh-server']:
        _handle_manhole(options.subOptions.opts['ssh-user'],
                        options.subOptions.opts['ssh-password'],
                        options.subOptions.opts['ssh-port'], arguments)

    print('Starting pinky-broker service'.ljust(73), end='')
    if nodaemon:
        os.execlp('twistd', *arguments)
    else:
        proc = subprocess.Popen(arguments,
                                stdin=subprocess.PIPE,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        out, err = proc.communicate()
        if not err:
            if 'exception' in out:
                result = darkred('Fail')
                exit_code = -1
            else:
                result = darkgreen('Ok')
                exit_code = 0
        else:
            result = darkred('Fail')
            exit_code = -1

        print('[{}]'.format(result))
        print(err if exit_code == -1 else out)
        sys.exit(exit_code)
Ejemplo n.º 5
0
def _handle_manhole(user, password, port, arguments):
    if None in (user, password, port):
        print('You need to secify SSH user, password and port to activate it'
              ''.ljust(73),
              end='')
        print('[{}]'.format(darkred('Fail')))
        sys.exit(1)

    arguments.append('--activate-ssh-server=true')
    arguments.append('--ssh-user={}'.format(user))
    arguments.append('--ssh-password={}'.format(password))
    arguments.append('--ssh-port={}'.format(port))
Ejemplo n.º 6
0
def _handle_manhole(user, password, port, arguments):
    if None in (user, password, port):
        print(
            'You need to secify SSH user, password and port to activate it'
            ''.ljust(73), end=''
        )
        print('[{}]'.format(darkred('Fail')))
        sys.exit(1)

    arguments.append('--activate-ssh-server=true')
    arguments.append('--ssh-user={}'.format(user))
    arguments.append('--ssh-password={}'.format(password))
    arguments.append('--ssh-port={}'.format(port))
Ejemplo n.º 7
0
def handle_stop_command(srv, pid):
    """ Kill the running service
        :param srv: `str` containing the service to kill
            passed in as underscore_case
    """
    service = 'pinky_{}'.format(srv)
    twisted_pid = filepath.FilePath(pid)
    if not twisted_pid.exists():
        print('error: {}.pid file can\'t be found.'.format(service))
        sys.exit(-1)

    pid = twisted_pid.open().read()
    print('killing {} process id {} with SIGINT signal'.format(
        service, pid).ljust(73), end='')
    try:
        filepath.os.kill(int(pid), signal.SIGINT)
        print('[{}]'.format(darkgreen('Ok')))
    except:
        print('[{}]'.format(darkred('Fail')))
        raise