# TopologyUpdater.sh

## Overview

This script was not created by me but by The Guild Operators group.  These guys created CNTools which is the best thing since sliced bread.  For now here is a list of the contributors:\
[Markus](https://github.com/gufmar)\
[Pal Dorogi](https://github.com/ilap)\
[OCG](https://github.com/oldcryptogeek)\
[RedOracle](https://github.com/RedOracle)\
[Papacarp](https://github.com/papacarp)\
[Bergr01](https://github.com/bergr01)\
[Ola Ahlman](https://github.com/Scitz0)\
[SmaugPool](https://github.com/SmaugPool) [Priyank](https://github.com/rdlrt)\
[Psychomb](https://github.com/psychomb)\
[PegasusPool](https://github.com/PegasusPool)\
[Matthijs](https://github.com/matthijs-aeon)\
[Marek](https://github.com/mmahut)

For a more updated list, check out:  <https://cardano-community.github.io/guild-operators/Contributors.html>

There are about 4 methods to updating/getting into the topology network. This method after 3 hours allows you to pull a list of peers in topology to update your topology logs.\
Notes:\
\--this is only done on your relays, not your core.\
\--script location/info:  <https://cardano-community.github.io/guild-operators/Scripts/topologyupdater.html>


# Create TopologyUpdater logs folder & download script

## Create Logs folder:

```
cd ~/cardano-node
mkdir logs
```

{% hint style="info" %}
&#x20;Now that we've created the logs folder, let's down the script.
{% endhint %}

```
cd ~/cardano-node/scripts
curl -s -o topologyUpdater.sh https://raw.githubusercontent.com/cardano-community/guild-operators/master/scripts/cnode-helper-scripts/topologyUpdater.sh
chmod 750 topologyUpdater.sh
```


# Modify topologyUpdater.sh script

## Modify script

In this step we'll modify the topologyUpdater script:

```
$ nano topologyUpdater.sh
```

![Edit the script like above, relay1 or relay2](https://4240409876-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MBFpjOg1dwoKNI3vNAW%2F-MCtN81iEryVPhhtGzym%2F-MBG597n6F3rNGa94rHS%2FtopologyUpdater1.16.png?alt=media\&token=89de4c56-b316-42c6-b38c-7b98657e700e)

{% hint style="info" %}
&#x20;Save the changes by pressing: ctrl+o\
&#x20;Then Enter exit editor: ctrl+x
{% endhint %}

Once you have made your edits, you can check to see if the script runs correctly by:

```
./topologyUpdater.sh
```

If your edits are good, you should see a line stating "nice to meet you".

If you have error go back up and edit the script again and try again.  If you still end up with an error please ask in telegram channel.


# Configure crontab

## What is cron?

The software utility cron is a time-based job scheduler in Unix-like computer operating systems. Users that set up and maintain software environments use cron to schedule jobs to run periodically at fixed times, dates, or intervals.

In our case, we want to configure cron scheduler by editing the crontab file which controls scheduling:&#x20;

```
crontab -e
```

At the bottom of the commented list that pops up, copy/paste the line below:

```bash
25 * * * * /home/cardano/cardano-node/scripts/topologyUpdater.sh
```

The picture below is an example of what you should have:

![](https://4240409876-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MBFpjOg1dwoKNI3vNAW%2F-MBG63OE5-tfMth9Nwea%2F-MBG9ZVSzyVT62VMPyPW%2Fcrontab.png?alt=media\&token=a5ebe262-04a6-40c3-8bea-be8f5ea046f7)

{% hint style="info" %}
&#x20;Save the changes by pressing: ctrl+o\
&#x20;Then Enter exit editor: ctrl+x.
{% endhint %}

We are finished with setting up crontab to run our topologyUpdater.sh script at 25 mins after the hour each hour.


# Check topologyupdater logs

## Checking the logs

Let's go to the logs folder we created and check our topologyUpdater logs:

```
cd ~/cardano-node/logs
cat topologyUpdater_lastresult.json
```

{% hint style="info" %}
&#x20;There should be a nice to meet you line, then you will see "glad you are staying with us".\
&#x20;After 3 to 4 hours of "glad you are staying with us" we can use the clio website in the next step to pull relays in the topology to populate our relay topology files.
{% endhint %}


# Create script to grab topology peers

## Creating the topology\_push.sh script

Move to your scripts directory and open the new script:

```
cd ~/cardano-node/scripts
nano topology_push.sh
```

Copy/paste the following lines into the new script topology\_push.sh:

```bash
#!/bin/bash

curl -s -o /home/cardano/cardano-node/configuration/relay1/mainnet_candidate-topology.json "https://api.clio.one/htopology/v1/fetch/?max=7&customPeers=CoreIP:3000:4|Relay2:3002|relays-new.mainnet-candidate.dev.cardano.org:3001:2"
```

{% hint style="info" %}
the topology.json file name changes on each new genesis as well as the relays-new address.  If in doubt, check your topology file name and open the new topology file for the current genesis and see what relays-new address it shows.
{% endhint %}

Now we need to edit the script, check the picture below to see what items need changed:

![](https://4240409876-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MBFpjOg1dwoKNI3vNAW%2F-MCsXFISvY2pked9xt0T%2F-MBGSGc2gZgCMGO1e8pt%2Ftopologypushv2.png?alt=media\&token=446b718a-be2f-4e5a-9bbe-8cccce9fbba9)

{% hint style="info" %}
&#x20;Save the changes by pressing: ctrl+o\
&#x20;Then Enter exit editor: ctrl+x
{% endhint %}

Once you are done with the edits, we can test it out after topologyUpdater has ran successfully for 3 hours you will be able to use this new script.  Let's set the execute permissions:

```bash
chmod +x topology_push.sh
```

Once you have been running topologyUpdater for 3 hours (check your logs) you can manually execute the following:

```bash
./topology_push.sh
```

This will go out, pull relay peers in the topology and automatically update your topology file.

Remember you MUST close the relay then restart it for the relay to read this new topology file.


