= Configuration

This chapter explains the configuration of CRaSH, configuration aims to be as simple as possible
and is adapted to the mode running CRaSH.

== Mount point configuration

CRaSH uses the file system for reading configuration files and discovering command source files. CRaSh uses a virtual
file system to be decoupled from the implementation, there are up to three implementations provided out of the box
(frameworks embedding CRaSH may add their own VFS implementation):

- _file_ : the actual file system of the operating system based on the _java.io.File_ API
- _classpath_ : uses the resources provided by the actual classpath
- _war_ : the content of the web archive, available only when CRaSH is embedded in a web application

CRaSH can be configured for the _conf_ and _cmd_ mount points with a simple string that describes the VFS to be used. A _mount point_
is configured with a list of mounts, a mount being the name of a file system associated with a path in this file system.

* _file:cmd/_ : the _cmd_ directory relative to the file system running the JVM
* _file:/cmd/_ : the _cmd_ directory relative to the root of the file system (so _/cmd_)
* _classpath:/crash/commands/_ : any _/crash/command/_ package found in the classpath
* _war:/WEB-INF/crash/commands/_ : the folder _/WEB-INF/crash/commands_ in the war file hosting CRaSH
* _classpath:/crash/commands/;war:/WEB-INF/crash/commands_ : the aggregates of two entries

By default CRaSH provides an adapted mount point configuration for each mode, but you can customize it
according to your needs.

=== Configuring the web application mode

The servlet context parameters are used for configuring the paths:

[source,xml]
----
<web-app>
  ...
  <context-param>
    <param-name>crash.mountpointconfig.conf</param-name>
    <param-value>war:/WEB-INF/crash/</param-value>
  </context-param>
  <context-param>
    <param-name>crash.mountpointconfig.cmd</param-name>
    <param-value>war:/WEB-INF/crash/commands/</param-value>
  </context-param>
  ...
</web-app>
----

In this mode, the configs are subject to property interpolation based on the system properties of the JVM:

[source,xml]
----
<web-app>
  ...
  <context-param>
    <param-name>crash.mountpointconfig.conf</param-name>
    <param-value>${myconf}</param-value>
  </context-param>
  ...
</web-app>
----

The interpolation format allows to specify a default value when the property cannot be resolved using Bash syntax:

[source,xml]
----
<web-app>
  ...
  <context-param>
    <param-name>crash.mountpointconfig.conf</param-name>
    <param-value>${myconf:-war:/WEB-INF/crash/commands/}</param-value>
  </context-param>
  ...
</web-app>
----

Interpolation is only available for the web application mode.

=== Configuring the spring mode

The +org.crsh.spring.SpringWebBootstrap+ bean exposes the _cmdMountPointConfig_ and _confMountPointConfig_ properties to configure it:

[source,xml]
----
  <bean class="org.crsh.spring.SpringWebBootstrap">
    <property name="cmdMountPointConfig" value="war:/WEB-INF/crash/commands/"/>
    <property name="confMounPointConfig" value="war:/WEB-INF/crash/"/>
    ...
  </bean>
----

== Configuration properties

Properties play an important role in CRaSH configuration, they are configured differently according to the mode.

=== Configuring the standalone or attach mode

In standalone or attach mode configuration can be in the _/conf/crash.properties_ file or via the command line directly.

The _crash.properties_ file does not exist by default and it is created at the first run, so you should run CRaSH
at least once to extract the file:

----
% crash
----

You can also specify properties as a CRaSH command line argument with the _-p_ option:

----
% crash -p crash.property_name=property_value
----

=== Configuring the web application mode

In the war file packaging, the configuration file can be found under _/WEB-INF/crash/crash.properties_ file of the archive.
Configuration can be overriden by Java Virtual Machine system properties by using the same property name.

=== Configuring shell default message

The _/crash/commands/base/login.groovy_ file contains two closures that are evaluated each time a message is required

* The +prompt+ closure returns the prompt message
* The +welcome+ closure returns the welcome message

Those closure can be customized to return different messages.

