150 status = system('%s %s' % (forkcmd, appid)) |
150 status = system('%s %s' % (forkcmd, appid)) |
151 if status: |
151 if status: |
152 print '%s exited with status %s' % (forkcmd, status) |
152 print '%s exited with status %s' % (forkcmd, status) |
153 else: |
153 else: |
154 self.run_arg(appid) |
154 self.run_arg(appid) |
|
155 |
155 |
156 |
156 # base commands ############################################################### |
157 # base commands ############################################################### |
157 |
158 |
158 class ListCommand(Command): |
159 class ListCommand(Command): |
159 """List configurations, cubes and instances. |
160 """List configurations, cubes and instances. |
364 print '-> instance %s (%s) deleted.' % (appid, confignames) |
365 print '-> instance %s (%s) deleted.' % (appid, confignames) |
365 |
366 |
366 |
367 |
367 # instance commands ######################################################## |
368 # instance commands ######################################################## |
368 |
369 |
369 class StartInstanceCommand(InstanceCommand): |
370 class StartInstanceCommand(InstanceCommandFork): |
370 """Start the given instances. If no instance is given, start them all. |
371 """Start the given instances. If no instance is given, start them all. |
371 |
372 |
372 <instance>... |
373 <instance>... |
373 identifiers of the instances to start. If no instance is |
374 identifiers of the instances to start. If no instance is |
374 given, start them all. |
375 given, start them all. |
396 }), |
397 }), |
397 ) |
398 ) |
398 |
399 |
399 def start_instance(self, appid): |
400 def start_instance(self, appid): |
400 """start the instance's server""" |
401 """start the instance's server""" |
401 # use get() since start may be used from other commands (eg upgrade) |
402 debug = self['debug'] |
402 # without all options defined |
403 force = self['force'] |
403 debug = self.get('debug') |
404 loglevel = self['loglevel'] |
404 force = self.get('force') |
|
405 loglevel = self.get('loglevel') |
|
406 config = cwcfg.config_for(appid) |
405 config = cwcfg.config_for(appid) |
407 if loglevel is not None: |
406 if loglevel is not None: |
408 loglevel = 'LOG_%s' % loglevel.upper() |
407 loglevel = 'LOG_%s' % loglevel.upper() |
409 config.global_set_option('log-threshold', loglevel) |
408 config.global_set_option('log-threshold', loglevel) |
410 config.init_log(loglevel, debug=debug, force=True) |
409 config.init_log(loglevel, debug=debug, force=True) |
411 if self.get('profile'): |
410 if self['profile']: |
412 config.global_set_option('profile', self.config.profile) |
411 config.global_set_option('profile', self.config.profile) |
413 helper = self.config_helper(config, cmdname='start') |
412 helper = self.config_helper(config, cmdname='start') |
414 pidf = config['pid-file'] |
413 pidf = config['pid-file'] |
415 if exists(pidf) and not force: |
414 if exists(pidf) and not force: |
416 msg = "%s seems to be running. Remove %s by hand if necessary or use \ |
415 msg = "%s seems to be running. Remove %s by hand if necessary or use \ |
417 the --force option." |
416 the --force option." |
418 raise ExecutionError(msg % (appid, pidf)) |
417 raise ExecutionError(msg % (appid, pidf)) |
419 helper.start_command(config, debug) |
418 helper.start_server(config, debug) |
420 return True |
419 if not debug: |
|
420 # in debug mode, we reach this point once the instance is stopped... |
|
421 print 'instance %s %s' % (appid, self.actionverb) |
421 |
422 |
422 |
423 |
423 class StopInstanceCommand(InstanceCommand): |
424 class StopInstanceCommand(InstanceCommand): |
424 """Stop the given instances. |
425 """Stop the given instances. |
425 |
426 |
468 # already removed by twistd |
469 # already removed by twistd |
469 pass |
470 pass |
470 print 'instance %s stopped' % appid |
471 print 'instance %s stopped' % appid |
471 |
472 |
472 |
473 |
473 class RestartInstanceCommand(StartInstanceCommand, |
474 class RestartInstanceCommand(StartInstanceCommand): |
474 StopInstanceCommand): |
|
475 """Restart the given instances. |
475 """Restart the given instances. |
476 |
476 |
477 <instance>... |
477 <instance>... |
478 identifiers of the instances to restart. If no instance is |
478 identifiers of the instances to restart. If no instance is |
479 given, restart them all. |
479 given, restart them all. |
488 super(RestartInstanceCommand, self).run_args(args, askconfirm) |
488 super(RestartInstanceCommand, self).run_args(args, askconfirm) |
489 return |
489 return |
490 print ('some specific start order is specified, will first stop all ' |
490 print ('some specific start order is specified, will first stop all ' |
491 'instances then restart them.') |
491 'instances then restart them.') |
492 # get instances in startorder |
492 # get instances in startorder |
493 stopped = [] |
|
494 for appid in args: |
493 for appid in args: |
495 if askconfirm: |
494 if askconfirm: |
496 print '*'*72 |
495 print '*'*72 |
497 if not ASK.confirm('%s instance %r ?' % (self.name, appid)): |
496 if not ASK.confirm('%s instance %r ?' % (self.name, appid)): |
498 continue |
497 continue |
499 self.stop_instance(appid) |
498 StopInstanceCommand().stop_instance(appid) |
500 stopped.append(appid) |
|
501 forkcmd = [w for w in sys.argv if not w in args] |
499 forkcmd = [w for w in sys.argv if not w in args] |
502 forkcmd[1] = 'start' |
500 forkcmd[1] = 'start' |
503 forkcmd = ' '.join(forkcmd) |
501 forkcmd = ' '.join(forkcmd) |
504 for appid in reversed(args): |
502 for appid in reversed(args): |
505 status = system('%s %s' % (forkcmd, appid)) |
503 status = system('%s %s' % (forkcmd, appid)) |
506 if status: |
504 if status: |
507 sys.exit(status) |
505 sys.exit(status) |
508 |
506 |
509 def restart_instance(self, appid): |
507 def restart_instance(self, appid): |
510 self.stop_instance(appid) |
508 StopInstanceCommand().stop_instance(appid) |
511 if self.start_instance(appid): |
509 self.start_instance(appid) |
512 print 'instance %s %s' % (appid, self.actionverb) |
|
513 |
510 |
514 |
511 |
515 class ReloadConfigurationCommand(RestartInstanceCommand): |
512 class ReloadConfigurationCommand(RestartInstanceCommand): |
516 """Reload the given instances. This command is equivalent to a |
513 """Reload the given instances. This command is equivalent to a |
517 restart for now. |
514 restart for now. |
558 print "should be running with pid %s but the process can not be found" % pid |
555 print "should be running with pid %s but the process can not be found" % pid |
559 continue |
556 continue |
560 print "running with pid %s" % (pid) |
557 print "running with pid %s" % (pid) |
561 |
558 |
562 |
559 |
563 class UpgradeInstanceCommand(InstanceCommandFork, |
560 class UpgradeInstanceCommand(InstanceCommandFork): |
564 StartInstanceCommand, |
|
565 StopInstanceCommand): |
|
566 """Upgrade an instance after cubicweb and/or component(s) upgrade. |
561 """Upgrade an instance after cubicweb and/or component(s) upgrade. |
567 |
562 |
568 For repository update, you will be prompted for a login / password to use |
563 For repository update, you will be prompted for a login / password to use |
569 to connect to the system database. For some upgrades, the given user |
564 to connect to the system database. For some upgrades, the given user |
570 should have create or alter table permissions. |
565 should have create or alter table permissions. |
615 repository should connect to for upgrading. When unspecified or 'migration' is \ |
610 repository should connect to for upgrading. When unspecified or 'migration' is \ |
616 given, appropriate sources for migration will be automatically selected \ |
611 given, appropriate sources for migration will be automatically selected \ |
617 (recommended). If 'all' is given, will connect to all defined sources.", |
612 (recommended). If 'all' is given, will connect to all defined sources.", |
618 }), |
613 }), |
619 ) |
614 ) |
620 |
|
621 def ordered_instances(self): |
|
622 # need this since mro return StopInstanceCommand implementation |
|
623 return InstanceCommand.ordered_instances(self) |
|
624 |
615 |
625 def upgrade_instance(self, appid): |
616 def upgrade_instance(self, appid): |
626 print '\n' + underline_title('Upgrading the instance %s' % appid) |
617 print '\n' + underline_title('Upgrading the instance %s' % appid) |
627 from logilab.common.changelog import Version |
618 from logilab.common.changelog import Version |
628 config = cwcfg.config_for(appid) |
619 config = cwcfg.config_for(appid) |
666 return |
657 return |
667 for cube, fromversion, toversion in toupgrade: |
658 for cube, fromversion, toversion in toupgrade: |
668 print '-> migration needed from %s to %s for %s' % (fromversion, toversion, cube) |
659 print '-> migration needed from %s to %s for %s' % (fromversion, toversion, cube) |
669 # only stop once we're sure we have something to do |
660 # only stop once we're sure we have something to do |
670 if not (cwcfg.mode == 'dev' or self.config.nostartstop): |
661 if not (cwcfg.mode == 'dev' or self.config.nostartstop): |
671 self.stop_instance(appid) |
662 StopCommand().stop_instance(appid) |
672 # run cubicweb/componants migration scripts |
663 # run cubicweb/componants migration scripts |
673 mih.migrate(vcconf, reversed(toupgrade), self.config) |
664 mih.migrate(vcconf, reversed(toupgrade), self.config) |
674 # rewrite main configuration file |
665 # rewrite main configuration file |
675 mih.rewrite_configuration() |
666 mih.rewrite_configuration() |
676 # handle i18n upgrade: |
667 # handle i18n upgrade: |