neomaster 2.21 KB
Newer Older
Yoshinori Okuji's avatar
Yoshinori Okuji committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#! /usr/bin/env python
#
# neomaster - run a master node of NEO
#
# Copyright (C) 2006  Nexedi SA
# 
# 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.
# 
# 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
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

from optparse import OptionParser
22
from neo import setupLog
23
from neo.util import bin
Yoshinori Okuji's avatar
Yoshinori Okuji committed
24 25

parser = OptionParser()
Yoshinori Okuji's avatar
Yoshinori Okuji committed
26 27
parser.add_option('-v', '--verbose', action = 'store_true', 
                  help = 'print verbose messages')
28 29 30 31 32 33 34
parser.add_option('-u', '--uuid', help='the node UUID (testing purpose)')
parser.add_option('-n', '--name', help = 'the node name (impove logging)')
parser.add_option('-b', '--bind', help = 'the local address to bind to')
parser.add_option('-c', '--cluster', help = 'the cluster name')
parser.add_option('-m', '--masters', help = 'master node list')
parser.add_option('-r', '--replicas', help = 'replicas number')
parser.add_option('-p', '--partitions', help = 'partitions number')
Aurel's avatar
Aurel committed
35
parser.add_option('-l', '--logfile', help = 'specify a logging file')
Yoshinori Okuji's avatar
Yoshinori Okuji committed
36

37
# build configuration dict from command line options
Yoshinori Okuji's avatar
Yoshinori Okuji committed
38
(options, args) = parser.parse_args()
39 40 41 42 43 44 45 46 47 48 49
config = {
    'uuid': options.uuid,
    'bind': options.bind or '127.0.0.1:10000',
    'cluster': options.cluster,
    'masters': options.masters or '',
    'replicas': options.replicas or 0,
    'partitions': options.partitions or 100,
}
config['uuid'] = bin(config['uuid'])
config['replicas'] = int(config['replicas'])
config['partitions'] = int(config['partitions'])
Yoshinori Okuji's avatar
Yoshinori Okuji committed
50

51 52
# setup custom logging
setupLog(options.name or 'master', options.logfile or None, options.verbose)
Yoshinori Okuji's avatar
Yoshinori Okuji committed
53

54
# and then, load and run the application
55
from neo.master.app import Application
56
app = Application(**config)
Yoshinori Okuji's avatar
Yoshinori Okuji committed
57
app.run()