67 lines
1.9 KiB
Python
Executable File
67 lines
1.9 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
""" Script to start and stop mandaye server
|
|
"""
|
|
|
|
import logging
|
|
|
|
from optparse import OptionParser
|
|
|
|
from mandaye import config
|
|
from mandaye import server
|
|
|
|
def get_cmd_options():
|
|
usage = "usage: %prog [-d, --daemon] start|stop|createdb"
|
|
parser = OptionParser(usage=usage)
|
|
parser.add_option("--start",
|
|
dest="start",
|
|
default=False,
|
|
action="store_true",
|
|
help="Start Mandaye server"
|
|
)
|
|
parser.add_option("--stop",
|
|
dest="stop",
|
|
default=False,
|
|
action="store_true",
|
|
help="Stop the server"
|
|
)
|
|
parser.add_option("-d", "--daemon",
|
|
dest="daemon",
|
|
default=False,
|
|
action="store_true",
|
|
help="Daemonize the server"
|
|
)
|
|
parser.add_option("--createdb",
|
|
dest="createdb",
|
|
default=False,
|
|
action="store_true",
|
|
help="Create the Mandaye database"
|
|
)
|
|
(options, args) = parser.parse_args()
|
|
if options.start and options.stop:
|
|
parser.error("you can't use options start and stop at the same time")
|
|
if options.daemon and not options.start and not options.stop:
|
|
parser.error("You must use option start or stop")
|
|
if not options.start and not options.stop and not options.createdb:
|
|
parser.error("You must use option start | stop | createdb")
|
|
return options
|
|
|
|
def main():
|
|
options = get_cmd_options()
|
|
if options.createdb:
|
|
logging.info("Creating database...")
|
|
if config.db_url:
|
|
from mandaye.models import Base
|
|
from sqlalchemy import create_engine
|
|
engine = create_engine(config.db_url)
|
|
Base.metadata.create_all(engine)
|
|
print "Database created"
|
|
|
|
if options.start:
|
|
print "Starting Mandaye %s:%d .." % (config.host, config.port)
|
|
server.serve()
|
|
|
|
if __name__ == "__main__":
|
|
main()
|