The Common Reusable SHell (CRaSH) deploys in a Java runtime and provides interactions with the JVM. Commands are written in Groovy and can be developed 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 are 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

How can I run CRaSH ?

Refer to documentation in the Running Crash chapter.

How can I connect Crash to a JVM ?

Refer to documentation in the Connection section of the Shell Usage chapter.

Basic

What is the best way to create a command ?

The best way to create a command is to use CRaSH utilities. Refer to documentation in the [reference#developping_commands] section of the Developers chapter.

What is the best way to start with CRaSH ?

  • Launch CRaSH and play with commands

  • Create commands (script command and class command)

  • See cookbook and documentation.

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.

I try to run CRaSH in Eclipse and it terminates immediately

CRaSH uses jline to handle keyboard input, and it’s bypassing the Java API to read the key events. Somewhere in the process there is a mismatch with the input handling in the Console view of Eclipse, and CRaSH terminates without any reported error. You have to force jline to use a pure Java handling of the keyboard events by adding the following JVM parameter in the Launch Configuration:

-Djline.terminal=jline.UnsupportedTerminal

You will notice that the caret is not positioned correctly after submitting a command.

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.

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 !");
}
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 are 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;
Table name are case sensitive.

Close the connection

jdbc close