Skip to content

Instantly share code, notes, and snippets.

@anpieber
Created May 22, 2013 07:48
Show Gist options
  • Save anpieber/5625928 to your computer and use it in GitHub Desktop.
Save anpieber/5625928 to your computer and use it in GitHub Desktop.
Documentation of clean & restart in karaf
h1. Starting and Stopping Karaf
This chapter describes how to start and stop Apache Karaf and the various options that are available.
h2. Starting Karaf
h3. On Windows
From a console window, change to the installation directory and run {{Karaf}}. For the binary distribution, go to
{code}
cd [karaf_install_dir]
{code}
where {{karaf_install_dir}} is the directory in which Karaf was installed, e.g., {{c:\Program Files\apache-karaf-x.y}}.
Then type:
{code}
bin\karaf.bat
{code}
h3. On Unix
From a command shell, change to the installation directory and run {{Karaf}}. For the binary distribution, go to
{code}
cd [karaf_install_dir]
{code}
where {{karaf_install_dir}} is the directory in which Karaf was installed, e.g., {{/usr/local/apache-karaf-x.y}}.
Then type:
{code}
bin/karaf
{code}
{warning:title=Warning}
Do NOT close the console or shell in which Karaf was started, as that will terminate Karaf (unless Karaf was started with nohup).
{warning}
h2. 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:
{code}
bin\karaf.bat server
{code}
or, on Unix:
{code}
bin\karaf server
{code}
h2. Starting Karaf in the background
Karaf can be easily started as a background process using the following command:
{code}
bin\start.bat
{code}
or, on Unix:
{code}
bin\start
{code}
h2. 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:
{code}
bin/start clean
{code}
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.
h2. Restarting Karaf
You can restart Karaf directly from the command line by using:
{code}
dev:restart
{code}
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
{code}
dev:restart --help
{code}
h2. 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:
{code}
system:shutdown
{code}
or simply:
{code}
shutdown
{code}
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:
{code}
system:shutdown -f
{code}
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, in which m is the number of minutes to wait. The work now is an alias for +0.
The following command will shutdown Karaf at 10:35am:
{code}
system:shutdown 10:35
{code}
The following command will shutdown Karaf in 10 minutes:
{code}
system:shutdown +10
{code}
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:
{code}
bin\stop.bat
{code}
or, on Unix:
{code}
bin/stop
{code}
@ailjushkin
Copy link

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment