Starting and Stopping Karaf

This chapter describes how to start and stop Apache Karaf and the various options that are available.

Starting Karaf

On Windows

From a console window, change to the installation directory and run Karaf. For the binary distribution, go to

cd [karaf_install_dir]

where karaf_install_dir is the directory in which Karaf was installed, e.g., c:\Program Files\apache-karaf-x.y.

Then type:

bin\karaf.bat

On Unix

From a command shell, change to the installation directory and run Karaf. For the binary distribution, go to

cd [karaf_install_dir]

where karaf_install_dir is the directory in which Karaf was installed, e.g., /usr/local/apache-karaf-x.y.

Then type:

bin/karaf

Warning

Do NOT close the console or shell in which Karaf was started, as that will terminate Karaf (unless Karaf was started with nohup).

Starting Karaf without console

Karaf can be started without the console if you don't intend to use it (one can always connect using the remote ssh access) using the following command:

bin\karaf.bat server

or, on Unix:

bin\karaf server

Starting Karaf in the background

Karaf can be easily started as a background process using the following command:

bin\start.bat

or, on Unix:

bin\start

Starting Karaf from clean

Karaf can be reset to a clean state by simply deleting the data folder.
For convenience, a parameter on the karaf and start scripts is available:

bin/start clean

In addition there might be situations where you need to restart the application from your application or dont have any
access to the service starting and stopping karaf. In this case you can either put an empty clean_cache or clean_all file
into the data folder. If you restart or start and stop Karaf then either the cache will be cleaned or the entire
data folder will be deleted.

Restarting Karaf

You can restart Karaf directly from the command line by using:

dev:restart

Be careful since this does not start a new JVM but simply restarts the OSGi framework. If you want to clean your cache
or data directory during the reboot add the -c or -cc params to your build. Mor detailed information about the
restart parameters could be retrieved from the command line by using

dev:restart --help

Stopping Karaf

For both Windows and Unix installations, you can perform a clean shutdown of Karaf by using the following command when inside a Karaf console:

system:shutdown

or simply:

shutdown

The shutdown command asks you to confirm that you really want to shutdown. If you are sure about the shutdown and avoid the confirmation message, you can use the -f or --force option:

system:shutdown -f

It's also possible to delay the shutdown using the time argument. The time argument can have different formats.
First, it can be an absolute time in the format hh:mm, in which hh is the hour (1 or 2 digits) and mm is the minute of
the hour (in two digits). Second, it can be in the format m (or +m), in which m is the number of minutes to wait.
The word now is an alias for 0.

The following command will shutdown Karaf at 10:35am:

system:shutdown 10:35

The following command will shutdown Karaf in 10 minutes:

system:shutdown 10

If you're running from the main console, exiting the shell using logout or Ctrl+D will also terminate the Karaf instance.

From a command shell, you can run the following command:

bin\stop.bat

or, on Unix:

bin/stop