cwctl.py
changeset 2654 6512522860aa
parent 2633 bc9386c3b2c9
child 2743 b0e79a77ad67
equal deleted inserted replaced
2653:51bf32bbe78d 2654:6512522860aa
   380         ('profile',
   380         ('profile',
   381          {'short': 'P', 'type' : 'string', 'metavar': '<stat file>',
   381          {'short': 'P', 'type' : 'string', 'metavar': '<stat file>',
   382           'default': None,
   382           'default': None,
   383           'help': 'profile code and use the specified file to store stats',
   383           'help': 'profile code and use the specified file to store stats',
   384           }),
   384           }),
       
   385         ('loglevel',
       
   386          {'short': 'l', 'type' : 'choice', 'metavar': '<log level>',
       
   387           'default': None, 'choices': ('debug', 'info', 'warning', 'error'),
       
   388           'help': 'debug if -D is set, error otherwise',
       
   389           }),
   385         )
   390         )
   386 
   391 
   387     def start_instance(self, appid):
   392     def start_instance(self, appid):
   388         """start the instance's server"""
   393         """start the instance's server"""
   389         # use get() since start may be used from other commands (eg upgrade)
   394         # use get() since start may be used from other commands (eg upgrade)
   390         # without all options defined
   395         # without all options defined
   391         debug = self.get('debug')
   396         debug = self.get('debug')
   392         force = self.get('force')
   397         force = self.get('force')
       
   398         loglevel = self.get('loglevel')
   393         config = cwcfg.config_for(appid)
   399         config = cwcfg.config_for(appid)
       
   400         if loglevel is not None:
       
   401             loglevel = 'LOG_%s' % loglevel.upper()
       
   402             config.global_set_option('log-threshold', loglevel)
       
   403             config.init_log(loglevel, debug=debug, force=True)
   394         if self.get('profile'):
   404         if self.get('profile'):
   395             config.global_set_option('profile', self.config.profile)
   405             config.global_set_option('profile', self.config.profile)
   396         helper = self.config_helper(config, cmdname='start')
   406         helper = self.config_helper(config, cmdname='start')
   397         pidf = config['pid-file']
   407         pidf = config['pid-file']
   398         if exists(pidf) and not force:
   408         if exists(pidf) and not force:
   399             msg = "%s seems to be running. Remove %s by hand if necessary or use \
   409             msg = "%s seems to be running. Remove %s by hand if necessary or use \
   400 the --force option."
   410 the --force option."
   401             raise ExecutionError(msg % (appid, pidf))
   411             raise ExecutionError(msg % (appid, pidf))
   402         command = helper.start_command(config, debug)
   412         helper.start_command(config, debug)
   403         if debug:
       
   404             print "starting server with command :"
       
   405             print command
       
   406         if system(command):
       
   407             print 'an error occured while starting the instance, not started'
       
   408             print
       
   409             return False
       
   410         if not debug:
       
   411             print '-> instance %s started.' % appid
       
   412         return True
   413         return True
   413 
   414 
   414 
   415 
   415 class StopInstanceCommand(InstanceCommand):
   416 class StopInstanceCommand(InstanceCommand):
   416     """Stop the given instances.
   417     """Stop the given instances.