85 lines
3.3 KiB
Python
85 lines
3.3 KiB
Python
# w.c.s. - web application for online forms
|
|
# Copyright (C) 2005-2010 Entr'ouvert
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
# 02110-1301 USA
|
|
|
|
import socket
|
|
import sys
|
|
import qommon.scgi_server
|
|
import quixote.server.simple_server
|
|
|
|
from qommon.ctl import Command, make_option
|
|
|
|
class CmdStart(Command):
|
|
name = 'start'
|
|
|
|
def __init__(self):
|
|
Command.__init__(self, [
|
|
make_option('--port', metavar='PORT', action='store',
|
|
dest='port', default=3001),
|
|
make_option('--extra', metavar='DIR', action='append',
|
|
dest='extra', default=[]),
|
|
make_option('--handler-connection-limit', metavar='LIMIT',
|
|
action='store',
|
|
dest='handler_connection_limit', default=None),
|
|
make_option('--script-name', metavar='NAME', action='store',
|
|
dest='script_name', default=None),
|
|
make_option('--app-dir', metavar='DIR', action='store',
|
|
dest='app_dir', default=None),
|
|
make_option('--data-dir', metavar='DIR', action='store',
|
|
dest='data_dir', default=None),
|
|
make_option('--http', action='store_true',
|
|
dest='http', default=False),
|
|
make_option('--silent', action='store_true',
|
|
dest='silent', default=False),
|
|
])
|
|
|
|
def execute(self, options, args):
|
|
import publisher
|
|
|
|
run_kwargs = {}
|
|
run_kwargs['port'] = int(options.port)
|
|
run_kwargs['spawn_cron'] = True
|
|
run_function = qommon.scgi_server.run
|
|
for directory in options.extra:
|
|
publisher.WcsPublisher.register_extra_dir(directory)
|
|
if options.handler_connection_limit:
|
|
run_kwargs['handler_connection_limit'] = int(options.handler_connection_limit)
|
|
if options.script_name:
|
|
run_kwargs['script_name'] = options.script_name
|
|
if options.app_dir:
|
|
publisher.WcsPublisher.APP_DIR = options.app_dir
|
|
if options.data_dir:
|
|
publisher.WcsPublisher.DATA_DIR = options.data_dir
|
|
if options.http:
|
|
run_function = qommon.scgi_server.http_run
|
|
if options.silent:
|
|
sys.stdout = file('/dev/null', 'w')
|
|
sys.stderr = file('/dev/null', 'w')
|
|
|
|
try:
|
|
run_function(publisher.WcsPublisher.create_publisher, **run_kwargs)
|
|
except socket.error, e:
|
|
if e[0] == 98:
|
|
print >> sys.stderr, 'address already in use'
|
|
sys.exit(1)
|
|
raise
|
|
except KeyboardInterrupt:
|
|
sys.exit(1)
|
|
|
|
CmdStart.register()
|
|
|