# Restarting Connectware

This section explains how to restart Connectware. Restarting may be necessary when applying configuration changes, troubleshooting issues, or performing maintenance tasks.

{% tabs %}
{% tab title="Kubernetes" %}

### Restarting Connectware on Kubernetes

In Kubernetes environments, restarting Connectware requires scaling down all controller resources to zero before scaling them back up. The following procedure ensures a proper restart without data loss.

{% hint style="danger" %}

* The following procedure will scale everything that is currently deployed in the target namespace.
* If you have any workload besides Connectware Core Services in this namespace, they will be restarted too.
  {% endhint %}

#### Prerequisites

* `kubectl` installed and configured to point at the target Kubernetes cluster
* A shell capable of storing variables (e.g. bash)

#### Procedure

1. Store the namespace that is used for Connectware in a variable:

{% code lineNumbers="true" %}

```bash
CONNECTWARE_NS=<namespace here>
```

{% endcode %}

2. Verify what will be restarted using this procedure:

{% code lineNumbers="true" %}

```bash
kubectl get sts,deployment -n $CONNECTWARE_NS
```

{% endcode %}

3. If this displays any workload that is not part of the Connectware Core Services, note down their scaling. You'll need to scale them to their original value after finishing this procedure.
4. Store the number of replicas configured for the broker:

{% code lineNumbers="true" %}

```bash
BROKER_REPLICAS=$(kubectl get --no-headers -o custom-columns=":spec.replicas" sts broker -n $CONNECTWARE_NS)
```

{% endcode %}

5. Optional: If you use the optional control-plane-broker, store the number of replicas configured for it:

{% code lineNumbers="true" %}

```bash
CONTROL_PLANE_REPLICAS=$(kubectl get --no-headers -o custom-columns=":spec.replicas" sts control-plane-broker -n $CONNECTWARE_NS)
```

{% endcode %}

6. Scale down all StatefulSets and Deployments:

{% code lineNumbers="true" %}

```bash
kubectl get deploy,sts -n $CONNECTWARE_NS -o name | xargs -I % kubectl scale -n $CONNECTWARE_NS % --replicas 0
```

{% endcode %}

7. Wait for all pods to be terminated. You can monitor this progress with (terminate with Ctrl+C when no more pods are showing):

{% code lineNumbers="true" %}

```bash
while [ True ]; do clear; kubectl get pod -n $CONNECTWARE_NS ; sleep 5; done
```

{% endcode %}

8. Scale up all workloads to 1:

{% code lineNumbers="true" %}

```bash
kubectl get deploy,sts -n $CONNECTWARE_NS -o name | xargs -I % kubectl scale -n $CONNECTWARE_NS % --replicas 1
```

{% endcode %}

9. Scale broker to the number of replicas recorded earlier:

{% code lineNumbers="true" %}

```bash
kubectl -n $CONNECTWARE_NS scale sts broker --replicas $BROKER_REPLICAS
```

{% endcode %}

10. Optional: If you use the optional control-plane-broker, scale control-plane-broker to the original number of replicas:

{% code lineNumbers="true" %}

```bash
kubectl -n $CONNECTWARE_NS scale sts control-plane-broker --replicas $CONTROL_PLANE_REPLICAS
```

{% endcode %}

11. Monitor pods and verify all reach the Running status and report ready:

{% code lineNumbers="true" %}

```bash
while [ True ]; do clear; kubectl get pod -n $CONNECTWARE_NS ; sleep 5; done
```

{% endcode %}

12. Optional: Scale any additional workloads in this namespace to the values you noted down earlier.
    {% endtab %}

{% tab title="Docker" %}

### Restarting Connectware on Docker

1. Access the system that hosts your Connectware instance via SSH.
2. Navigate to your Connectware installation directory. If you have used the default values during installation, the installation directory is `/opt/connectware`.
3. Stop the current Connectware services:

{% code lineNumbers="true" %}

```bash
docker compose down
```

{% endcode %}

4. Restart Connectware:

{% code lineNumbers="true" %}

```bash
docker compose up -d
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Verifying after Restarting

After restarting Connectware, verify that all services are running correctly:

1. Check the service status via the Admin UI. For more information, see [System Status](https://docs.cybus.io/1-11-0/documentation/system-status) and [Service Logs](https://docs.cybus.io/1-11-0/documentation/services/service-logs).
2. Verify that the connections to the data sources are reestablished.
3. Confirm that any previously configured mappings or workflows are functioning.

## Troubleshooting when Restarting Fails

If Connectware does not start properly after restart:

1. Check logs for errors.
   * For Kubernetes: `kubectl logs -n $CONNECTWARE_NS <podname>`
   * For Docker: `docker compose logs <your-connectware-container>`
2. Verify network connectivity between components.
3. Ensure that the configuration files are valid and correctly formatted.

If problems persist, contact Cybus support at <support@cybus.io>.
