コード例 #1
0
ファイル: pinky_node.py プロジェクト: dr4ke616/pinky
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)
コード例 #2
0
ファイル: pinky_node.py プロジェクト: dr4ke616/pinky
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)
コード例 #3
0
ファイル: pinky_broker.py プロジェクト: dr4ke616/pinky
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)
コード例 #4
0
ファイル: pinky_broker.py プロジェクト: dr4ke616/pinky
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)
コード例 #5
0
ファイル: utils.py プロジェクト: dr4ke616/pinky
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