cwctl.py
brancholdstable
changeset 8123 a4e667270dd4
parent 7815 2a164a9cf81c
child 7896 4c954e1e73ef
equal deleted inserted replaced
7863:d8bb8f631d41 8123:a4e667270dd4
   552             return
   552             return
   553         import signal
   553         import signal
   554         pid = int(open(pidf).read().strip())
   554         pid = int(open(pidf).read().strip())
   555         try:
   555         try:
   556             kill(pid, signal.SIGTERM)
   556             kill(pid, signal.SIGTERM)
   557         except:
   557         except Exception:
   558             print >> sys.stderr, "process %s seems already dead." % pid
   558             print >> sys.stderr, "process %s seems already dead." % pid
   559         else:
   559         else:
   560             try:
   560             try:
   561                 wait_process_end(pid)
   561                 wait_process_end(pid)
   562             except ExecutionError, ex:
   562             except ExecutionError, ex:
   563                 print >> sys.stderr, ex
   563                 print >> sys.stderr, ex
   564                 print >> sys.stderr, 'trying SIGKILL'
   564                 print >> sys.stderr, 'trying SIGKILL'
   565                 try:
   565                 try:
   566                     kill(pid, signal.SIGKILL)
   566                     kill(pid, signal.SIGKILL)
   567                 except:
   567                 except Exception:
   568                     # probably dead now
   568                     # probably dead now
   569                     pass
   569                     pass
   570                 wait_process_end(pid)
   570                 wait_process_end(pid)
   571         try:
   571         try:
   572             remove(pidf)
   572             remove(pidf)
   726         print '\n' + underline_title('Upgrading the instance %s' % appid)
   726         print '\n' + underline_title('Upgrading the instance %s' % appid)
   727         from logilab.common.changelog import Version
   727         from logilab.common.changelog import Version
   728         config = cwcfg.config_for(appid)
   728         config = cwcfg.config_for(appid)
   729         config.repairing = True # notice we're not starting the server
   729         config.repairing = True # notice we're not starting the server
   730         config.verbosity = self.config.verbosity
   730         config.verbosity = self.config.verbosity
   731         try:
   731         set_sources_mode = getattr(config, 'set_sources_mode', None)
   732             config.set_sources_mode(self.config.ext_sources or ('migration',))
   732         if set_sources_mode is not None:
   733         except AttributeError:
   733             set_sources_mode(self.config.ext_sources or ('migration',))
   734             # not a server config
       
   735             pass
       
   736         # get instance and installed versions for the server and the componants
   734         # get instance and installed versions for the server and the componants
   737         mih = config.migration_handler()
   735         mih = config.migration_handler()
   738         repo = mih.repo_connect()
   736         repo = mih.repo_connect()
   739         vcconf = repo.get_versions()
   737         vcconf = repo.get_versions()
   740         if self.config.force_cube_version:
   738         if self.config.force_cube_version:
   800                                'continue anyway?'):
   798                                'continue anyway?'):
   801                 print '-> migration not completed.'
   799                 print '-> migration not completed.'
   802                 return False
   800                 return False
   803         return True
   801         return True
   804 
   802 
       
   803 
       
   804 class ListVersionsInstanceCommand(InstanceCommand):
       
   805     """List versions used by an instance.
       
   806 
       
   807     <instance>...
       
   808       identifiers of the instances to list versions for.
       
   809     """
       
   810     name = 'versions'
       
   811 
       
   812     def versions_instance(self, appid):
       
   813         from logilab.common.changelog import Version
       
   814         config = cwcfg.config_for(appid)
       
   815         # should not raise error if db versions don't match fs versions
       
   816         config.repairing = True
       
   817         if hasattr(config, 'set_sources_mode'):
       
   818             config.set_sources_mode(('migration',))
       
   819         repo = config.migration_handler().repo_connect()
       
   820         vcconf = repo.get_versions()
       
   821         for key in sorted(vcconf):
       
   822             print key+': %s.%s.%s' % vcconf[key]
       
   823 
       
   824 
   805 class ShellCommand(Command):
   825 class ShellCommand(Command):
   806     """Run an interactive migration shell on an instance. This is a python shell
   826     """Run an interactive migration shell on an instance. This is a python shell
   807     with enhanced migration commands predefined in the namespace. An additional
   827     with enhanced migration commands predefined in the namespace. An additional
   808     argument may be given corresponding to a file containing commands to execute
   828     argument may be given corresponding to a file containing commands to execute
   809     in batch mode.
   829     in batch mode.
   962 for cmdcls in (ListCommand,
   982 for cmdcls in (ListCommand,
   963                CreateInstanceCommand, DeleteInstanceCommand,
   983                CreateInstanceCommand, DeleteInstanceCommand,
   964                StartInstanceCommand, StopInstanceCommand, RestartInstanceCommand,
   984                StartInstanceCommand, StopInstanceCommand, RestartInstanceCommand,
   965                ReloadConfigurationCommand, StatusCommand,
   985                ReloadConfigurationCommand, StatusCommand,
   966                UpgradeInstanceCommand,
   986                UpgradeInstanceCommand,
       
   987                ListVersionsInstanceCommand,
   967                ShellCommand,
   988                ShellCommand,
   968                RecompileInstanceCatalogsCommand,
   989                RecompileInstanceCatalogsCommand,
   969                ListInstancesCommand, ListCubesCommand,
   990                ListInstancesCommand, ListCubesCommand,
   970                ):
   991                ):
   971     CWCTL.register(cmdcls)
   992     CWCTL.register(cmdcls)