# Starting and stopping Discovery

Use the Discovery control script, `discovery.sh`, to start and stop Discovery.

## Starting Discovery

Before starting Discovery, start the database server that Discovery is configured to use.

By default, Discovery is configured to use an example HyperSQL database suitable for evaluating a single Discovery server. To start the example HyperSQL database, run the command below:

```console
$ sql/hsqldb.sh start
```

### Starting Discovery as a background process

To start Discovery as a background process that logs to `logs/discovery.log`, use the `start` command:

```console
$ ./discovery.sh start
```

If Discovery is already running, this command restarts Discovery.

For information on changing default log location, name, and rolling behaviour, see [Discovery log files](discovery-logs.md).

### Starting Discovery as a foreground process

To start Discovery as a foreground process that logs to STDOUT, use the `start` command with option `-f`:

```console
$ ./discovery.sh start -f
```

This method of starting Discovery is appropriate when running Discovery in a container

## Stopping Discovery

Follow the instructions below to stop Discovery.

### Stopping a Discovery background process

To stop a Discovery server running as a background process, use the `stop` command:

```console
$ ./discovery.sh stop
```

### Stopping a Discovery foreground process

To stop a Discovery server running as a foreground process, use one of the methods below:

* Press Ctrl-C in the terminal running Discovery.
* Send the process a TERM signal:

  ```
  $ kill __pid__
  ```
* If Discovery is running in a container, stop the container.

## Retrieving Discovery status

To determine if Discovery is running as a background process, use the `status` command:

```console
$ ./discovery.sh status
```

This command prints the status of Discovery to STDOUT, and exits with status code 0 if Discovery is running or status code 1 if Discovery is not running.
