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