Exemple #1
0
def commit_command(db=None, what=None, why=None):
    """
    Used to a commit event to the database for other admins to know
    what is going on with the config.  The system logs quite a lot
    already for you, like your username, machine name, etc:

        m2sh commit -db test.sqlite -what mongrel2.org \
            -why "Needed to change paters."

    In future versions it will prevent you from committing as root,
    because only assholes commit from root.

    Both parameters are arbitrary, but I like to record what I did to
    different Hosts in servers.
    """
    import socket

    store = model.load_db("sqlite:" + db)
    who = unicode(getpass.getuser())

    if who == u"root":
        print "Commit from root eh?  Man, you're kind of a tool."

    log = model.Log()
    log.who = who
    log.what = unicode(what)
    log.why = unicode(why)
    log.location = unicode(socket.gethostname())
    log.how = u"m2sh"

    store.add(log)
    store.commit()
Exemple #2
0
def control_command(db=None, host="", name="", uuid=""):
    """
    Start a simple control console for working with mongrel2.
    This is *very* bare bones at the moment but should improve.

        m2sh control -db config.sqlite -uuid 3d815ade-9081-4c36-94dc-77a9b060b021
        m2sh control -db config.sqlite -host localhost
        m2sh control -db config.sqlite -name test
    """
    store = model.load_db("sqlite:" + db)
    import zmq

    servers = find_servers(db, uuid, host, name, False)

    if servers:
        server = servers[0]
        CTX = zmq.Context()

        results = store.find(model.Setting, model.Setting.key == unicode("control_port"))
        addr = results[0].value if results.count() > 1 else "ipc://run/control"

        ctl = CTX.socket(zmq.REQ)

        print "CONNECTING to: %s in %s" % (addr, server.chroot)
        os.chdir(server.chroot)
        ctl.connect(addr)

        try:
            while True:
                cmd = raw_input("> ")
                ctl.send(cmd)
                print ctl.recv()

        except EOFError:
            ctl.close()
Exemple #3
0
def commit_command(db=None, what=None, why=None):
    """
    Used to a commit event to the database for other admins to know
    what is going on with the config.  The system logs quite a lot
    already for you, like your username, machine name, etc:

        m2sh commit -db test.sqlite -what mongrel2.org \
            -why "Needed to change paters."

    In future versions it will prevent you from committing as root,
    because only assholes commit from root.

    Both parameters are arbitrary, but I like to record what I did to
    different Hosts in servers.
    """
    import socket

    store = model.load_db("sqlite:" + db)
    who = str(getpass.getuser())

    if who == 'root':
        print("Commit from root eh?  Man, you're kind of a tool.")

    log = model.Log()
    log.who = who
    log.what = str(what)
    log.why = str(why)
    log.location = str(socket.gethostname())
    log.how = 'm2sh'

    store.add(log)
    store.commit()
Exemple #4
0
def log_command(db=None, count=20):
    """
    Dumps commit logs:

        m2sh log -db test.sqlite -count 20
        m2sh log -db test.sqlite

    So you know who to blame.
    """

    store = model.load_db("sqlite:" + db)
    logs = store.find(model.Log)

    for log in logs.order_by(model.Log.happened_at)[0:count]:
        print log
Exemple #5
0
def log_command(db=None, count=20):
    """
    Dumps commit logs:

        m2sh log -db test.sqlite -count 20
        m2sh log -db test.sqlite

    So you know who to blame.
    """

    store = model.load_db("sqlite:" + db)
    logs = store.find(model.Log)

    for log in logs.order_by(model.Log.happened_at)[0:count]:
        print(log)
Exemple #6
0
def get_server_pid(db, host):
    store = model.load_db("sqlite:" + db)
    results = store.find(model.Server, model.Server.default_host == unicode(host))

    if results.count() == 0:
        print "No servers found."
        return None

    server = results[0]
    pid_file = os.path.realpath(server.chroot + server.pid_file)

    if not os.path.isfile(pid_file):
        print "ERROR: PID file %s not found." % pid_file
        return None

    pid = int(open(pid_file, 'r').read())

    return pid
Exemple #7
0
def control_command(db=None, host="", name="", uuid=""):
    """
    Start a simple control console for working with mongrel2.
    This is *very* bare bones at the moment but should improve.

        m2sh control -db config.sqlite -uuid 3d815ade-9081-4c36-94dc-77a9b060b021
        m2sh control -db config.sqlite -host localhost
        m2sh control -db config.sqlite -name test
    """
    store = model.load_db("sqlite:" + db)
    import zmq

    servers = find_servers(db, uuid, host, name, False)

    if servers:
        server = servers[0]
        CTX = zmq.Context()

        results = store.find(model.Setting,
                             model.Setting.key == str("control_port"))
        addr = results[0].value if results.count() > 1 else "ipc://run/control"

        ctl = CTX.socket(zmq.REQ)

        print("CONNECTING to: %s in %s" % (addr, server.chroot))
        os.chdir(server.chroot)
        ctl.connect(addr)

        try:
            while True:
                cmd = input("> ")
                ctl.send(cmd.encode())
                print(ctl.recv())

        except EOFError:
            ctl.close()