15 # |
15 # |
16 # You should have received a copy of the GNU Lesser General Public License along |
16 # You should have received a copy of the GNU Lesser General Public License along |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 """the cubicweb-ctl tool, based on logilab.common.clcommands to |
18 """the cubicweb-ctl tool, based on logilab.common.clcommands to |
19 provide a pluggable commands system. |
19 provide a pluggable commands system. |
20 |
|
21 |
|
22 """ |
20 """ |
|
21 |
23 __docformat__ = "restructuredtext en" |
22 __docformat__ = "restructuredtext en" |
24 |
23 |
25 # *ctl module should limit the number of import to be imported as quickly as |
24 # *ctl module should limit the number of import to be imported as quickly as |
26 # possible (for cubicweb-ctl reactivity, necessary for instance for usable bash |
25 # possible (for cubicweb-ctl reactivity, necessary for instance for usable bash |
27 # completion). So import locally in command helpers. |
26 # completion). So import locally in command helpers. |
475 }), |
474 }), |
476 ) |
475 ) |
477 |
476 |
478 def start_instance(self, appid): |
477 def start_instance(self, appid): |
479 """start the instance's server""" |
478 """start the instance's server""" |
480 force = self['force'] |
|
481 loglevel = self['loglevel'] |
|
482 config = cwcfg.config_for(appid, debugmode=self['debug']) |
479 config = cwcfg.config_for(appid, debugmode=self['debug']) |
483 if loglevel is not None: |
480 init_cmdline_log_threshold(config, self['loglevel']) |
484 loglevel = 'LOG_%s' % loglevel.upper() |
|
485 config.global_set_option('log-threshold', loglevel) |
|
486 config.init_log(loglevel, force=True) |
|
487 if self['profile']: |
481 if self['profile']: |
488 config.global_set_option('profile', self.config.profile) |
482 config.global_set_option('profile', self.config.profile) |
489 helper = self.config_helper(config, cmdname='start') |
483 helper = self.config_helper(config, cmdname='start') |
490 pidf = config['pid-file'] |
484 pidf = config['pid-file'] |
491 if exists(pidf) and not force: |
485 if exists(pidf) and not self['force']: |
492 msg = "%s seems to be running. Remove %s by hand if necessary or use \ |
486 msg = "%s seems to be running. Remove %s by hand if necessary or use \ |
493 the --force option." |
487 the --force option." |
494 raise ExecutionError(msg % (appid, pidf)) |
488 raise ExecutionError(msg % (appid, pidf)) |
495 helper.start_server(config) |
489 helper.start_server(config) |
|
490 |
|
491 |
|
492 def init_cmdline_log_threshold(config, loglevel): |
|
493 if loglevel is not None: |
|
494 config.global_set_option('log-threshold', loglevel.upper()) |
|
495 config.init_log(config['log-threshold'], force=True) |
496 |
496 |
497 |
497 |
498 class StopInstanceCommand(InstanceCommand): |
498 class StopInstanceCommand(InstanceCommand): |
499 """Stop the given instances. |
499 """Stop the given instances. |
500 |
500 |