neostorage.py 2.28 KB
Newer Older
1
#!/usr/bin/env python
2 3 4
#
# neostorage - run a storage node of NEO
#
Julien Muchembled's avatar
Julien Muchembled committed
5
# Copyright (C) 2006-2016  Nexedi SA
6
#
7 8 9 10
# 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.
11
#
12 13 14 15 16 17
# 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
18
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19

20
from neo.lib import logging
21
from neo.lib.config import getServerOptionParser, ConfigurationManager
22 23


24
parser = getServerOptionParser()
25 26
parser.add_option('-u', '--uuid', help='specify an UUID to use for this ' \
                  'process. Previously assigned UUID takes precedence (ie ' \
27
                  'you should always use --reset with this switch)')
28 29
parser.add_option('-a', '--adapter', help = 'database adapter to use')
parser.add_option('-d', '--database', help = 'database connections string')
30
parser.add_option('-e', '--engine', help = 'database engine')
31 32
parser.add_option('-w', '--wait', help='seconds to wait for backend to be '
    'available, before erroring-out (-1 = infinite)', type='float', default=0)
33 34
parser.add_option('--reset', action='store_true',
                  help='remove an existing database if any, and exit')
35 36

defaults = dict(
37
    bind = '127.0.0.1',
38 39 40 41 42
    masters = '127.0.0.1:10000',
    adapter = 'MySQL',
)

def main(args=None):
43 44 45
    # TODO: Forbid using "reset" along with any unneeded argument.
    #       "reset" is too dangerous to let user a chance of accidentally
    #       letting it slip through in a long option list.
Julien Muchembled's avatar
Julien Muchembled committed
46
    #       We should drop support configuration files to make such check useful.
47
    (options, args) = parser.parse_args(args=args)
48
    config = ConfigurationManager(defaults, options, 'storage')
49 50

    # setup custom logging
51
    logging.setup(config.getLogfile())
52 53 54 55

    # and then, load and run the application
    from neo.storage.app import Application
    app = Application(config)
56 57
    if not config.getReset():
        app.run()