# Netrunner and PM2

## Using PM2 for production management

<figure><img src="https://3015034387-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNKK8Y1uEALYsObbKnPLt%2Fuploads%2FpIFCqiHHd1pF7OFJFGbZ%2Fimage.png?alt=media&#x26;token=1f19a247-da62-45bf-ae4c-a0939e78f458" alt=""><figcaption></figcaption></figure>

PM2 allows you to run services in the background, monitor server resource usage, write logs, and more.

{% hint style="info" %}
**PM2 is the recommended way to run and maintain a node (regular and validator) for Klyntar**
{% endhint %}

To run & work with a testnet you can use these simple commands:

## 1. Start a testnet in a single command:

```
pm2 start runner2.js
```

## 2. Check the active background services

You will see the following

<figure><img src="https://3015034387-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNKK8Y1uEALYsObbKnPLt%2Fuploads%2FlhLHg2krqqG6X8Mr9y7N%2Fimage.png?alt=media&#x26;token=911a607a-bfff-4f8c-83ae-9b1d642f3a91" alt=""><figcaption></figcaption></figure>

## 3. Enter monitoring dashboard

```
pm2 monit runner2
```

<figure><img src="https://3015034387-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNKK8Y1uEALYsObbKnPLt%2Fuploads%2FLtlKFEb33iV2F9hHJsuf%2Fimage.png?alt=media&#x26;token=cf82e4be-a9f7-4110-87bb-6db097a24e8c" alt=""><figcaption></figcaption></figure>

## 4. Read the logs stream

```
pm2 logs runner2
```

<figure><img src="https://3015034387-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNKK8Y1uEALYsObbKnPLt%2Fuploads%2FYJmsplFsOv7Wqpllk1cl%2Fimage.png?alt=media&#x26;token=423c5b99-7013-4b51-8bad-4b302175f314" alt=""><figcaption></figcaption></figure>

## 5. Read last N lines of logs from stdout / stderr streams (`nostream` mode)

```
pm2 logs --lines <N> --nostream runner2
```

{% hint style="info" %}

#### Reading logs available even if the service was stopped - so it's useful to understand reasons of downtimes and so on

{% endhint %}

## 6. Stop a testnet

```
pm2 stop runner2
```

{% hint style="info" %}

#### When you stop the testnet and then run it again - the progress will be dropped and testnet will start from height 0 and epoch 0

{% endhint %}
