author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 20 Apr 2010 10:00:55 +0200 | |
changeset 5336 | 7bf2d66418af |
parent 5323 | 329b4f6d18b4 |
child 5380 | a4e7e87d315f |
permissions | -rw-r--r-- |
4720
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
1 |
"""the cubicweb-ctl tool, based on logilab.common.clcommands to |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
2 |
provide a pluggable commands system. |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
3 |
|
0 | 4 |
|
4720
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
5 |
:organization: Logilab |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
6 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
7 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
8 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
9 |
""" |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
10 |
__docformat__ = "restructuredtext en" |
0 | 11 |
|
4718
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4684
diff
changeset
|
12 |
# *ctl module should limit the number of import to be imported as quickly as |
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4684
diff
changeset
|
13 |
# possible (for cubicweb-ctl reactivity, necessary for instance for usable bash |
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4684
diff
changeset
|
14 |
# completion). So import locally in command helpers. |
0 | 15 |
import sys |
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
16 |
from warnings import warn |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
diff
changeset
|
17 |
from os import remove, listdir, system, pathsep |
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
diff
changeset
|
18 |
try: |
3562 | 19 |
from os import kill, getpgid |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
diff
changeset
|
20 |
except ImportError: |
4721
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
21 |
def kill(*args): |
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
22 |
"""win32 kill implementation""" |
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
23 |
def getpgid(): |
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
24 |
"""win32 getpgid implementation""" |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
diff
changeset
|
25 |
|
4064
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
26 |
from os.path import exists, join, isfile, isdir, dirname, abspath |
0 | 27 |
|
1132 | 28 |
from logilab.common.clcommands import register_commands, pop_arg |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2532
diff
changeset
|
29 |
from logilab.common.shellutils import ASK |
1132 | 30 |
|
2790
968108e16066
move underline_title to toolsutils
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2743
diff
changeset
|
31 |
from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage |
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3619
diff
changeset
|
32 |
from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CWDEV, CONFIGURATIONS |
2790
968108e16066
move underline_title to toolsutils
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2743
diff
changeset
|
33 |
from cubicweb.toolsutils import Command, main_run, rm, create_dir, underline_title |
1446 | 34 |
|
0 | 35 |
def wait_process_end(pid, maxtry=10, waittime=1): |
36 |
"""wait for a process to actually die""" |
|
37 |
import signal |
|
38 |
from time import sleep |
|
39 |
nbtry = 0 |
|
40 |
while nbtry < maxtry: |
|
41 |
try: |
|
42 |
kill(pid, signal.SIGUSR1) |
|
3117
32686ae66c75
mostly adapt the i18n subsystem to limitation wrt redirection handinling in windows, using the -o argument of the utilities
Aurélien Campéas
parents:
3115
diff
changeset
|
43 |
except (OSError, AttributeError): # XXX win32 |
0 | 44 |
break |
45 |
nbtry += 1 |
|
46 |
sleep(waittime) |
|
47 |
else: |
|
48 |
raise ExecutionError('can\'t kill process %s' % pid) |
|
49 |
||
50 |
def list_instances(regdir): |
|
51 |
return sorted(idir for idir in listdir(regdir) if isdir(join(regdir, idir))) |
|
52 |
||
53 |
def detect_available_modes(templdir): |
|
54 |
modes = [] |
|
55 |
for fname in ('schema', 'schema.py'): |
|
56 |
if exists(join(templdir, fname)): |
|
57 |
modes.append('repository') |
|
58 |
break |
|
59 |
for fname in ('data', 'views', 'views.py'): |
|
60 |
if exists(join(templdir, fname)): |
|
61 |
modes.append('web ui') |
|
62 |
break |
|
63 |
return modes |
|
1446 | 64 |
|
65 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
66 |
class InstanceCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
67 |
"""base class for command taking 0 to n instance id as arguments |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
68 |
(0 meaning all registered instances) |
0 | 69 |
""" |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
70 |
arguments = '[<instance>...]' |
0 | 71 |
options = ( |
72 |
("force", |
|
73 |
{'short': 'f', 'action' : 'store_true', |
|
74 |
'default': False, |
|
75 |
'help': 'force command without asking confirmation', |
|
76 |
} |
|
77 |
), |
|
78 |
) |
|
79 |
actionverb = None |
|
1446 | 80 |
|
0 | 81 |
def ordered_instances(self): |
82 |
"""return instances in the order in which they should be started, |
|
83 |
considering $REGISTRY_DIR/startorder file if it exists (useful when |
|
3619
af81a4f7053e
enhance docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3562
diff
changeset
|
84 |
some instances depends on another as external source). |
af81a4f7053e
enhance docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3562
diff
changeset
|
85 |
|
af81a4f7053e
enhance docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3562
diff
changeset
|
86 |
Instance used by another one should appears first in the file (one |
af81a4f7053e
enhance docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3562
diff
changeset
|
87 |
instance per line) |
0 | 88 |
""" |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4798
diff
changeset
|
89 |
regdir = cwcfg.instances_dir() |
0 | 90 |
_allinstances = list_instances(regdir) |
91 |
if isfile(join(regdir, 'startorder')): |
|
92 |
allinstances = [] |
|
93 |
for line in file(join(regdir, 'startorder')): |
|
94 |
line = line.strip() |
|
95 |
if line and not line.startswith('#'): |
|
96 |
try: |
|
97 |
_allinstances.remove(line) |
|
98 |
allinstances.append(line) |
|
99 |
except ValueError: |
|
1132 | 100 |
print ('ERROR: startorder file contains unexistant ' |
101 |
'instance %s' % line) |
|
0 | 102 |
allinstances += _allinstances |
103 |
else: |
|
104 |
allinstances = _allinstances |
|
105 |
return allinstances |
|
1446 | 106 |
|
0 | 107 |
def run(self, args): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
108 |
"""run the <command>_method on each argument (a list of instance |
0 | 109 |
identifiers) |
110 |
""" |
|
111 |
if not args: |
|
112 |
args = self.ordered_instances() |
|
113 |
try: |
|
114 |
askconfirm = not self.config.force |
|
115 |
except AttributeError: |
|
116 |
# no force option |
|
117 |
askconfirm = False |
|
118 |
else: |
|
119 |
askconfirm = False |
|
120 |
self.run_args(args, askconfirm) |
|
1446 | 121 |
|
0 | 122 |
def run_args(self, args, askconfirm): |
123 |
for appid in args: |
|
124 |
if askconfirm: |
|
125 |
print '*'*72 |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
126 |
if not ASK.confirm('%s instance %r ?' % (self.name, appid)): |
0 | 127 |
continue |
128 |
self.run_arg(appid) |
|
1446 | 129 |
|
0 | 130 |
def run_arg(self, appid): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
131 |
cmdmeth = getattr(self, '%s_instance' % self.name) |
0 | 132 |
try: |
133 |
cmdmeth(appid) |
|
134 |
except (KeyboardInterrupt, SystemExit): |
|
135 |
print >> sys.stderr, '%s aborted' % self.name |
|
136 |
sys.exit(2) # specific error code |
|
137 |
except (ExecutionError, ConfigurationError), ex: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
138 |
print >> sys.stderr, 'instance %s not %s: %s' % ( |
0 | 139 |
appid, self.actionverb, ex) |
140 |
except Exception, ex: |
|
141 |
import traceback |
|
142 |
traceback.print_exc() |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
143 |
print >> sys.stderr, 'instance %s not %s: %s' % ( |
0 | 144 |
appid, self.actionverb, ex) |
145 |
||
146 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
147 |
class InstanceCommandFork(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
148 |
"""Same as `InstanceCommand`, but command is forked in a new environment |
0 | 149 |
for each argument |
150 |
""" |
|
151 |
||
152 |
def run_args(self, args, askconfirm): |
|
153 |
if len(args) > 1: |
|
154 |
forkcmd = ' '.join(w for w in sys.argv if not w in args) |
|
155 |
else: |
|
156 |
forkcmd = None |
|
157 |
for appid in args: |
|
158 |
if askconfirm: |
|
159 |
print '*'*72 |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
160 |
if not ASK.confirm('%s instance %r ?' % (self.name, appid)): |
0 | 161 |
continue |
162 |
if forkcmd: |
|
163 |
status = system('%s %s' % (forkcmd, appid)) |
|
164 |
if status: |
|
2156
fadb86b040a9
continue to run command on other instances, do not exit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2104
diff
changeset
|
165 |
print '%s exited with status %s' % (forkcmd, status) |
0 | 166 |
else: |
167 |
self.run_arg(appid) |
|
1446 | 168 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
169 |
|
0 | 170 |
# base commands ############################################################### |
171 |
||
172 |
class ListCommand(Command): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
173 |
"""List configurations, cubes and instances. |
0 | 174 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
175 |
list available configurations, installed cubes, and registered instances |
0 | 176 |
""" |
177 |
name = 'list' |
|
178 |
options = ( |
|
179 |
('verbose', |
|
1446 | 180 |
{'short': 'v', 'action' : 'store_true', |
181 |
'help': "display more information."}), |
|
0 | 182 |
) |
1446 | 183 |
|
0 | 184 |
def run(self, args): |
185 |
"""run the command with its specific arguments""" |
|
186 |
if args: |
|
187 |
raise BadCommandUsage('Too much arguments') |
|
5027
d688daf0a62c
[config] move ConfigurationProblem to migration + refactor it to benefit from config methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5026
diff
changeset
|
188 |
from cubicweb.migration import ConfigurationProblem |
3486
ea6bf6f9ba0c
[cwctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3198
diff
changeset
|
189 |
print 'CubicWeb %s (%s mode)' % (cwcfg.cubicweb_version(), cwcfg.mode) |
0 | 190 |
print |
191 |
print 'Available configurations:' |
|
192 |
for config in CONFIGURATIONS: |
|
193 |
print '*', config.name |
|
194 |
for line in config.__doc__.splitlines(): |
|
195 |
line = line.strip() |
|
196 |
if not line: |
|
197 |
continue |
|
198 |
print ' ', line |
|
1446 | 199 |
print |
5027
d688daf0a62c
[config] move ConfigurationProblem to migration + refactor it to benefit from config methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5026
diff
changeset
|
200 |
cfgpb = ConfigurationProblem(cwcfg) |
0 | 201 |
try: |
1342
4273e44852cb
no more cubes_dir class method
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
202 |
cubesdir = pathsep.join(cwcfg.cubes_search_path()) |
1132 | 203 |
namesize = max(len(x) for x in cwcfg.available_cubes()) |
0 | 204 |
except ConfigurationError, ex: |
205 |
print 'No cubes available:', ex |
|
206 |
except ValueError: |
|
207 |
print 'No cubes available in %s' % cubesdir |
|
208 |
else: |
|
209 |
print 'Available cubes (%s):' % cubesdir |
|
1132 | 210 |
for cube in cwcfg.available_cubes(): |
0 | 211 |
try: |
1132 | 212 |
tinfo = cwcfg.cube_pkginfo(cube) |
0 | 213 |
tversion = tinfo.version |
5027
d688daf0a62c
[config] move ConfigurationProblem to migration + refactor it to benefit from config methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5026
diff
changeset
|
214 |
cfgpb.add_cube(cube, tversion) |
0 | 215 |
except ConfigurationError: |
216 |
tinfo = None |
|
217 |
tversion = '[missing cube information]' |
|
218 |
print '* %s %s' % (cube.ljust(namesize), tversion) |
|
219 |
if self.config.verbose: |
|
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
220 |
if tinfo: |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
221 |
descr = getattr(tinfo, 'description', '') |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
222 |
if not descr: |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
223 |
descr = getattr(tinfo, 'short_desc', '') |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
224 |
if descr: |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
225 |
warn('[3.8] short_desc is deprecated, update %s' |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
226 |
' pkginfo' % cube, DeprecationWarning) |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
227 |
else: |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
228 |
descr = tinfo.__doc__ |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
229 |
if descr: |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
230 |
print ' '+ ' \n'.join(descr.splitlines()) |
2024
82128fe6798c
redo juj's fix in stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1898
diff
changeset
|
231 |
modes = detect_available_modes(cwcfg.cube_dir(cube)) |
0 | 232 |
print ' available modes: %s' % ', '.join(modes) |
233 |
print |
|
234 |
try: |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4798
diff
changeset
|
235 |
regdir = cwcfg.instances_dir() |
0 | 236 |
except ConfigurationError, ex: |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
237 |
print 'No instance available:', ex |
0 | 238 |
print |
239 |
return |
|
240 |
instances = list_instances(regdir) |
|
241 |
if instances: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
242 |
print 'Available instances (%s):' % regdir |
0 | 243 |
for appid in instances: |
1132 | 244 |
modes = cwcfg.possible_configurations(appid) |
0 | 245 |
if not modes: |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
246 |
print '* %s (BROKEN instance, no configuration found)' % appid |
0 | 247 |
continue |
248 |
print '* %s (%s)' % (appid, ', '.join(modes)) |
|
249 |
try: |
|
1132 | 250 |
config = cwcfg.config_for(appid, modes[0]) |
1446 | 251 |
except Exception, exc: |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
252 |
print ' (BROKEN instance, %s)' % exc |
0 | 253 |
continue |
254 |
else: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
255 |
print 'No instance available in %s' % regdir |
0 | 256 |
print |
4656
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
257 |
# configuration management problem solving |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
258 |
cfgpb.solve() |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
259 |
if cfgpb.warnings: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
260 |
print 'Warnings:\n', '\n'.join('* '+txt for txt in cfgpb.warnings) |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
261 |
if cfgpb.errors: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
262 |
print 'Errors:' |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
263 |
for op, cube, version in cfgpb.errors: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
264 |
if op == 'add': |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
265 |
print '* cube', cube, |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
266 |
if version: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
267 |
print ' version', version, |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
268 |
print 'is not installed, but required by %s' % ' '.join(cfgpb.reverse_constraints[cube]) |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
269 |
else: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
270 |
print '* cube %s version %s is installed, but version %s is required by (%s)' % ( |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
271 |
cube, cfgpb.cubes[cube].version, version, ', '.join(cfgpb.reverse_constraints[cube])) |
0 | 272 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
273 |
class CreateInstanceCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
274 |
"""Create an instance from a cube. This is an unified |
0 | 275 |
command which can handle web / server / all-in-one installation |
276 |
according to available parts of the software library and of the |
|
277 |
desired cube. |
|
278 |
||
279 |
<cube> |
|
280 |
the name of cube to use (list available cube names using |
|
281 |
the "list" command). You can use several cubes by separating |
|
282 |
them using comma (e.g. 'jpl,eemail') |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
283 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
284 |
an identifier for the instance to create |
0 | 285 |
""" |
286 |
name = 'create' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
287 |
arguments = '<cube> <instance>' |
0 | 288 |
options = ( |
289 |
("config-level", |
|
290 |
{'short': 'l', 'type' : 'int', 'metavar': '<level>', |
|
291 |
'default': 0, |
|
292 |
'help': 'configuration level (0..2): 0 will ask for essential \ |
|
293 |
configuration parameters only while 2 will ask for all parameters', |
|
294 |
} |
|
295 |
), |
|
296 |
("config", |
|
297 |
{'short': 'c', 'type' : 'choice', 'metavar': '<install type>', |
|
298 |
'choices': ('all-in-one', 'repository', 'twisted'), |
|
299 |
'default': 'all-in-one', |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
300 |
'help': 'installation type, telling which part of an instance \ |
0 | 301 |
should be installed. You can list available configurations using the "list" \ |
302 |
command. Default to "all-in-one", e.g. an installation embedding both the RQL \ |
|
303 |
repository and the web server.', |
|
304 |
} |
|
305 |
), |
|
306 |
) |
|
1446 | 307 |
|
0 | 308 |
def run(self, args): |
309 |
"""run the command with its specific arguments""" |
|
2633
bc9386c3b2c9
get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2615
diff
changeset
|
310 |
from logilab.common.textutils import splitstrip |
0 | 311 |
configname = self.config.config |
2633
bc9386c3b2c9
get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2615
diff
changeset
|
312 |
cubes = splitstrip(pop_arg(args, 1)) |
0 | 313 |
appid = pop_arg(args) |
314 |
# get the configuration and helper |
|
1132 | 315 |
config = cwcfg.config_for(appid, configname) |
0 | 316 |
config.set_language = False |
2104
b4ffcea3275b
change cubes into expanded cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2032
diff
changeset
|
317 |
cubes = config.expand_cubes(cubes) |
b4ffcea3275b
change cubes into expanded cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2032
diff
changeset
|
318 |
config.init_cubes(cubes) |
0 | 319 |
helper = self.config_helper(config) |
320 |
# check the cube exists |
|
321 |
try: |
|
1132 | 322 |
templdirs = [cwcfg.cube_dir(cube) |
0 | 323 |
for cube in cubes] |
324 |
except ConfigurationError, ex: |
|
325 |
print ex |
|
326 |
print '\navailable cubes:', |
|
1132 | 327 |
print ', '.join(cwcfg.available_cubes()) |
0 | 328 |
return |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
329 |
# create the registry directory for this instance |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
330 |
print '\n'+underline_title('Creating the instance %s' % appid) |
0 | 331 |
create_dir(config.apphome) |
332 |
# cubicweb-ctl configuration |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
333 |
print '\n'+underline_title('Configuring the instance (%s.conf)' % configname) |
0 | 334 |
config.input_config('main', self.config.config_level) |
335 |
# configuration'specific stuff |
|
336 |
print |
|
337 |
helper.bootstrap(cubes, self.config.config_level) |
|
4610
7bf205b9a845
when creating an instance, ask for cubes specific options properly (fix #607349)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4609
diff
changeset
|
338 |
# input for cubes specific options |
7bf205b9a845
when creating an instance, ask for cubes specific options properly (fix #607349)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4609
diff
changeset
|
339 |
for section in set(sect.lower() for sect, opt, optdict in config.all_options() |
5323
329b4f6d18b4
[config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5302
diff
changeset
|
340 |
if optdict.get('level') <= self.config.config_level): |
4610
7bf205b9a845
when creating an instance, ask for cubes specific options properly (fix #607349)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4609
diff
changeset
|
341 |
if section not in ('main', 'email', 'pyro'): |
7bf205b9a845
when creating an instance, ask for cubes specific options properly (fix #607349)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4609
diff
changeset
|
342 |
print '\n' + underline_title('%s options' % section) |
7bf205b9a845
when creating an instance, ask for cubes specific options properly (fix #607349)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4609
diff
changeset
|
343 |
config.input_config(section, self.config.config_level) |
0 | 344 |
# write down configuration |
345 |
config.save() |
|
4064
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
346 |
self._handle_win32(config, appid) |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2318
diff
changeset
|
347 |
print '-> generated %s' % config.main_config_file() |
0 | 348 |
# handle i18n files structure |
349 |
# in the first cube given |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2318
diff
changeset
|
350 |
print '-> preparing i18n catalogs' |
4021
280c910c8710
move i18n / migration modules from cw.common to cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3720
diff
changeset
|
351 |
from cubicweb import i18n |
0 | 352 |
langs = [lang for lang, _ in i18n.available_catalogs(join(templdirs[0], 'i18n'))] |
353 |
errors = config.i18ncompile(langs) |
|
354 |
if errors: |
|
355 |
print '\n'.join(errors) |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
356 |
if not ASK.confirm('error while compiling message catalogs, ' |
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
357 |
'continue anyway ?'): |
0 | 358 |
print 'creation not completed' |
359 |
return |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
360 |
# create the additional data directory for this instance |
0 | 361 |
if config.appdatahome != config.apphome: # true in dev mode |
362 |
create_dir(config.appdatahome) |
|
2489
37a747ad6fd4
#344772: instance backups should be done in instance_data_dir
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
363 |
create_dir(join(config.appdatahome, 'backup')) |
0 | 364 |
if config['uid']: |
365 |
from logilab.common.shellutils import chown |
|
366 |
# this directory should be owned by the uid of the server process |
|
367 |
print 'set %s as owner of the data directory' % config['uid'] |
|
368 |
chown(config.appdatahome, config['uid']) |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2318
diff
changeset
|
369 |
print '\n-> creation done for %r.\n' % config.apphome |
0 | 370 |
helper.postcreate() |
371 |
||
4064
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
372 |
def _handle_win32(self, config, appid): |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
373 |
if sys.platform != 'win32': |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
374 |
return |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
375 |
service_template = """ |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
376 |
import sys |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
377 |
import win32serviceutil |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
378 |
sys.path.insert(0, r"%(CWPATH)s") |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
379 |
|
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
380 |
from cubicweb.etwist.service import CWService |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
381 |
|
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
382 |
classdict = {'_svc_name_': 'cubicweb-%(APPID)s', |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
383 |
'_svc_display_name_': 'CubicWeb ' + '%(CNAME)s', |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
384 |
'instance': '%(APPID)s'} |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
385 |
%(CNAME)sService = type('%(CNAME)sService', (CWService,), classdict) |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
386 |
|
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
387 |
if __name__ == '__main__': |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
388 |
win32serviceutil.HandleCommandLine(%(CNAME)sService) |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
389 |
""" |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
390 |
open(join(config.apphome, 'win32svc.py'), 'wb').write( |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
391 |
service_template % {'APPID': appid, |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
392 |
'CNAME': appid.capitalize(), |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
393 |
'CWPATH': abspath(join(dirname(__file__), '..'))}) |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
394 |
|
1446 | 395 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
396 |
class DeleteInstanceCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
397 |
"""Delete an instance. Will remove instance's files and |
0 | 398 |
unregister it. |
399 |
""" |
|
400 |
name = 'delete' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
401 |
arguments = '<instance>' |
1446 | 402 |
|
0 | 403 |
options = () |
404 |
||
405 |
def run(self, args): |
|
406 |
"""run the command with its specific arguments""" |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
407 |
appid = pop_arg(args, msg="No instance specified !") |
1132 | 408 |
configs = [cwcfg.config_for(appid, configname) |
409 |
for configname in cwcfg.possible_configurations(appid)] |
|
0 | 410 |
if not configs: |
411 |
raise ExecutionError('unable to guess configuration for %s' % appid) |
|
412 |
for config in configs: |
|
413 |
helper = self.config_helper(config, required=False) |
|
414 |
if helper: |
|
415 |
helper.cleanup() |
|
416 |
# remove home |
|
417 |
rm(config.apphome) |
|
418 |
# remove instance data directory |
|
419 |
try: |
|
420 |
rm(config.appdatahome) |
|
421 |
except OSError, ex: |
|
422 |
import errno |
|
423 |
if ex.errno != errno.ENOENT: |
|
424 |
raise |
|
425 |
confignames = ', '.join([config.name for config in configs]) |
|
2532
f7ca29d75183
[cleanup] improve dialog message consistency
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2512
diff
changeset
|
426 |
print '-> instance %s (%s) deleted.' % (appid, confignames) |
0 | 427 |
|
428 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
429 |
# instance commands ######################################################## |
0 | 430 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
431 |
class StartInstanceCommand(InstanceCommandFork): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
432 |
"""Start the given instances. If no instance is given, start them all. |
1446 | 433 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
434 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
435 |
identifiers of the instances to start. If no instance is |
0 | 436 |
given, start them all. |
437 |
""" |
|
438 |
name = 'start' |
|
439 |
actionverb = 'started' |
|
440 |
options = ( |
|
441 |
("debug", |
|
442 |
{'short': 'D', 'action' : 'store_true', |
|
443 |
'help': 'start server in debug mode.'}), |
|
444 |
("force", |
|
445 |
{'short': 'f', 'action' : 'store_true', |
|
446 |
'default': False, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
447 |
'help': 'start the instance even if it seems to be already \ |
0 | 448 |
running.'}), |
449 |
('profile', |
|
450 |
{'short': 'P', 'type' : 'string', 'metavar': '<stat file>', |
|
451 |
'default': None, |
|
452 |
'help': 'profile code and use the specified file to store stats', |
|
453 |
}), |
|
2654
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
454 |
('loglevel', |
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
455 |
{'short': 'l', 'type' : 'choice', 'metavar': '<log level>', |
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
456 |
'default': None, 'choices': ('debug', 'info', 'warning', 'error'), |
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
457 |
'help': 'debug if -D is set, error otherwise', |
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
458 |
}), |
0 | 459 |
) |
460 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
461 |
def start_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
462 |
"""start the instance's server""" |
3182 | 463 |
debug = self['debug'] |
464 |
force = self['force'] |
|
465 |
loglevel = self['loglevel'] |
|
1132 | 466 |
config = cwcfg.config_for(appid) |
2654
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
467 |
if loglevel is not None: |
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
468 |
loglevel = 'LOG_%s' % loglevel.upper() |
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
469 |
config.global_set_option('log-threshold', loglevel) |
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
470 |
config.init_log(loglevel, debug=debug, force=True) |
3182 | 471 |
if self['profile']: |
0 | 472 |
config.global_set_option('profile', self.config.profile) |
473 |
helper = self.config_helper(config, cmdname='start') |
|
474 |
pidf = config['pid-file'] |
|
475 |
if exists(pidf) and not force: |
|
476 |
msg = "%s seems to be running. Remove %s by hand if necessary or use \ |
|
477 |
the --force option." |
|
478 |
raise ExecutionError(msg % (appid, pidf)) |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
479 |
helper.start_server(config, debug) |
0 | 480 |
|
481 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
482 |
class StopInstanceCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
483 |
"""Stop the given instances. |
1446 | 484 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
485 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
486 |
identifiers of the instances to stop. If no instance is |
0 | 487 |
given, stop them all. |
488 |
""" |
|
489 |
name = 'stop' |
|
490 |
actionverb = 'stopped' |
|
1446 | 491 |
|
0 | 492 |
def ordered_instances(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
493 |
instances = super(StopInstanceCommand, self).ordered_instances() |
0 | 494 |
instances.reverse() |
495 |
return instances |
|
1446 | 496 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
497 |
def stop_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
498 |
"""stop the instance's server""" |
1132 | 499 |
config = cwcfg.config_for(appid) |
0 | 500 |
helper = self.config_helper(config, cmdname='stop') |
501 |
helper.poststop() # do this anyway |
|
502 |
pidf = config['pid-file'] |
|
503 |
if not exists(pidf): |
|
504 |
print >> sys.stderr, "%s doesn't exist." % pidf |
|
505 |
return |
|
506 |
import signal |
|
507 |
pid = int(open(pidf).read().strip()) |
|
508 |
try: |
|
509 |
kill(pid, signal.SIGTERM) |
|
510 |
except: |
|
511 |
print >> sys.stderr, "process %s seems already dead." % pid |
|
512 |
else: |
|
513 |
try: |
|
514 |
wait_process_end(pid) |
|
515 |
except ExecutionError, ex: |
|
516 |
print >> sys.stderr, ex |
|
517 |
print >> sys.stderr, 'trying SIGKILL' |
|
518 |
try: |
|
519 |
kill(pid, signal.SIGKILL) |
|
520 |
except: |
|
521 |
# probably dead now |
|
522 |
pass |
|
523 |
wait_process_end(pid) |
|
524 |
try: |
|
525 |
remove(pidf) |
|
526 |
except OSError: |
|
527 |
# already removed by twistd |
|
528 |
pass |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
529 |
print 'instance %s stopped' % appid |
1446 | 530 |
|
0 | 531 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
532 |
class RestartInstanceCommand(StartInstanceCommand): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
533 |
"""Restart the given instances. |
1446 | 534 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
535 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
536 |
identifiers of the instances to restart. If no instance is |
0 | 537 |
given, restart them all. |
538 |
""" |
|
539 |
name = 'restart' |
|
540 |
actionverb = 'restarted' |
|
541 |
||
542 |
def run_args(self, args, askconfirm): |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4798
diff
changeset
|
543 |
regdir = cwcfg.instances_dir() |
0 | 544 |
if not isfile(join(regdir, 'startorder')) or len(args) <= 1: |
545 |
# no specific startorder |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
546 |
super(RestartInstanceCommand, self).run_args(args, askconfirm) |
0 | 547 |
return |
548 |
print ('some specific start order is specified, will first stop all ' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
549 |
'instances then restart them.') |
0 | 550 |
# get instances in startorder |
551 |
for appid in args: |
|
552 |
if askconfirm: |
|
553 |
print '*'*72 |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
554 |
if not ASK.confirm('%s instance %r ?' % (self.name, appid)): |
0 | 555 |
continue |
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
556 |
StopInstanceCommand().stop_instance(appid) |
0 | 557 |
forkcmd = [w for w in sys.argv if not w in args] |
558 |
forkcmd[1] = 'start' |
|
559 |
forkcmd = ' '.join(forkcmd) |
|
560 |
for appid in reversed(args): |
|
561 |
status = system('%s %s' % (forkcmd, appid)) |
|
562 |
if status: |
|
563 |
sys.exit(status) |
|
1446 | 564 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
565 |
def restart_instance(self, appid): |
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
566 |
StopInstanceCommand().stop_instance(appid) |
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
567 |
self.start_instance(appid) |
0 | 568 |
|
1446 | 569 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
570 |
class ReloadConfigurationCommand(RestartInstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
571 |
"""Reload the given instances. This command is equivalent to a |
0 | 572 |
restart for now. |
1446 | 573 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
574 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
575 |
identifiers of the instances to reload. If no instance is |
0 | 576 |
given, reload them all. |
577 |
""" |
|
578 |
name = 'reload' |
|
1446 | 579 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
580 |
def reload_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
581 |
self.restart_instance(appid) |
1446 | 582 |
|
0 | 583 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
584 |
class StatusCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
585 |
"""Display status information about the given instances. |
1446 | 586 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
587 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
588 |
identifiers of the instances to status. If no instance is |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
589 |
given, get status information about all registered instances. |
0 | 590 |
""" |
591 |
name = 'status' |
|
592 |
options = () |
|
593 |
||
1132 | 594 |
@staticmethod |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
595 |
def status_instance(appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
596 |
"""print running status information for an instance""" |
1132 | 597 |
for mode in cwcfg.possible_configurations(appid): |
598 |
config = cwcfg.config_for(appid, mode) |
|
0 | 599 |
print '[%s-%s]' % (appid, mode), |
600 |
try: |
|
601 |
pidf = config['pid-file'] |
|
602 |
except KeyError: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
603 |
print 'buggy instance, pid file not specified' |
0 | 604 |
continue |
605 |
if not exists(pidf): |
|
606 |
print "doesn't seem to be running" |
|
607 |
continue |
|
608 |
pid = int(open(pidf).read().strip()) |
|
609 |
# trick to guess whether or not the process is running |
|
610 |
try: |
|
611 |
getpgid(pid) |
|
612 |
except OSError: |
|
613 |
print "should be running with pid %s but the process can not be found" % pid |
|
614 |
continue |
|
615 |
print "running with pid %s" % (pid) |
|
616 |
||
617 |
||
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
618 |
class UpgradeInstanceCommand(InstanceCommandFork): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
619 |
"""Upgrade an instance after cubicweb and/or component(s) upgrade. |
0 | 620 |
|
621 |
For repository update, you will be prompted for a login / password to use |
|
622 |
to connect to the system database. For some upgrades, the given user |
|
623 |
should have create or alter table permissions. |
|
624 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
625 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
626 |
identifiers of the instances to upgrade. If no instance is |
0 | 627 |
given, upgrade them all. |
628 |
""" |
|
629 |
name = 'upgrade' |
|
630 |
actionverb = 'upgraded' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
631 |
options = InstanceCommand.options + ( |
0 | 632 |
('force-componant-version', |
633 |
{'short': 't', 'type' : 'csv', 'metavar': 'cube1=X.Y.Z,cube2=X.Y.Z', |
|
634 |
'default': None, |
|
635 |
'help': 'force migration from the indicated version for the specified cube.'}), |
|
636 |
('force-cubicweb-version', |
|
637 |
{'short': 'e', 'type' : 'string', 'metavar': 'X.Y.Z', |
|
638 |
'default': None, |
|
639 |
'help': 'force migration from the indicated cubicweb version.'}), |
|
1446 | 640 |
|
0 | 641 |
('fs-only', |
642 |
{'short': 's', 'action' : 'store_true', |
|
643 |
'default': False, |
|
644 |
'help': 'only upgrade files on the file system, not the database.'}), |
|
645 |
||
646 |
('nostartstop', |
|
647 |
{'short': 'n', 'action' : 'store_true', |
|
648 |
'default': False, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
649 |
'help': 'don\'t try to stop instance before migration and to restart it after.'}), |
1446 | 650 |
|
0 | 651 |
('verbosity', |
652 |
{'short': 'v', 'type' : 'int', 'metavar': '<0..2>', |
|
653 |
'default': 1, |
|
654 |
'help': "0: no confirmation, 1: only main commands confirmed, 2 ask \ |
|
655 |
for everything."}), |
|
1446 | 656 |
|
0 | 657 |
('backup-db', |
658 |
{'short': 'b', 'type' : 'yn', 'metavar': '<y or n>', |
|
659 |
'default': None, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
660 |
'help': "Backup the instance database before upgrade.\n"\ |
0 | 661 |
"If the option is ommitted, confirmation will be ask.", |
662 |
}), |
|
663 |
||
664 |
('ext-sources', |
|
665 |
{'short': 'E', 'type' : 'csv', 'metavar': '<sources>', |
|
666 |
'default': None, |
|
667 |
'help': "For multisources instances, specify to which sources the \ |
|
668 |
repository should connect to for upgrading. When unspecified or 'migration' is \ |
|
669 |
given, appropriate sources for migration will be automatically selected \ |
|
670 |
(recommended). If 'all' is given, will connect to all defined sources.", |
|
671 |
}), |
|
672 |
) |
|
673 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
674 |
def upgrade_instance(self, appid): |
2512
106b2a05dc88
[cleanup] started to improve cubicweb-ctl dialog messages consistency
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2489
diff
changeset
|
675 |
print '\n' + underline_title('Upgrading the instance %s' % appid) |
0 | 676 |
from logilab.common.changelog import Version |
1132 | 677 |
config = cwcfg.config_for(appid) |
2473
490f88fb99b6
new distinguish repairing/creating from regular start.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2395
diff
changeset
|
678 |
config.repairing = True # notice we're not starting the server |
0 | 679 |
config.verbosity = self.config.verbosity |
1219
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
680 |
try: |
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
681 |
config.set_sources_mode(self.config.ext_sources or ('migration',)) |
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
682 |
except AttributeError: |
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
683 |
# not a server config |
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
684 |
pass |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
685 |
# get instance and installed versions for the server and the componants |
0 | 686 |
mih = config.migration_handler() |
687 |
repo = mih.repo_connect() |
|
688 |
vcconf = repo.get_versions() |
|
689 |
if self.config.force_componant_version: |
|
690 |
packversions = {} |
|
691 |
for vdef in self.config.force_componant_version: |
|
692 |
componant, version = vdef.split('=') |
|
693 |
packversions[componant] = Version(version) |
|
694 |
vcconf.update(packversions) |
|
695 |
toupgrade = [] |
|
696 |
for cube in config.cubes(): |
|
697 |
installedversion = config.cube_version(cube) |
|
698 |
try: |
|
699 |
applversion = vcconf[cube] |
|
700 |
except KeyError: |
|
701 |
config.error('no version information for %s' % cube) |
|
702 |
continue |
|
703 |
if installedversion > applversion: |
|
704 |
toupgrade.append( (cube, applversion, installedversion) ) |
|
1446 | 705 |
cubicwebversion = config.cubicweb_version() |
0 | 706 |
if self.config.force_cubicweb_version: |
707 |
applcubicwebversion = Version(self.config.force_cubicweb_version) |
|
708 |
vcconf['cubicweb'] = applcubicwebversion |
|
709 |
else: |
|
710 |
applcubicwebversion = vcconf.get('cubicweb') |
|
711 |
if cubicwebversion > applcubicwebversion: |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2156
diff
changeset
|
712 |
toupgrade.append(('cubicweb', applcubicwebversion, cubicwebversion)) |
0 | 713 |
if not self.config.fs_only and not toupgrade: |
2512
106b2a05dc88
[cleanup] started to improve cubicweb-ctl dialog messages consistency
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2489
diff
changeset
|
714 |
print '-> no software migration needed for instance %s.' % appid |
0 | 715 |
return |
716 |
for cube, fromversion, toversion in toupgrade: |
|
2532
f7ca29d75183
[cleanup] improve dialog message consistency
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2512
diff
changeset
|
717 |
print '-> migration needed from %s to %s for %s' % (fromversion, toversion, cube) |
1404
971b19de6b85
stop application only once we're sure we've something to do, fixing #342689
sylvain.thenault@logilab.fr
parents:
1219
diff
changeset
|
718 |
# only stop once we're sure we have something to do |
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3619
diff
changeset
|
719 |
if not (CWDEV or self.config.nostartstop): |
3188
34395d1f00d6
[c-c] fix 3.4.9 name error :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3182
diff
changeset
|
720 |
StopInstanceCommand().stop_instance(appid) |
0 | 721 |
# run cubicweb/componants migration scripts |
722 |
mih.migrate(vcconf, reversed(toupgrade), self.config) |
|
723 |
# rewrite main configuration file |
|
724 |
mih.rewrite_configuration() |
|
725 |
# handle i18n upgrade: |
|
726 |
# * install new languages |
|
727 |
# * recompile catalogs |
|
5092
e126becc1263
[upgrade] after upgrade, fork command to start instance avoid grave uicfg pb (explicit rules all removed...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5043
diff
changeset
|
728 |
# XXX search available language in the first cube given |
4021
280c910c8710
move i18n / migration modules from cw.common to cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3720
diff
changeset
|
729 |
from cubicweb import i18n |
1132 | 730 |
templdir = cwcfg.cube_dir(config.cubes()[0]) |
0 | 731 |
langs = [lang for lang, _ in i18n.available_catalogs(join(templdir, 'i18n'))] |
732 |
errors = config.i18ncompile(langs) |
|
733 |
if errors: |
|
734 |
print '\n'.join(errors) |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
735 |
if not ASK.confirm('Error while compiling message catalogs, ' |
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
736 |
'continue anyway ?'): |
2512
106b2a05dc88
[cleanup] started to improve cubicweb-ctl dialog messages consistency
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2489
diff
changeset
|
737 |
print '-> migration not completed.' |
0 | 738 |
return |
739 |
mih.shutdown() |
|
740 |
print |
|
2512
106b2a05dc88
[cleanup] started to improve cubicweb-ctl dialog messages consistency
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2489
diff
changeset
|
741 |
print '-> instance migrated.' |
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3619
diff
changeset
|
742 |
if not (CWDEV or self.config.nostartstop): |
5092
e126becc1263
[upgrade] after upgrade, fork command to start instance avoid grave uicfg pb (explicit rules all removed...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5043
diff
changeset
|
743 |
# restart instance through fork to get a proper environment, avoid |
e126becc1263
[upgrade] after upgrade, fork command to start instance avoid grave uicfg pb (explicit rules all removed...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5043
diff
changeset
|
744 |
# uicfg pb (and probably gettext catalogs, to check...) |
e126becc1263
[upgrade] after upgrade, fork command to start instance avoid grave uicfg pb (explicit rules all removed...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5043
diff
changeset
|
745 |
forkcmd = '%s start %s' % (sys.argv[0], appid) |
e126becc1263
[upgrade] after upgrade, fork command to start instance avoid grave uicfg pb (explicit rules all removed...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5043
diff
changeset
|
746 |
status = system(forkcmd) |
e126becc1263
[upgrade] after upgrade, fork command to start instance avoid grave uicfg pb (explicit rules all removed...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5043
diff
changeset
|
747 |
if status: |
e126becc1263
[upgrade] after upgrade, fork command to start instance avoid grave uicfg pb (explicit rules all removed...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5043
diff
changeset
|
748 |
print '%s exited with status %s' % (forkcmd, status) |
0 | 749 |
print |
750 |
||
751 |
||
752 |
class ShellCommand(Command): |
|
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
753 |
"""Run an interactive migration shell on an instance. This is a python shell |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
754 |
with enhanced migration commands predefined in the namespace. An additional |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
755 |
argument may be given corresponding to a file containing commands to execute |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
756 |
in batch mode. |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
757 |
|
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
758 |
By default it will connect to a local instance using an in memory |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
759 |
connection, unless -P option is specified, in which case you will be |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
760 |
connected through pyro. In the later case, you won't have access to |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
761 |
repository internals (session, etc...) so most migration commands won't be |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
762 |
available. |
0 | 763 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
764 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
765 |
the identifier of the instance to connect. |
0 | 766 |
""" |
767 |
name = 'shell' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
768 |
arguments = '<instance> [batch command file]' |
0 | 769 |
options = ( |
770 |
('system-only', |
|
771 |
{'short': 'S', 'action' : 'store_true', |
|
772 |
'help': 'only connect to the system source when the instance is ' |
|
773 |
'using multiple sources. You can\'t use this option and the ' |
|
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
774 |
'--ext-sources option at the same time.', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
775 |
'group': 'local' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
776 |
}), |
1446 | 777 |
|
0 | 778 |
('ext-sources', |
779 |
{'short': 'E', 'type' : 'csv', 'metavar': '<sources>', |
|
780 |
'help': "For multisources instances, specify to which sources the \ |
|
781 |
repository should connect to for upgrading. When unspecified or 'all' given, \ |
|
782 |
will connect to all defined sources. If 'migration' is given, appropriate \ |
|
783 |
sources for migration will be automatically selected.", |
|
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
784 |
'group': 'local' |
0 | 785 |
}), |
1446 | 786 |
|
2905
b23bbb31368c
backport change from default to get -f option on cw shell, may be necessary for the forthcoming migration...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2743
diff
changeset
|
787 |
('force', |
b23bbb31368c
backport change from default to get -f option on cw shell, may be necessary for the forthcoming migration...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2743
diff
changeset
|
788 |
{'short': 'f', 'action' : 'store_true', |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
789 |
'help': 'don\'t check instance is up to date.', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
790 |
'group': 'local' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
791 |
}), |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
792 |
|
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
793 |
('pyro', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
794 |
{'short': 'P', 'action' : 'store_true', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
795 |
'help': 'connect to a running instance through Pyro.', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
796 |
'group': 'remote', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
797 |
}), |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
798 |
('pyro-ns-host', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
799 |
{'short': 'H', 'type' : 'string', 'metavar': '<host[:port]>', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
800 |
'help': 'Pyro name server host. If not set, will be detected by ' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
801 |
'using a broadcast query.', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
802 |
'group': 'remote' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
803 |
}), |
0 | 804 |
) |
2905
b23bbb31368c
backport change from default to get -f option on cw shell, may be necessary for the forthcoming migration...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2743
diff
changeset
|
805 |
|
0 | 806 |
def run(self, args): |
4524
2eb36514ad6d
[cw-shell] do not set arbitrary limit on number of arguments
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4064
diff
changeset
|
807 |
appid = pop_arg(args, None, msg="No instance specified !") |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
808 |
if self.config.pyro: |
3707
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
809 |
from cubicweb import AuthenticationError |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
810 |
from cubicweb.dbapi import connect |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
811 |
from cubicweb.server.utils import manager_userpasswd |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
812 |
from cubicweb.server.migractions import ServerMigrationHelper |
3707
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
813 |
while True: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
814 |
try: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
815 |
login, pwd = manager_userpasswd(msg=None) |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
816 |
cnx = connect(appid, login=login, password=pwd, |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
817 |
host=self.config.pyro_ns_host, mulcnx=False) |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
818 |
except AuthenticationError, ex: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
819 |
print ex |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
820 |
except (KeyboardInterrupt, EOFError): |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
821 |
print |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
822 |
sys.exit(0) |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
823 |
else: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
824 |
break |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
825 |
cnx.load_appobjects() |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
826 |
repo = cnx._repo |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
827 |
mih = ServerMigrationHelper(None, repo=repo, cnx=cnx, |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
828 |
# hack so it don't try to load fs schema |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
829 |
schema=1) |
0 | 830 |
else: |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
831 |
config = cwcfg.config_for(appid) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
832 |
if self.config.ext_sources: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
833 |
assert not self.config.system_only |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
834 |
sources = self.config.ext_sources |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
835 |
elif self.config.system_only: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
836 |
sources = ('system',) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
837 |
else: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
838 |
sources = ('all',) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
839 |
config.set_sources_mode(sources) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
840 |
config.repairing = self.config.force |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
841 |
mih = config.migration_handler() |
3709
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
842 |
try: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
843 |
if args: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
844 |
for arg in args: |
3715
e3ccadb126d7
[shell] make process_script available throuhg c-c shell / migration script context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3709
diff
changeset
|
845 |
mih.cmd_process_script(arg) |
3709
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
846 |
else: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
847 |
mih.interactive_shell() |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
848 |
finally: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
849 |
if not self.config.pyro: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
850 |
mih.shutdown() |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
851 |
else: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
852 |
cnx.close() |
0 | 853 |
|
854 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
855 |
class RecompileInstanceCatalogsCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
856 |
"""Recompile i18n catalogs for instances. |
1446 | 857 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
858 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
859 |
identifiers of the instances to consider. If no instance is |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
860 |
given, recompile for all registered instances. |
0 | 861 |
""" |
1898
39b37f90a8a4
[cw-ctl] rename i18n commands (see #342889)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1477
diff
changeset
|
862 |
name = 'i18ninstance' |
1132 | 863 |
|
864 |
@staticmethod |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
865 |
def i18ninstance_instance(appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
866 |
"""recompile instance's messages catalogs""" |
1132 | 867 |
config = cwcfg.config_for(appid) |
5043
fe52dd3936cf
[repo config] cleanup read_instance_schema / bootstrap_schema / creating mess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5042
diff
changeset
|
868 |
config.quick_start = True # notify this is not a regular start |
5042
cc062bb09abb
fix #726167: i18ninstance use data in bootstrab_cubes instead of the database one
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4798
diff
changeset
|
869 |
repo = config.repository() |
cc062bb09abb
fix #726167: i18ninstance use data in bootstrab_cubes instead of the database one
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4798
diff
changeset
|
870 |
if config._cubes is None: |
0 | 871 |
# web only config |
5042
cc062bb09abb
fix #726167: i18ninstance use data in bootstrab_cubes instead of the database one
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4798
diff
changeset
|
872 |
config.init_cubes(repo.get_cubes()) |
0 | 873 |
errors = config.i18ncompile() |
874 |
if errors: |
|
875 |
print '\n'.join(errors) |
|
876 |
||
877 |
||
878 |
class ListInstancesCommand(Command): |
|
879 |
"""list available instances, useful for bash completion.""" |
|
880 |
name = 'listinstances' |
|
881 |
hidden = True |
|
1446 | 882 |
|
0 | 883 |
def run(self, args): |
884 |
"""run the command with its specific arguments""" |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4798
diff
changeset
|
885 |
regdir = cwcfg.instances_dir() |
0 | 886 |
for appid in sorted(listdir(regdir)): |
887 |
print appid |
|
888 |
||
889 |
||
890 |
class ListCubesCommand(Command): |
|
891 |
"""list available componants, useful for bash completion.""" |
|
892 |
name = 'listcubes' |
|
893 |
hidden = True |
|
1446 | 894 |
|
0 | 895 |
def run(self, args): |
896 |
"""run the command with its specific arguments""" |
|
1132 | 897 |
for cube in cwcfg.available_cubes(): |
0 | 898 |
print cube |
899 |
||
900 |
register_commands((ListCommand, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
901 |
CreateInstanceCommand, |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
902 |
DeleteInstanceCommand, |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
903 |
StartInstanceCommand, |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
904 |
StopInstanceCommand, |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
905 |
RestartInstanceCommand, |
0 | 906 |
ReloadConfigurationCommand, |
907 |
StatusCommand, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
908 |
UpgradeInstanceCommand, |
0 | 909 |
ShellCommand, |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
910 |
RecompileInstanceCatalogsCommand, |
0 | 911 |
ListInstancesCommand, ListCubesCommand, |
912 |
)) |
|
913 |
||
1446 | 914 |
|
0 | 915 |
def run(args): |
916 |
"""command line tool""" |
|
1132 | 917 |
cwcfg.load_cwctl_plugins() |
4720
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
918 |
main_run(args, """%%prog %s [options] %s |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
919 |
|
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
920 |
The CubicWeb swiss-knife. |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
921 |
|
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
922 |
%s""" |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
923 |
) |
0 | 924 |
|
925 |
if __name__ == '__main__': |
|
926 |
run(sys.argv[1:]) |