Exemplo n.º 1
0
def init (scgi_port, cfg_file):
    # Translation support
    CTK.i18n.install ('cherokee', LOCALEDIR, unicode=True)

    # Ensure SIGCHLD is set. It needs to receive the signal in order
    # to detect when its child processes finish.
    if signal.getsignal (signal.SIGCHLD) == signal.SIG_IGN:
        signal.signal (signal.SIGCHLD, signal.SIG_DFL)

    # Move to the server directory
    pathname, scriptname = os.path.split(sys.argv[0])
    os.chdir(os.path.abspath(pathname))

    # Let the user know what is going on
    version = VERSION
    pid     = os.getpid()

    if scgi_port.isdigit():
        print _("Server %(version)s running.. PID=%(pid)d Port=%(scgi_port)s") % (locals())
    else:
        print _("Server %(version)s running.. PID=%(pid)d Socket=%(scgi_port)s") % (locals())

    # Read configuration file
    CTK.cfg.file = cfg_file
    CTK.cfg.load()

    # Update config tree if required
    config_version.config_version_update_cfg (CTK.cfg)

    # Init CTK
    if scgi_port.isdigit():
        # Ensure that 'localhost' can be resolved
        try:
            socket.getaddrinfo ("localhost", int(scgi_port))
        except socket.gaierror:
            print >> sys.stderr, "[FATAL ERROR]: The 'localhost' host name cannot be resolved.\n"
            sys.exit(1)

        CTK.init (host="localhost", port=int(scgi_port), sec_cookie=True, sec_submit=True)

    else:
        # Remove the unix socket if it already exists
        try:
            mode = os.stat (scgi_port)[stat.ST_MODE]
            if stat.S_ISSOCK(mode):
                print "Removing an old '%s' unix socket.." %(scgi_port)
                os.unlink (scgi_port)
        except OSError:
            pass

        CTK.init (unix_socket=scgi_port, sec_cookie=True, sec_submit=True)

    # At this moment, CTK must be forced to work as a syncronous
    # server. All the initial tests (config file readable, correct
    # installation, etc) must be performed in the safest possible way,
    # ensuring that race conditions don't cause trouble. It will be
    # upgraded to asyncronous mode just before the mainloop is reached
    CTK.set_synchronous (True)
Exemplo n.º 2
0
def init (scgi_port, cfg_file):
    # Translation support
    CTK.i18n.install ('cherokee', LOCALEDIR, unicode=True)

    # Ensure SIGCHLD is set. It needs to receive the signal in order
    # to detect when its child processes finish.
    if signal.getsignal (signal.SIGCHLD) == signal.SIG_IGN:
        signal.signal (signal.SIGCHLD, signal.SIG_DFL)

    # Move to the server directory
    pathname, scriptname = os.path.split(sys.argv[0])
    os.chdir(os.path.abspath(pathname))

    # Let the user know what is going on
    version = VERSION
    pid     = os.getpid()

    if scgi_port.isdigit():
        print _("Server %(version)s running.. PID=%(pid)d Port=%(scgi_port)s") % (locals())
    else:
        print _("Server %(version)s running.. PID=%(pid)d Socket=%(scgi_port)s") % (locals())

    # Read configuration file
    CTK.cfg.file = cfg_file
    CTK.cfg.load()

    # Update config tree if required
    config_version.config_version_update_cfg (CTK.cfg)

    # Init CTK
    if scgi_port.isdigit():
        # Ensure that 'localhost' can be resolved
        try:
            socket.getaddrinfo ("localhost", int(scgi_port))
        except socket.gaierror:
            print >> sys.stderr, "[FATAL ERROR]: The 'localhost' host name cannot be resolved.\n"
            sys.exit(1)

        CTK.init (host="localhost", port=int(scgi_port), sec_cookie=True)

    else:
        # Remove the unix socket if it already exists
        try:
            mode = os.stat (scgi_port)[stat.ST_MODE]
            if stat.S_ISSOCK(mode):
                print "Removing an old '%s' unix socket.." %(scgi_port)
                os.unlink (scgi_port)
        except OSError:
            pass

        CTK.init (unix_socket=scgi_port, sec_cookie=True)

    # At this moment, CTK must be forced to work as a syncronous
    # server. All the initial tests (config file readable, correct
    # installation, etc) must be performed in the safest possible way,
    # ensuring that race conditions don't cause trouble. It will be
    # upgraded to asyncronous mode just before the mainloop is reached
    CTK.set_synchronous (True)
Exemplo n.º 3
0
def init (scgi_port, cfg_file):
    # Translation support
    gettext.install('cherokee', LOCALEDIR)

    import __builtin__
    __builtin__.__dict__['N_'] = lambda x: x

    # Try to avoid zombie processes
    if hasattr(signal, "SIGCHLD"):
        signal.signal(signal.SIGCHLD, signal.SIG_IGN)

    # Move to the server directory
    pathname, scriptname = os.path.split(sys.argv[0])
    os.chdir(os.path.abspath(pathname))

    # Let the user know what is going on
    version = VERSION
    pid     = os.getpid()

    if scgi_port.isdigit():
        print _("Server %(version)s running.. PID=%(pid)d Port=%(scgi_port)s") % (locals())
    else:
        print _("Server %(version)s running.. PID=%(pid)d Socket=%(scgi_port)s") % (locals())

    # Read configuration file
    CTK.cfg.file = cfg_file
    CTK.cfg.load()

    # Update config tree if required
    config_version.config_version_update_cfg (CTK.cfg)

    # Init CTK
    if scgi_port.isdigit():
        CTK.init (port=8000)

    else:
        # Remove the unix socket if it already exists
        try:
            mode = os.stat (scgi_port)[stat.ST_MODE]
            if stat.S_ISSOCK(mode):
                print "Removing an old '%s' unix socket.." %(scgi_port)
                os.unlink (scgi_port)
        except OSError:
            pass

        CTK.init (unix_socket=scgi_port)

    # At this moment, CTK must be forced to work as a syncronous
    # server. All the initial tests (config file readable, correct
    # installation, etc) must be performed in the safest possible way,
    # ensuring that race conditions don't cause trouble. It will be
    # upgraded to asyncronous mode just before the mainloop is reached
    CTK.set_synchronous (True)