# Run IQ Server as a Service

The server can be run as a service or daemon. This is recommended to ensure the server will restart when the operating system reboots. Following instructions are for Linux environments that use _systemd_.

See the KB to [run as a service on a Windows Server](https://support.sonatype.com/hc/en-us/articles/213463798-Running-the-Sonatype-IQ-Server-as-a-Service-on-Windows)

**Note**  
This topic applies to IQ Server installations using the bundled JDK distribution. If you are using the standalone JAR distribution, service configuration differs.

1. Create a dedicated service user (for example, `iqserver`) with limited access on the server.
2. Install IQ Server in a directory such as _/opt/sonatype-iq-server_.
3. Configure IQ Server to run as a `systemd` service. See the `SystemD` section below.

## Set directory permissions

Create a dedicated user with limited access for the service.

The user needs full access rights to the server installation directory and the `sonatype-work` directory listed in the `config YAML`.

The following command grants service user permissions:

```
chown -R iqserver /opt/sonatype-iq-server
```

These steps assume that a dedicated service user already exists and owns both the IQ Server installation directory and the configured _sonatype-work_ directory.

## Bundled JDK distribution (Recommended)

When using the IQ Server distribution that includes a bundled JDK, start IQ Server using the provided wrapper script:

```
<install-dir>/bin/nexus-iq-server server <path/to/config.yml>
```

The `nexus-iq-server` wrapper script is included with the bundled JDK distribution at `<install-dir>/bin/nexus-iq-server`.

For IQ Server 205 and later, custom startup scripts that call the server JAR directly should reference the server JAR in the `jars` directory, for example:

```
./jars/insight-brain-service-*-server.jar
```

**Note**  
If you use a custom startup script with a separately installed Java runtime, use a Java version supported by your IQ Server version. See the [Java Compatibility Matrix](https://help.sonatype.com/en/java-compatibility-matrix.html).

The bundled distribution also includes example service scripts and a sample configuration file in the `<install-dir>/examples` directory.

## SystemD

This example shows how to run IQ Server as a `native systemd service`. It does not require a _/etc/init.d_ script.

1. Make sure the `iqserver` user exists (or create it).
2. Ensure IQ Server is installed in a directory such as `/opt/sonatype-iq-server`.
3. Create a file called `sonatypeiq.service` in the `/etc/systemd/system/` directory.

```
/etc/systemd/system/sonatypeiq.service
```

4. Add the following script and save the file:

```
[Unit]
Description=Sonatype Nexus IQ Server
After=network-online.target

[Service]
Type=simple
User=iqserver
WorkingDirectory=/opt/sonatype-iq-server

ExecStart=/opt/sonatype-iq-server/bin/nexus-iq-server server config.yml

Restart=on-failure
TimeoutStopSec=600

StandardOutput=journal
StandardError=append:/opt/sonatype-iq-server/stderr.log

[Install]
WantedBy=multi-user.target
```

Activate the service with the following commands:

```
sudo systemctl daemon-reload
sudo systemctl enable sonatypeiq.service
sudo systemctl start sonatypeiq.service
sudo systemctl status sonatypeiq.service
```

## Native Linux installers from the community

Community-provided native installers for Linux are available to set up the server to run as a service, however, they are not officially supported.

See [github.com/sonatype-nexus-community/nexus-iq-server-installer](https://github.com/sonatype-nexus-community/nexus-iq-server-installer)
