author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 17 Feb 2010 13:11:30 +0100 | |
branch | stable |
changeset 4609 | 169ca2904322 |
parent 4525 | 956a0630abc8 |
child 4610 | 7bf205b9a845 |
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 |
# cubicweb-ctl configuration |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
301 |
print '\n'+underline_title('Configuring the instance (%s.conf)' % configname) |
0 | 302 |
config.input_config('main', self.config.config_level) |
303 |
# configuration'specific stuff |
|
304 |
print |
|
305 |
helper.bootstrap(cubes, self.config.config_level) |
|
306 |
# write down configuration |
|
307 |
config.save() |
|
4064
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
308 |
self._handle_win32(config, appid) |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2318
diff
changeset
|
309 |
print '-> generated %s' % config.main_config_file() |
0 | 310 |
# handle i18n files structure |
311 |
# in the first cube given |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2318
diff
changeset
|
312 |
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
|
313 |
from cubicweb import i18n |
0 | 314 |
langs = [lang for lang, _ in i18n.available_catalogs(join(templdirs[0], 'i18n'))] |
315 |
errors = config.i18ncompile(langs) |
|
316 |
if errors: |
|
317 |
print '\n'.join(errors) |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
318 |
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
|
319 |
'continue anyway ?'): |
0 | 320 |
print 'creation not completed' |
321 |
return |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
322 |
# create the additional data directory for this instance |
0 | 323 |
if config.appdatahome != config.apphome: # true in dev mode |
324 |
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
|
325 |
create_dir(join(config.appdatahome, 'backup')) |
0 | 326 |
if config['uid']: |
327 |
from logilab.common.shellutils import chown |
|
328 |
# this directory should be owned by the uid of the server process |
|
329 |
print 'set %s as owner of the data directory' % config['uid'] |
|
330 |
chown(config.appdatahome, config['uid']) |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2318
diff
changeset
|
331 |
print '\n-> creation done for %r.\n' % config.apphome |
0 | 332 |
helper.postcreate() |
333 |
||
4064
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
334 |
def _handle_win32(self, config, appid): |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
335 |
if sys.platform != 'win32': |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
336 |
return |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
337 |
service_template = """ |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
338 |
import sys |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
339 |
import win32serviceutil |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
340 |
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
|
341 |
|
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
342 |
from cubicweb.etwist.service import CWService |
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 |
classdict = {'_svc_name_': 'cubicweb-%(APPID)s', |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
345 |
'_svc_display_name_': 'CubicWeb ' + '%(CNAME)s', |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
346 |
'instance': '%(APPID)s'} |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
347 |
%(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
|
348 |
|
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
349 |
if __name__ == '__main__': |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
350 |
win32serviceutil.HandleCommandLine(%(CNAME)sService) |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
351 |
""" |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
352 |
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
|
353 |
service_template % {'APPID': appid, |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
354 |
'CNAME': appid.capitalize(), |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
355 |
'CWPATH': abspath(join(dirname(__file__), '..'))}) |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
356 |
|
1446 | 357 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
358 |
class DeleteInstanceCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
359 |
"""Delete an instance. Will remove instance's files and |
0 | 360 |
unregister it. |
361 |
""" |
|
362 |
name = 'delete' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
363 |
arguments = '<instance>' |
1446 | 364 |
|
0 | 365 |
options = () |
366 |
||
367 |
def run(self, args): |
|
368 |
"""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
|
369 |
appid = pop_arg(args, msg="No instance specified !") |
1132 | 370 |
configs = [cwcfg.config_for(appid, configname) |
371 |
for configname in cwcfg.possible_configurations(appid)] |
|
0 | 372 |
if not configs: |
373 |
raise ExecutionError('unable to guess configuration for %s' % appid) |
|
374 |
for config in configs: |
|
375 |
helper = self.config_helper(config, required=False) |
|
376 |
if helper: |
|
377 |
helper.cleanup() |
|
378 |
# remove home |
|
379 |
rm(config.apphome) |
|
380 |
# remove instance data directory |
|
381 |
try: |
|
382 |
rm(config.appdatahome) |
|
383 |
except OSError, ex: |
|
384 |
import errno |
|
385 |
if ex.errno != errno.ENOENT: |
|
386 |
raise |
|
387 |
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
|
388 |
print '-> instance %s (%s) deleted.' % (appid, confignames) |
0 | 389 |
|
390 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
391 |
# instance commands ######################################################## |
0 | 392 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
393 |
class StartInstanceCommand(InstanceCommandFork): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
394 |
"""Start the given instances. If no instance is given, start them all. |
1446 | 395 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
396 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
397 |
identifiers of the instances to start. If no instance is |
0 | 398 |
given, start them all. |
399 |
""" |
|
400 |
name = 'start' |
|
401 |
actionverb = 'started' |
|
402 |
options = ( |
|
403 |
("debug", |
|
404 |
{'short': 'D', 'action' : 'store_true', |
|
405 |
'help': 'start server in debug mode.'}), |
|
406 |
("force", |
|
407 |
{'short': 'f', 'action' : 'store_true', |
|
408 |
'default': False, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
409 |
'help': 'start the instance even if it seems to be already \ |
0 | 410 |
running.'}), |
411 |
('profile', |
|
412 |
{'short': 'P', 'type' : 'string', 'metavar': '<stat file>', |
|
413 |
'default': None, |
|
414 |
'help': 'profile code and use the specified file to store stats', |
|
415 |
}), |
|
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
|
416 |
('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
|
417 |
{'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
|
418 |
'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
|
419 |
'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
|
420 |
}), |
0 | 421 |
) |
422 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
423 |
def start_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
424 |
"""start the instance's server""" |
3182 | 425 |
debug = self['debug'] |
426 |
force = self['force'] |
|
427 |
loglevel = self['loglevel'] |
|
1132 | 428 |
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
|
429 |
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
|
430 |
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
|
431 |
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
|
432 |
config.init_log(loglevel, debug=debug, force=True) |
3182 | 433 |
if self['profile']: |
0 | 434 |
config.global_set_option('profile', self.config.profile) |
435 |
helper = self.config_helper(config, cmdname='start') |
|
436 |
pidf = config['pid-file'] |
|
437 |
if exists(pidf) and not force: |
|
438 |
msg = "%s seems to be running. Remove %s by hand if necessary or use \ |
|
439 |
the --force option." |
|
440 |
raise ExecutionError(msg % (appid, pidf)) |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
441 |
helper.start_server(config, debug) |
0 | 442 |
|
443 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
444 |
class StopInstanceCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
445 |
"""Stop the given instances. |
1446 | 446 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
447 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
448 |
identifiers of the instances to stop. If no instance is |
0 | 449 |
given, stop them all. |
450 |
""" |
|
451 |
name = 'stop' |
|
452 |
actionverb = 'stopped' |
|
1446 | 453 |
|
0 | 454 |
def ordered_instances(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
455 |
instances = super(StopInstanceCommand, self).ordered_instances() |
0 | 456 |
instances.reverse() |
457 |
return instances |
|
1446 | 458 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
459 |
def stop_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
460 |
"""stop the instance's server""" |
1132 | 461 |
config = cwcfg.config_for(appid) |
0 | 462 |
helper = self.config_helper(config, cmdname='stop') |
463 |
helper.poststop() # do this anyway |
|
464 |
pidf = config['pid-file'] |
|
465 |
if not exists(pidf): |
|
466 |
print >> sys.stderr, "%s doesn't exist." % pidf |
|
467 |
return |
|
468 |
import signal |
|
469 |
pid = int(open(pidf).read().strip()) |
|
470 |
try: |
|
471 |
kill(pid, signal.SIGTERM) |
|
472 |
except: |
|
473 |
print >> sys.stderr, "process %s seems already dead." % pid |
|
474 |
else: |
|
475 |
try: |
|
476 |
wait_process_end(pid) |
|
477 |
except ExecutionError, ex: |
|
478 |
print >> sys.stderr, ex |
|
479 |
print >> sys.stderr, 'trying SIGKILL' |
|
480 |
try: |
|
481 |
kill(pid, signal.SIGKILL) |
|
482 |
except: |
|
483 |
# probably dead now |
|
484 |
pass |
|
485 |
wait_process_end(pid) |
|
486 |
try: |
|
487 |
remove(pidf) |
|
488 |
except OSError: |
|
489 |
# already removed by twistd |
|
490 |
pass |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
491 |
print 'instance %s stopped' % appid |
1446 | 492 |
|
0 | 493 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
494 |
class RestartInstanceCommand(StartInstanceCommand): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
495 |
"""Restart the given instances. |
1446 | 496 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
497 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
498 |
identifiers of the instances to restart. If no instance is |
0 | 499 |
given, restart them all. |
500 |
""" |
|
501 |
name = 'restart' |
|
502 |
actionverb = 'restarted' |
|
503 |
||
504 |
def run_args(self, args, askconfirm): |
|
1132 | 505 |
regdir = cwcfg.registry_dir() |
0 | 506 |
if not isfile(join(regdir, 'startorder')) or len(args) <= 1: |
507 |
# no specific startorder |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
508 |
super(RestartInstanceCommand, self).run_args(args, askconfirm) |
0 | 509 |
return |
510 |
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
|
511 |
'instances then restart them.') |
0 | 512 |
# get instances in startorder |
513 |
for appid in args: |
|
514 |
if askconfirm: |
|
515 |
print '*'*72 |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
516 |
if not ASK.confirm('%s instance %r ?' % (self.name, appid)): |
0 | 517 |
continue |
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
518 |
StopInstanceCommand().stop_instance(appid) |
0 | 519 |
forkcmd = [w for w in sys.argv if not w in args] |
520 |
forkcmd[1] = 'start' |
|
521 |
forkcmd = ' '.join(forkcmd) |
|
522 |
for appid in reversed(args): |
|
523 |
status = system('%s %s' % (forkcmd, appid)) |
|
524 |
if status: |
|
525 |
sys.exit(status) |
|
1446 | 526 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
527 |
def restart_instance(self, appid): |
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
528 |
StopInstanceCommand().stop_instance(appid) |
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
529 |
self.start_instance(appid) |
0 | 530 |
|
1446 | 531 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
532 |
class ReloadConfigurationCommand(RestartInstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
533 |
"""Reload the given instances. This command is equivalent to a |
0 | 534 |
restart for now. |
1446 | 535 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
536 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
537 |
identifiers of the instances to reload. If no instance is |
0 | 538 |
given, reload them all. |
539 |
""" |
|
540 |
name = 'reload' |
|
1446 | 541 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
542 |
def reload_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
543 |
self.restart_instance(appid) |
1446 | 544 |
|
0 | 545 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
546 |
class StatusCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
547 |
"""Display status information about the given instances. |
1446 | 548 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
549 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
550 |
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
|
551 |
given, get status information about all registered instances. |
0 | 552 |
""" |
553 |
name = 'status' |
|
554 |
options = () |
|
555 |
||
1132 | 556 |
@staticmethod |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
557 |
def status_instance(appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
558 |
"""print running status information for an instance""" |
1132 | 559 |
for mode in cwcfg.possible_configurations(appid): |
560 |
config = cwcfg.config_for(appid, mode) |
|
0 | 561 |
print '[%s-%s]' % (appid, mode), |
562 |
try: |
|
563 |
pidf = config['pid-file'] |
|
564 |
except KeyError: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
565 |
print 'buggy instance, pid file not specified' |
0 | 566 |
continue |
567 |
if not exists(pidf): |
|
568 |
print "doesn't seem to be running" |
|
569 |
continue |
|
570 |
pid = int(open(pidf).read().strip()) |
|
571 |
# trick to guess whether or not the process is running |
|
572 |
try: |
|
573 |
getpgid(pid) |
|
574 |
except OSError: |
|
575 |
print "should be running with pid %s but the process can not be found" % pid |
|
576 |
continue |
|
577 |
print "running with pid %s" % (pid) |
|
578 |
||
579 |
||
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
580 |
class UpgradeInstanceCommand(InstanceCommandFork): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
581 |
"""Upgrade an instance after cubicweb and/or component(s) upgrade. |
0 | 582 |
|
583 |
For repository update, you will be prompted for a login / password to use |
|
584 |
to connect to the system database. For some upgrades, the given user |
|
585 |
should have create or alter table permissions. |
|
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 upgrade. If no instance is |
0 | 589 |
given, upgrade them all. |
590 |
""" |
|
591 |
name = 'upgrade' |
|
592 |
actionverb = 'upgraded' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
593 |
options = InstanceCommand.options + ( |
0 | 594 |
('force-componant-version', |
595 |
{'short': 't', 'type' : 'csv', 'metavar': 'cube1=X.Y.Z,cube2=X.Y.Z', |
|
596 |
'default': None, |
|
597 |
'help': 'force migration from the indicated version for the specified cube.'}), |
|
598 |
('force-cubicweb-version', |
|
599 |
{'short': 'e', 'type' : 'string', 'metavar': 'X.Y.Z', |
|
600 |
'default': None, |
|
601 |
'help': 'force migration from the indicated cubicweb version.'}), |
|
1446 | 602 |
|
0 | 603 |
('fs-only', |
604 |
{'short': 's', 'action' : 'store_true', |
|
605 |
'default': False, |
|
606 |
'help': 'only upgrade files on the file system, not the database.'}), |
|
607 |
||
608 |
('nostartstop', |
|
609 |
{'short': 'n', 'action' : 'store_true', |
|
610 |
'default': False, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
611 |
'help': 'don\'t try to stop instance before migration and to restart it after.'}), |
1446 | 612 |
|
0 | 613 |
('verbosity', |
614 |
{'short': 'v', 'type' : 'int', 'metavar': '<0..2>', |
|
615 |
'default': 1, |
|
616 |
'help': "0: no confirmation, 1: only main commands confirmed, 2 ask \ |
|
617 |
for everything."}), |
|
1446 | 618 |
|
0 | 619 |
('backup-db', |
620 |
{'short': 'b', 'type' : 'yn', 'metavar': '<y or n>', |
|
621 |
'default': None, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
622 |
'help': "Backup the instance database before upgrade.\n"\ |
0 | 623 |
"If the option is ommitted, confirmation will be ask.", |
624 |
}), |
|
625 |
||
626 |
('ext-sources', |
|
627 |
{'short': 'E', 'type' : 'csv', 'metavar': '<sources>', |
|
628 |
'default': None, |
|
629 |
'help': "For multisources instances, specify to which sources the \ |
|
630 |
repository should connect to for upgrading. When unspecified or 'migration' is \ |
|
631 |
given, appropriate sources for migration will be automatically selected \ |
|
632 |
(recommended). If 'all' is given, will connect to all defined sources.", |
|
633 |
}), |
|
634 |
) |
|
635 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
636 |
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
|
637 |
print '\n' + underline_title('Upgrading the instance %s' % appid) |
0 | 638 |
from logilab.common.changelog import Version |
1132 | 639 |
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
|
640 |
config.repairing = True # notice we're not starting the server |
0 | 641 |
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
|
642 |
try: |
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
643 |
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
|
644 |
except AttributeError: |
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
645 |
# not a server config |
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
646 |
pass |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
647 |
# get instance and installed versions for the server and the componants |
0 | 648 |
mih = config.migration_handler() |
649 |
repo = mih.repo_connect() |
|
650 |
vcconf = repo.get_versions() |
|
651 |
if self.config.force_componant_version: |
|
652 |
packversions = {} |
|
653 |
for vdef in self.config.force_componant_version: |
|
654 |
componant, version = vdef.split('=') |
|
655 |
packversions[componant] = Version(version) |
|
656 |
vcconf.update(packversions) |
|
657 |
toupgrade = [] |
|
658 |
for cube in config.cubes(): |
|
659 |
installedversion = config.cube_version(cube) |
|
660 |
try: |
|
661 |
applversion = vcconf[cube] |
|
662 |
except KeyError: |
|
663 |
config.error('no version information for %s' % cube) |
|
664 |
continue |
|
665 |
if installedversion > applversion: |
|
666 |
toupgrade.append( (cube, applversion, installedversion) ) |
|
1446 | 667 |
cubicwebversion = config.cubicweb_version() |
0 | 668 |
if self.config.force_cubicweb_version: |
669 |
applcubicwebversion = Version(self.config.force_cubicweb_version) |
|
670 |
vcconf['cubicweb'] = applcubicwebversion |
|
671 |
else: |
|
672 |
applcubicwebversion = vcconf.get('cubicweb') |
|
673 |
if cubicwebversion > applcubicwebversion: |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2156
diff
changeset
|
674 |
toupgrade.append(('cubicweb', applcubicwebversion, cubicwebversion)) |
0 | 675 |
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
|
676 |
print '-> no software migration needed for instance %s.' % appid |
0 | 677 |
return |
678 |
for cube, fromversion, toversion in toupgrade: |
|
2532
f7ca29d75183
[cleanup] improve dialog message consistency
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2512
diff
changeset
|
679 |
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
|
680 |
# 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
|
681 |
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
|
682 |
StopInstanceCommand().stop_instance(appid) |
0 | 683 |
# run cubicweb/componants migration scripts |
684 |
mih.migrate(vcconf, reversed(toupgrade), self.config) |
|
685 |
# rewrite main configuration file |
|
686 |
mih.rewrite_configuration() |
|
687 |
# handle i18n upgrade: |
|
688 |
# * install new languages |
|
689 |
# * recompile catalogs |
|
690 |
# 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
|
691 |
from cubicweb import i18n |
1132 | 692 |
templdir = cwcfg.cube_dir(config.cubes()[0]) |
0 | 693 |
langs = [lang for lang, _ in i18n.available_catalogs(join(templdir, 'i18n'))] |
694 |
errors = config.i18ncompile(langs) |
|
695 |
if errors: |
|
696 |
print '\n'.join(errors) |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
697 |
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
|
698 |
'continue anyway ?'): |
2512
106b2a05dc88
[cleanup] started to improve cubicweb-ctl dialog messages consistency
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2489
diff
changeset
|
699 |
print '-> migration not completed.' |
0 | 700 |
return |
701 |
mih.shutdown() |
|
702 |
print |
|
2512
106b2a05dc88
[cleanup] started to improve cubicweb-ctl dialog messages consistency
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2489
diff
changeset
|
703 |
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
|
704 |
if not (CWDEV or self.config.nostartstop): |
3190
75cf006babe4
another friend
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3188
diff
changeset
|
705 |
StartInstanceCommand().start_instance(appid) |
0 | 706 |
print |
707 |
||
708 |
||
709 |
class ShellCommand(Command): |
|
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
710 |
"""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
|
711 |
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
|
712 |
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
|
713 |
in batch mode. |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
714 |
|
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
715 |
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
|
716 |
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
|
717 |
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
|
718 |
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
|
719 |
available. |
0 | 720 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
721 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
722 |
the identifier of the instance to connect. |
0 | 723 |
""" |
724 |
name = 'shell' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
725 |
arguments = '<instance> [batch command file]' |
0 | 726 |
options = ( |
727 |
('system-only', |
|
728 |
{'short': 'S', 'action' : 'store_true', |
|
729 |
'help': 'only connect to the system source when the instance is ' |
|
730 |
'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
|
731 |
'--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
|
732 |
'group': 'local' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
733 |
}), |
1446 | 734 |
|
0 | 735 |
('ext-sources', |
736 |
{'short': 'E', 'type' : 'csv', 'metavar': '<sources>', |
|
737 |
'help': "For multisources instances, specify to which sources the \ |
|
738 |
repository should connect to for upgrading. When unspecified or 'all' given, \ |
|
739 |
will connect to all defined sources. If 'migration' is given, appropriate \ |
|
740 |
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
|
741 |
'group': 'local' |
0 | 742 |
}), |
1446 | 743 |
|
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
|
744 |
('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
|
745 |
{'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
|
746 |
'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
|
747 |
'group': 'local' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
748 |
}), |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
749 |
|
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
750 |
('pyro', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
751 |
{'short': 'P', 'action' : 'store_true', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
752 |
'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
|
753 |
'group': 'remote', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
754 |
}), |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
755 |
('pyro-ns-host', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
756 |
{'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
|
757 |
'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
|
758 |
'using a broadcast query.', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
759 |
'group': 'remote' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
760 |
}), |
0 | 761 |
) |
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
|
762 |
|
0 | 763 |
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
|
764 |
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
|
765 |
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
|
766 |
from cubicweb import AuthenticationError |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
767 |
from cubicweb.dbapi import connect |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
768 |
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
|
769 |
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
|
770 |
while True: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
771 |
try: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
772 |
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
|
773 |
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
|
774 |
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
|
775 |
except AuthenticationError, ex: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
776 |
print ex |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
777 |
except (KeyboardInterrupt, EOFError): |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
778 |
print |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
779 |
sys.exit(0) |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
780 |
else: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
781 |
break |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
782 |
cnx.load_appobjects() |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
783 |
repo = cnx._repo |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
784 |
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
|
785 |
# 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
|
786 |
schema=1) |
0 | 787 |
else: |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
788 |
config = cwcfg.config_for(appid) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
789 |
if self.config.ext_sources: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
790 |
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
|
791 |
sources = self.config.ext_sources |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
792 |
elif 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 = ('system',) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
794 |
else: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
795 |
sources = ('all',) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
796 |
config.set_sources_mode(sources) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
797 |
config.repairing = self.config.force |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
798 |
mih = config.migration_handler() |
3709
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
799 |
try: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
800 |
if args: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
801 |
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
|
802 |
mih.cmd_process_script(arg) |
3709
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
803 |
else: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
804 |
mih.interactive_shell() |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
805 |
finally: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
806 |
if not self.config.pyro: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
807 |
mih.shutdown() |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
808 |
else: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
809 |
cnx.close() |
0 | 810 |
|
811 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
812 |
class RecompileInstanceCatalogsCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
813 |
"""Recompile i18n catalogs for instances. |
1446 | 814 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
815 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
816 |
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
|
817 |
given, recompile for all registered instances. |
0 | 818 |
""" |
1898
39b37f90a8a4
[cw-ctl] rename i18n commands (see #342889)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1477
diff
changeset
|
819 |
name = 'i18ninstance' |
1132 | 820 |
|
821 |
@staticmethod |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
822 |
def i18ninstance_instance(appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
823 |
"""recompile instance's messages catalogs""" |
1132 | 824 |
config = cwcfg.config_for(appid) |
0 | 825 |
try: |
826 |
config.bootstrap_cubes() |
|
827 |
except IOError, ex: |
|
828 |
import errno |
|
829 |
if ex.errno != errno.ENOENT: |
|
830 |
raise |
|
831 |
# 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
|
832 |
# 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
|
833 |
config.repairing = True |
0 | 834 |
# create an in-memory repository, will call config.init_cubes() |
835 |
config.repository() |
|
836 |
except AttributeError: |
|
837 |
# web only config |
|
838 |
config.init_cubes(config.repository().get_cubes()) |
|
839 |
errors = config.i18ncompile() |
|
840 |
if errors: |
|
841 |
print '\n'.join(errors) |
|
842 |
||
843 |
||
844 |
class ListInstancesCommand(Command): |
|
845 |
"""list available instances, useful for bash completion.""" |
|
846 |
name = 'listinstances' |
|
847 |
hidden = True |
|
1446 | 848 |
|
0 | 849 |
def run(self, args): |
850 |
"""run the command with its specific arguments""" |
|
1132 | 851 |
regdir = cwcfg.registry_dir() |
0 | 852 |
for appid in sorted(listdir(regdir)): |
853 |
print appid |
|
854 |
||
855 |
||
856 |
class ListCubesCommand(Command): |
|
857 |
"""list available componants, useful for bash completion.""" |
|
858 |
name = 'listcubes' |
|
859 |
hidden = True |
|
1446 | 860 |
|
0 | 861 |
def run(self, args): |
862 |
"""run the command with its specific arguments""" |
|
1132 | 863 |
for cube in cwcfg.available_cubes(): |
0 | 864 |
print cube |
865 |
||
866 |
register_commands((ListCommand, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
867 |
CreateInstanceCommand, |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
868 |
DeleteInstanceCommand, |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
869 |
StartInstanceCommand, |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
870 |
StopInstanceCommand, |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
871 |
RestartInstanceCommand, |
0 | 872 |
ReloadConfigurationCommand, |
873 |
StatusCommand, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
874 |
UpgradeInstanceCommand, |
0 | 875 |
ShellCommand, |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
876 |
RecompileInstanceCatalogsCommand, |
0 | 877 |
ListInstancesCommand, ListCubesCommand, |
878 |
)) |
|
879 |
||
1446 | 880 |
|
0 | 881 |
def run(args): |
882 |
"""command line tool""" |
|
1132 | 883 |
cwcfg.load_cwctl_plugins() |
0 | 884 |
main_run(args, __doc__) |
885 |
||
886 |
if __name__ == '__main__': |
|
887 |
run(sys.argv[1:]) |