# Bash Script to Keep the Orchestrator Alive

**URL:** https://forum.hypercore.one/t/bash-script-to-keep-the-orchestrator-alive/486
**Category:** How To
**Created:** [August 31, 2024, 8:11pm UTC](https://forum.hypercore.one/t/bash-script-to-keep-the-orchestrator-alive/486 "2024-08-31T20:11:48Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![0x3639](https://forum.hypercore.one/user_avatar/forum.hypercore.one/0x3639/32/33_2.png) [@0x3639](https://forum.hypercore.one/u/0x3639)
#### Post date: [August 31, 2024, 8:11pm UTC](https://forum.hypercore.one/t/bash-script-to-keep-the-orchestrator-alive/486/1 "2024-08-31T20:11:48Z")

</div>

## Background

If the orchestrator loses connection to the `znnd` node or `eth` node it will shut down regardless of how the service is setup.

Here’s a bash script that checks if the `orchestrator` service is running, and if not, starts it and logs an event to `/var/log/syslog`. You can then set this script to run as a cron job every minute.

### Step 1: Create the Bash Script

1. Create the script, for example, `nano /usr/local/bin/check_orchestrator.sh`.

```bash
#!/bin/bash

# Check if the service is running
if ! systemctl is-active --quiet orchestrator; then
  # If not running, start the service
  systemctl start orchestrator
  
  # Log to syslog
  logger "Orchestrator service was not running and has been started."
fi

```

1. Make the script executable:

```bash
sudo chmod +x /usr/local/bin/check_orchestrator.sh

```

### Step 2: Set Up the Cron Job

1. Open the cron job editor:

```bash
crontab -e

```

1. Add the following line to run the script every minute:

```bash
* * * * * /usr/local/bin/check_orchestrator.sh

```

### Explanation:

- `systemctl is-active --quiet orchestrator`: This checks if the `orchestrator` service is running. The `--quiet` flag ensures that no output is produced.
- `systemctl start orchestrator`: This command starts the `orchestrator` service if it is not running.
- `logger "Orchestrator service was not running and has been started."`: This logs a message to `/var/log/syslog`.

This setup will ensure that the `orchestrator` service is checked every minute, and if it is found to be stopped, it will be started, and an entry will be made in the syslog.
