# -*- coding: utf-8 -*-
# $Id: backendctl 1634 2013-04-12 15:36:36Z amelung $
#
# Copyright (c) 2007-2009 Otto-von-Guericke-Universität, Magdeburg
#
# This file is part of ECSpooler.
#
"""
information from a backend. __main__ reads the command lines arguments and
processes them. A configuration file must be avaiable for each backend
with entries about spooler server's host and port as well as base port
for the backend. If a port is already in use, we will try another one.
"""
# add parent directory to the system path
# local imports
# TODO: should be in config.py
"""
"""
"""
"""
print """
Usage: backendctl [OPTION ...] BACKEND {start|stop|restart|status}
OPTIONs are:
new request. Default: First free port in the range
of 5060 .. 5074.
-S host Hostname or IP of the machine on which ECSpooler runs.
Needed for registering a backend. Default: localhost
-B port Port on which ECSpooler runs. Needed for registering a
backend. Default: 5050
-u user Name of the user required for authentication when starting
and registering to ECSpooler
-p password Password of the user required for authentication when
starting and registering to ECSpooler
BACKEND Name of the backend to start|stop|restart|status.
"""
"""
"""
"""
@see: ServiceControl.start()
"""
# Run backend as nobody
try:
print >> sys.stderr, "Cannot change uid:", e
try:
print >> sys.stderr, "No such backend: '%s'. Did you mean '%s'?" \
if backend:
print >> sys.stdout, " Port: %i" % p
print >> sys.stdout, "Registering to ECSpooler at '%s:%s'..." % (self.spooler_host, self.spooler_port)
try:
else:
print >> sys.stdout, 'os.fork not defined - skipping.'
cpid = 0
if cpid == 0:
# child process
# blocks here 'til shutdown
if err_msg:
print >> sys.stderr, err_msg
else:
# parent process
time.sleep(1)
else:
#print 'Backend start failed. See log for more information.'
print >> sys.stderr, 'Backend start failed. See log for more information.'
"""
Returns an instance of the backend class if one could be created.
"""
# put together the backend module and class name using backend_id
# get a instance, e.g., Python-Backend
# FIXME: use spooler instead of spooler
"backend = %s({ \
'host': '%s', \
'port': %d, \
'spooler': 'http://%s:%d', \
'auth': %s}, %s.__file__)" \
% (moduleName, self.host, port, \
if retval:
else:
time.sleep(0.1)
return (None, 0)
"""
Executes the import statement for the backend class, creates an
instance and returns this instance.
An exception is thrown if the port is already in use. In this case we
will return None.
@param: instance_create_stmt Statement which will be executed to create
a new instance of the backend class.
@return: The backend instance or None if the instance couldn't be created.
"""
try:
#log.debug(instance_create_stmt)
exec(instance_create_stmt)
return backend
# FIXME: This doesn't work on Windows -> no socket.error is thrown if
# port is already in use!
return None
"""
@see ServiceControl.stop
@see ServiceControl._process_stop
"""
print >> sys.stdout, result
"""
@see ServiceControl._process_status
"""
# -----------------------------------------------------------------------------
"""
"""
try:
["spoolerhost=", "spoolerport=",
"backendport=", "user=", "password=",
"help"])
# print help information and exit:
sys.exit(2)
sys.exit(2)
else:
spooler_host = 'localhost'
spooler_port = 5050
backend_port = 5060
sys.exit()
spooler_host = a
try:
spooler_port = int(a)
sys.exit(2)
user = a
password = a
try:
backend_port = int(a)
sys.exit(2)
print "%s requires username and password." % cmd
sys.exit(2)
# -- Main ----------------------------------------------------------------------
if __name__ == "__main__":
main()