blob: da6e3aacc7170883f6d139778ff2091a713be9db [file] [log] [blame]
Marian Harbachebeb1542019-12-13 10:42:46 +01001:linkattrs:
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -08002= Gerrit Inspector
Marcin Cieślaked612fb2012-04-17 16:24:34 +00003
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -08004== NAME
Marcin Cieślaked612fb2012-04-17 16:24:34 +00005Gerrit Inspector - Interactive Jython environment for Gerrit
6
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -08007== SYNOPSIS
Michael Ochmanna8434612016-07-08 10:58:27 +02008[verse]
Yuxuan 'fishy' Wangd85b6872013-11-15 11:47:46 -08009--
Michael Ochmanna8434612016-07-08 10:58:27 +020010_java_ -jar gerrit.war _daemon_
11 -d <SITE_PATH>
12 [--enable-httpd | --disable-httpd]
13 [--enable-sshd | --disable-sshd]
14 [--console-log]
Han-Wen Nienhuys348a6032019-09-24 19:44:57 +020015 [--replica]
Michael Ochmanna8434612016-07-08 10:58:27 +020016 -s
Yuxuan 'fishy' Wangd85b6872013-11-15 11:47:46 -080017--
Marcin Cieślaked612fb2012-04-17 16:24:34 +000018
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080019== DESCRIPTION
Marcin Cieślaked612fb2012-04-17 16:24:34 +000020Runs the Gerrit network daemon on the local system as described
21in the link:pgm-daemon.html[Daemon documentation], additionally
22starting an interactive Jython shell for inspection
23and troubleshooting of live data of the Gerrit instance.
24
25CAUTION: Gerrit Inspector works directly on instances of Java Virtual
26Machine objects and it is possible to read and write instance
27members as well as invoke Java functions. Access is granted
28also to 'private' and 'protected' members. Therefore it is possible
29to introduce changes to the internal state of the system in
30an inconsistent way. Care must be taken not to break the running system
31and/or destroy the data.
32
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080033== INSTALLATION
Marcin Cieślaked612fb2012-04-17 16:24:34 +000034
35Gerrit Inspector requires Jython library ('jython.jar') to be installed
36in the '$site_path/lib' directory. Jython, a Python interpreter for
Marian Harbach34253372019-12-10 18:01:31 +010037the Java Virtual Machine, can be obtained from the http://www.jython.org/[role=external,window=_blank]
Marcin Cieślaked612fb2012-04-17 16:24:34 +000038website. Only 'jython.jar' file is needed, installation of Jython libraries
39is optional. Gerrit Inspector has been tested with Jython 2.5.2 but
40might work an earlier version.
41
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080042== STARTUP
Marcin Cieślaked612fb2012-04-17 16:24:34 +000043
44During startup Jython examines Java libraries found on the classpath.
45While libraries are inspected a large amount of messages is displayed on the console:
46
47----
48*sys-package-mgr*: processing new jar, '/home/user/.gerritcodereview/tmp/gerrit_4890671371398741854_app/sshd-core-0.5.1-r1095809.jar'
49----
50
51After this a system-wide embedded initialization script is started. This script
52is contained in the gerrit's WAR archive. This script produces output similar to
53the following on the console:
54
55----
56"Shell" is "com.google.gerrit.pgm.shell.JythonShell@61644f2d"
57"m" is "com.google.gerrit.lifecycle.LifecycleManager@6f03b248"
Marcin Cieślaked612fb2012-04-17 16:24:34 +000058
59Welcome to the Gerrit Inspector
60Enter help() to see the above again, EOF to quit and stop Gerrit
61----
62
63Then an optional user startup script is processed. It should be
64located in the gerrit user home directory as '.gerritcodereview/Startup.py'.
65
66This script can access all variables defined in the system (such
67as the ones displayed by the initialization script as shown above).
68Variables and functions defined by the startup scripts are available for
69the interactive interpreter.
70
71When interactive interpreter exits (by issuing EOF on the command line),
72a whole Gerrit instance is shut down gracefully.
73
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080074== USING THE INTERPRETER
Marcin Cieślaked612fb2012-04-17 16:24:34 +000075
76Gerrit Inspector launches Jython interpreter in the context of the Gerrit
77Java Virtual Machine. All core facilities of the Jython (and Python)
78language are available to the user.
79
80Additional facilities can be provided, for example a 'Lib' directory from the
81Jython distribution can be installed under '$site_path/lib/Lib' to provide
82access to many standard Python modules. Jython can also use additional Java
83classes and libraries and most of the Python modules and scripts.
84
85The Inspector has by default access to classes and object instances available
86in the Java Virtual Machine. Objects are introspected and *private* and *protected*
87members are also available.
88
89For more information on using Jython, especially with regards to its limitations
90in interfacing to the Java Virtual Machine, please refer to the
Marian Harbach34253372019-12-10 18:01:31 +010091http://www.jython.org/[Jython documentation,role=external,window=_blank].
Marcin Cieślaked612fb2012-04-17 16:24:34 +000092
David Pursehouse659860f2013-12-16 14:50:04 +090093After successful initialization it is possible to examine components of
Marcin Cieślaked612fb2012-04-17 16:24:34 +000094Java packages, classes and live instances.
95
96----
97>>> import com.google.inject
98>>> dir(com.google.inject)
99['AbstractModule', 'Binder', 'Binding', 'BindingAnnotation', 'ConfigurationException', 'CreationException', 'Exposed', 'Guice', 'ImplementedBy', 'Inject', 'Injector', 'Key', 'MembersInjector', 'Module', 'OutOfScopeException', 'PrivateBinder', 'PrivateModule', 'ProvidedBy', 'Provider', 'Provides', 'ProvisionException', 'Scope', 'ScopeAnnotation', 'Scopes', 'Singleton', 'Stage', 'TypeLiteral', '__name__', 'assistedinject', 'binder', 'internal', 'matcher', 'name', 'servlet', 'spi', 'util']
100>>> type(com.google.inject)
101<type 'javapackage'>
102>>> dir(com.google.inject.Guice)
103['__class__', '__copy__', '__deepcopy__', '__delattr__', '__doc__',
104'__eq__', '__getattribute__', '__hash__', '__init__', '__ne__',
105'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
106'__str__', '__unicode__', 'class', 'clone', 'createInjector',
107'equals', 'finalize', 'getClass', 'hashCode', 'notify', 'notifyAll',
108'registerNatives', 'toString', 'wait']
109----
110
Marcin Cieślaked612fb2012-04-17 16:24:34 +0000111A built-in *help()* function provides values of global variables
112defined in the interpreter:
113
114----
115>>> help()
Marcin Cieślaked612fb2012-04-17 16:24:34 +0000116"m" is "com.google.gerrit.lifecycle.LifecycleManager@6f03b248"
Marcin Cieślaked612fb2012-04-17 16:24:34 +0000117"Shell" is "com.google.gerrit.pgm.shell.JythonShell@61644f2d"
David Ostrovsky947a80f2013-11-06 22:13:11 +0100118"d" is "com.google.gerrit.pgm.Daemon@28a3f689"
Marcin Cieślaked612fb2012-04-17 16:24:34 +0000119
120Welcome to the Gerrit Inspector
121Enter help() to see the above again, EOF to quit and stop Gerrit
122----
123
124Java and Python exceptions are intercepted by the Inspector:
125----
126>>> import java.lang.RuntimeException
127>>> raise java.lang.RuntimeException("Exiting")
128Traceback (most recent call last):
129 File "<stdin>", line 1, in <module>
130 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
131 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
132 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
133 at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
134 at org.python.core.PyReflectedConstructor.constructProxy(PyReflectedConstructor.java:210)
135
136java.lang.RuntimeException: java.lang.RuntimeException: Exiting
137>>>
138----
139
140To exit the interpreter, use EOF character (Ctrl-D on Unix systems, Ctrl-Z on Windows).
141
142It is also possible to shut down the JVM by using *System.exit()*
143
144----
145>>> import java.lang.System
146>>> java.lang.System.exit(1)
147----
148
149And Gerrit should shut down all its subsystems and exit:
150
151----
152[2012-04-17 15:31:08,458] INFO com.google.gerrit.pgm.Daemon : caught shutdown, cleaning up
153----
154
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800155== TROUBLESHOOTING
Marcin Cieślaked612fb2012-04-17 16:24:34 +0000156
157Gerrit Inspector is logging to the Gerrit error log.
158
159A successful startup is indicated in the logfile:
160
161----
162 [2012-04-17 13:43:44,888] INFO com.google.gerrit.pgm.shell.JythonShell : Jython shell instance created.
163----
164
165If 'jython.jar' library is not available, Gerrit refuses to start when given *-s* option:
166
167----
168[2012-04-17 13:57:29,611] ERROR com.google.gerrit.pgm.Daemon : Unable to start daemon
169com.google.inject.ProvisionException: Guice provision errors:
170
1711) Error injecting constructor, java.lang.UnsupportedOperationException: Cannot create Jython shell: Class org.python.util.InteractiveConsole not found
172 (You might need to install jython.jar in the lib directory)
173 at com.google.gerrit.pgm.shell.JythonShell.<init>(JythonShell.java:47)
174 while locating com.google.gerrit.pgm.shell.JythonShell
175 while locating com.google.gerrit.pgm.shell.InteractiveShell
176----
177
178Errors during processing of the startup script, 'Startup.py', are logged
179to the error log:
180
181----
182[2012-04-17 14:20:30,558] INFO com.google.gerrit.pgm.shell.JythonShell : Jython shell instance created.
David Pursehouse1ff91c02015-05-19 15:05:26 +0900183[2012-04-17 14:20:38,005] ERROR com.google.gerrit.pgm.shell.JythonShell : Exception occurred while loading file Startup.py :
Marcin Cieślaked612fb2012-04-17 16:24:34 +0000184java.lang.reflect.InvocationTargetException
185 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
186 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
187 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
188 at java.lang.reflect.Method.invoke(Method.java:616)
189 at com.google.gerrit.pgm.shell.JythonShell.runMethod0(JythonShell.java:112)
190 at com.google.gerrit.pgm.shell.JythonShell.execFile(JythonShell.java:194)
191 at com.google.gerrit.pgm.shell.JythonShell.reload(JythonShell.java:178)
192 at com.google.gerrit.pgm.shell.JythonShell.run(JythonShell.java:152)
193 at com.google.gerrit.pgm.Daemon.run(Daemon.java:190)
194 at com.google.gerrit.pgm.util.AbstractProgram.main(AbstractProgram.java:67)
195 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
196 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
197 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
198 at java.lang.reflect.Method.invoke(Method.java:616)
199 at com.google.gerrit.launcher.GerritLauncher.invokeProgram(GerritLauncher.java:167)
200 at com.google.gerrit.launcher.GerritLauncher.mainImpl(GerritLauncher.java:91)
201 at com.google.gerrit.launcher.GerritLauncher.main(GerritLauncher.java:49)
202 at Main.main(Main.java:25)
203Caused by: Traceback (most recent call last):
204 File "/home/user/.gerritcodereview/Startup.py", line 1, in <module>
205 Test
206NameError: name 'Test' is not defined
207----
208
209Those errors are non-fatal. System and user scripts can be loaded again
210by issuing the following command in the Gerrit Inspector console:
211
212----
213Shell.reload()
214----
215
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800216== LOGGING
Marcin Cieślaked612fb2012-04-17 16:24:34 +0000217Error and warning messages from the server are automatically written
218to the log file under '$site_path/logs/error_log'.
219
220Output and error messages (including Java and Python exceptions)
221resulting from interactive work are logged to the console.
222
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800223== KNOWN ISSUES
Marcin Cieślaked612fb2012-04-17 16:24:34 +0000224The Inspector does not yet recognize Google Guice bindings.
225
Michael Ochmann8129ece2016-07-08 11:25:25 +0200226[IMPORTANT]
227Using the Inspector may void your warranty.
Marcin Cieślaked612fb2012-04-17 16:24:34 +0000228
229GERRIT
230------
231Part of link:index.html[Gerrit Code Review]
Yuxuan 'fishy' Wang99cb68d2013-10-31 17:26:00 -0700232
233SEARCHBOX
234---------