Example #1
0
def main():
    from optparse import OptionParser
    parser = OptionParser(usage='%prog [options] config_file...')
    parser.add_option('-d', '--daemon', dest='daemon', action='store_true', default=False, help='daemonize')
    parser.add_option('-p', '--pidfile', dest='pidfile', action='store', default=None, help='write pid to file')
    parser.add_option('-c', '--cli', dest='server_class', action='store_const', const=MtrpcCli, default=AmqpServer,
                      help='run CLI')
    parser.add_option('-H', '--http', dest='server_class', action='store_const', const=HttpServer,
                      help='run HTTP backend')

    (o, a) = parser.parse_args()

    server = ServerConfig(a, o.server_class)

    if o.daemon and o.server_class is not MtrpcCli:
        daemonize.daemonize()

    server.run()
Example #2
0
if name.endswith("_agent"):
    name = name[:-6]  # strip _agent

CONFIG_DIR = '/etc/megiteam/mtrpc'
CONFIG_PATH = os.path.join(CONFIG_DIR, name + ".json")

parser = OptionParser(usage='%prog [options]')
parser.add_option('-d', '--daemon', dest='daemon', action='store_true', default=False, help='Daemonize')
parser.add_option('-c', '--config', dest='config', default=CONFIG_PATH, help='Path to config file', metavar='FILE')

(o, a) = parser.parse_args(sys.argv[1:])

server = None
restart_lock = threading.Lock()
final_callback = restart_lock.release
# (^ to restart the server when the service threads are stopped)

if o.daemon:
    daemonize.daemonize()

try:
    # no inner server loop needed, we have the outer one here
    while True:
        if restart_lock.acquire(False):   # (<- non-blocking)
            server = ServerConfig([o.config], AmqpServer)
            server.run(final_callback=final_callback)
        signal.pause()
except KeyboardInterrupt:
    if server is not None:
        server.stop()
Example #3
0
#!/usr/bin/env python

import signal

from mtrpc.server.amqp import AmqpServer
from mtrpc.server.server_config import ServerConfig


# configure and start the server -- then wait for KeyboardInterrupt
# exception or OS signals specified in the config file...

server = None

try:
    # no inner server loop needed, we have the outer one here
    while True:
        server = ServerConfig(['server_simple_example_conf.json'], AmqpServer)
        server.run()
        signal.pause()
except KeyboardInterrupt:
    if server is not None:
        server.stop()