The Common Reusable SHell (CRaSH) deploys in a Java runtime and provides interactions with the JVM. Commands are written in Groovy and can be developped at runtime making the extension of the shell very easy with fast development cycle.
FAQ
General
What is CRaSH ?
CRaSH is a shell that extends JVM. With CRaSH, you will connect with a shell directly on a JVM. Moreover, you could add your command (Java/Groovy) and that’s why CRaSH is really interesting.
What can I do with CRaSH ?
-
Monitoring JVM and make your own dashboard command.
-
Make command for your application (add data in a cache, add user, monitor jobs ).
-
Make your JMX command.
What is the differences between CRaSH and JMX ?
JMX provides only bean and methods, that’s all. CRaSH permit to access to JMX and to make command with it. CRaSH also permit to make script with thread, jdbc, entity …
Running CRaSH
Basic
Commons problems
Command not found
In most cases, when you created a command, it’s a syntax error in a command. Check your import and syntax with your ide.
Can’t find crash.properties file
You have to launch CRaSH in standalone mode once.
Then, it will appears in $CRASH_HOME/conf/
Where are the base commands ?
They will be in $CRASH_HOME/cmd/base directory. You have to launch CRaSH once in standalone mode.
Create your first command
In this cookbook, you will learn how to create a simple script command. You will see that you can create it dynamically without restarting CRaSH.
|
Note
|
A better solution to create a command is to use CRaSH class.It provides tools to simply command creation. |
Run CRaSH
cd $CRASH_HOME/bin ./crash.sh Type help at prompt
You will see something like :
Try one of these commands with the -h or --help switch: NAME DESCRIPTION clock dashboard date show the current time env display the term env filter hello help provides basic help java various java language commands jdbc JDBC connection jmx Java Management Extensions jndi Java Naming and Directory Interface jpa Java persistance API jvm JVM informations log logging commands man format and display the on-line manual pages shell shell related command sleep sleep for some time sort Sort a map system vm system properties commands thread JVM thread commands
Add new command
To add a command to CRaSH. You have to add a groovy file in the cmd directory :
cd $CRASH_HOME/cmd vi test.groovy
Put the following in test.groovy :
for (int i = 0;i < 10;i++) {
System.out.println("CRaSH is cool !");
}
|
Note
|
In this example, we create a command by using Java syntax. It’s because Groovy understand Java Syntax. So you could begin to develop your command in Java and when you want try cool Groovy stuff. |
refresh console
Type help again at prompt and you will see test command.
% help Try one of these commands with the -h or --help switch: NAME DESCRIPTION clock dashboard date show the current time env display the term env filter hello help provides basic help java various java language commands jdbc JDBC connection jmx Java Management Extensions jndi Java Naming and Directory Interface jpa Java persistance API jvm JVM informations log logging commands man format and display the on-line manual pages shell shell related command sleep sleep for some time sort Sort a map system vm system properties commands test thread JVM thread commands
Attaching to a running JVM
This chapter provides various recipes using the attach mechanism of CRaSH.
Expose several already running JVM via SSH using
In this recipe you will learn how to attach CRaSH to several JVM running on the local host. Each JVM will be accessible using the SSH connector. To achieve this goal we need to
-
attach CRaSH to one or several virtual machines
-
use the non-interactive mode
-
set the SSH port to 0 to avoid port collisions
crash.sh --non-interactive --property crash.ssh.port=0 PID1 PID2 PID3 ...
The execution of CRaSH will last a few seconds, the process will end when all JVM will have their own agent.
Interacting with a database
In this cookbook, you will see how to connect to a database and how to execute query.
Connect to a database
You have 2 possibility to connect to your databases : * open : open a connection from JNDI bound datasource * connect : connect to database with a JDBC connection string
Here is some examples :
H2
jdbc connect jdbc:h2:mem:test -u sa
MYSQL
jdbc connect -u USER -p PASSWORD jdbc:mysql://localhost:3306/DATABASE
Perform a select on a table
jdbc select * from UTILISATEUR;
|
Note
|
Table name are case sensitive. |
Close the connection
jdbc close