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