36 |
36 |
37 from cubicweb import AuthenticationError, ExecutionError, ConfigurationError |
37 from cubicweb import AuthenticationError, ExecutionError, ConfigurationError |
38 from cubicweb.toolsutils import Command, CommandHandler, underline_title |
38 from cubicweb.toolsutils import Command, CommandHandler, underline_title |
39 from cubicweb.cwctl import CWCTL, check_options_consistency, ConfigureInstanceCommand |
39 from cubicweb.cwctl import CWCTL, check_options_consistency, ConfigureInstanceCommand |
40 from cubicweb.server import SOURCE_TYPES |
40 from cubicweb.server import SOURCE_TYPES |
41 from cubicweb.server.repository import Repository |
|
42 from cubicweb.server.serverconfig import ( |
41 from cubicweb.server.serverconfig import ( |
43 USER_OPTIONS, ServerConfiguration, SourceConfiguration, |
42 USER_OPTIONS, ServerConfiguration, SourceConfiguration, |
44 ask_source_config, generate_source_config) |
43 ask_source_config, generate_source_config) |
45 |
44 |
46 # utility functions ########################################################### |
45 # utility functions ########################################################### |
674 cnx.commit() |
673 cnx.commit() |
675 print '-> password reset, sources file regenerated.' |
674 print '-> password reset, sources file regenerated.' |
676 cnx.close() |
675 cnx.close() |
677 |
676 |
678 |
677 |
679 class StartRepositoryCommand(Command): |
|
680 """Start a CubicWeb RQL server for a given instance. |
|
681 |
|
682 The server will be remotely accessible through ZMQ |
|
683 |
|
684 <instance> |
|
685 the identifier of the instance to initialize. |
|
686 """ |
|
687 name = 'start-repository' |
|
688 arguments = '<instance>' |
|
689 min_args = max_args = 1 |
|
690 options = ( |
|
691 ('debug', |
|
692 {'short': 'D', 'action' : 'store_true', |
|
693 'help': 'start server in debug mode.'}), |
|
694 ('loglevel', |
|
695 {'short': 'l', 'type' : 'choice', 'metavar': '<log level>', |
|
696 'default': None, 'choices': ('debug', 'info', 'warning', 'error'), |
|
697 'help': 'debug if -D is set, error otherwise', |
|
698 }), |
|
699 ('address', |
|
700 {'short': 'a', 'type': 'string', 'metavar': '<protocol>://<host>:<port>', |
|
701 'default': '', |
|
702 'help': ('specify a ZMQ URI on which to bind'), |
|
703 }), |
|
704 ) |
|
705 |
|
706 def create_repo(self, config): |
|
707 address = self['address'] |
|
708 if not address: |
|
709 address = config.get('zmq-repository-address') |
|
710 from cubicweb.server.utils import TasksManager |
|
711 from cubicweb.server.cwzmq import ZMQRepositoryServer |
|
712 repo = Repository(config, TasksManager()) |
|
713 return ZMQRepositoryServer(repo), address |
|
714 |
|
715 def run(self, args): |
|
716 from logilab.common.daemon import daemonize, setugid |
|
717 from cubicweb.cwctl import init_cmdline_log_threshold |
|
718 print 'WARNING: Standalone repository with pyro or zmq access is deprecated' |
|
719 appid = args[0] |
|
720 debug = self['debug'] |
|
721 if sys.platform == 'win32' and not debug: |
|
722 logger = logging.getLogger('cubicweb.ctl') |
|
723 logger.info('Forcing debug mode on win32 platform') |
|
724 debug = True |
|
725 config = ServerConfiguration.config_for(appid, debugmode=debug) |
|
726 init_cmdline_log_threshold(config, self['loglevel']) |
|
727 # create the server |
|
728 server, address = self.create_repo(config) |
|
729 # ensure the directory where the pid-file should be set exists (for |
|
730 # instance /var/run/cubicweb may be deleted on computer restart) |
|
731 pidfile = config['pid-file'] |
|
732 piddir = os.path.dirname(pidfile) |
|
733 # go ! (don't daemonize in debug mode) |
|
734 if not os.path.exists(piddir): |
|
735 os.makedirs(piddir) |
|
736 if not debug and daemonize(pidfile, umask=config['umask']): |
|
737 return |
|
738 uid = config['uid'] |
|
739 if uid is not None: |
|
740 setugid(uid) |
|
741 server.install_sig_handlers() |
|
742 server.connect(address) |
|
743 server.run() |
|
744 |
|
745 |
678 |
746 def _remote_dump(host, appid, output, sudo=False): |
679 def _remote_dump(host, appid, output, sudo=False): |
747 # XXX generate unique/portable file name |
680 # XXX generate unique/portable file name |
748 from datetime import date |
681 from datetime import date |
749 filename = '%s-%s.tgz' % (appid, date.today().strftime('%Y-%m-%d')) |
682 filename = '%s-%s.tgz' % (appid, date.today().strftime('%Y-%m-%d')) |
1123 schema_diff(fsschema, repo.schema, permissionshandler, diff_tool, ignore=('eid',)) |
1056 schema_diff(fsschema, repo.schema, permissionshandler, diff_tool, ignore=('eid',)) |
1124 |
1057 |
1125 |
1058 |
1126 for cmdclass in (CreateInstanceDBCommand, InitInstanceCommand, |
1059 for cmdclass in (CreateInstanceDBCommand, InitInstanceCommand, |
1127 GrantUserOnInstanceCommand, ResetAdminPasswordCommand, |
1060 GrantUserOnInstanceCommand, ResetAdminPasswordCommand, |
1128 StartRepositoryCommand, |
|
1129 DBDumpCommand, DBRestoreCommand, DBCopyCommand, |
1061 DBDumpCommand, DBRestoreCommand, DBCopyCommand, |
1130 AddSourceCommand, CheckRepositoryCommand, RebuildFTICommand, |
1062 AddSourceCommand, CheckRepositoryCommand, RebuildFTICommand, |
1131 SynchronizeSourceCommand, SchemaDiffCommand, |
1063 SynchronizeSourceCommand, SchemaDiffCommand, |
1132 ): |
1064 ): |
1133 CWCTL.register(cmdclass) |
1065 CWCTL.register(cmdclass) |