cwctl.py
changeset 9511 241b1232ed7f
parent 9372 e87a808a4c32
child 9556 12ee310541bb
equal deleted inserted replaced
9510:a5231a557ac0 9511:241b1232ed7f
   779             StopInstanceCommand(self.logger).stop_instance(appid)
   779             StopInstanceCommand(self.logger).stop_instance(appid)
   780         # run cubicweb/componants migration scripts
   780         # run cubicweb/componants migration scripts
   781         if self.config.fs_only or toupgrade:
   781         if self.config.fs_only or toupgrade:
   782             for cube, fromversion, toversion in toupgrade:
   782             for cube, fromversion, toversion in toupgrade:
   783                 print '-> migration needed from %s to %s for %s' % (fromversion, toversion, cube)
   783                 print '-> migration needed from %s to %s for %s' % (fromversion, toversion, cube)
   784             mih.migrate(vcconf, reversed(toupgrade), self.config)
   784             with mih.cnx:
       
   785                 mih.migrate(vcconf, reversed(toupgrade), self.config)
   785         else:
   786         else:
   786             print '-> no data migration needed for instance %s.' % appid
   787             print '-> no data migration needed for instance %s.' % appid
   787         # rewrite main configuration file
   788         # rewrite main configuration file
   788         mih.rewrite_configuration()
   789         mih.rewrite_configuration()
   789         mih.shutdown()
   790         mih.shutdown()
   910         return mih, lambda: mih.shutdown()
   911         return mih, lambda: mih.shutdown()
   911 
   912 
   912     def _handle_networked(self, appuri):
   913     def _handle_networked(self, appuri):
   913         """ returns migration context handler & shutdown function """
   914         """ returns migration context handler & shutdown function """
   914         from cubicweb import AuthenticationError
   915         from cubicweb import AuthenticationError
   915         from cubicweb.dbapi import connect
   916         from cubicweb.repoapi import connect, get_repository
   916         from cubicweb.server.utils import manager_userpasswd
   917         from cubicweb.server.utils import manager_userpasswd
   917         from cubicweb.server.migractions import ServerMigrationHelper
   918         from cubicweb.server.migractions import ServerMigrationHelper
   918         while True:
   919         while True:
   919             try:
   920             try:
   920                 login, pwd = manager_userpasswd(msg=None)
   921                 login, pwd = manager_userpasswd(msg=None)
   921                 cnx = connect(appuri, login=login, password=pwd, mulcnx=False)
   922                 repo = get_repository(appuri)
       
   923                 cnx = connect(repo, login=login, password=pwd, mulcnx=False)
   922             except AuthenticationError as ex:
   924             except AuthenticationError as ex:
   923                 print ex
   925                 print ex
   924             except (KeyboardInterrupt, EOFError):
   926             except (KeyboardInterrupt, EOFError):
   925                 print
   927                 print
   926                 sys.exit(0)
   928                 sys.exit(0)
   946         if protocol == 'inmemory':
   948         if protocol == 'inmemory':
   947             mih, shutdown_callback = self._handle_inmemory(appid)
   949             mih, shutdown_callback = self._handle_inmemory(appid)
   948         else:
   950         else:
   949             mih, shutdown_callback = self._handle_networked(appuri)
   951             mih, shutdown_callback = self._handle_networked(appuri)
   950         try:
   952         try:
   951             if args:
   953             with mih.cnx:
   952                 # use cmdline parser to access left/right attributes only
   954                 if args:
   953                 # remember that usage requires instance appid as first argument
   955                     # use cmdline parser to access left/right attributes only
   954                 scripts, args = self.cmdline_parser.largs[1:], self.cmdline_parser.rargs
   956                     # remember that usage requires instance appid as first argument
   955                 for script in scripts:
   957                     scripts, args = self.cmdline_parser.largs[1:], self.cmdline_parser.rargs
   956                     mih.cmd_process_script(script, scriptargs=args)
   958                     for script in scripts:
   957                     mih.commit()
   959                             mih.cmd_process_script(script, scriptargs=args)
   958             else:
   960                             mih.commit()
   959                 mih.interactive_shell()
   961                 else:
       
   962                     mih.interactive_shell()
   960         finally:
   963         finally:
   961             shutdown_callback()
   964             shutdown_callback()
   962 
   965 
   963 
   966 
   964 class RecompileInstanceCatalogsCommand(InstanceCommand):
   967 class RecompileInstanceCatalogsCommand(InstanceCommand):