Run the Node with Systemd

This section will work for both block producing nodes and relays. However, when we are ready to run our bp node with hot keys, we will change the startup script a bit.

Running the node with a manual shell command is fine for ensuring things work. However, for stable operations we're going to want to configure the node to run automatically. To accomplish this we are going to create a startup script and a systemd service that uses that script to start and run the node when the system boots. First let's create a startup script.

cd ~/preprodnet/scripts
nano node.sh

Use the following snippet as a template for your startup script. Please read carefully.

#!/bin/bash
#
# We will set a few variables to shorten our launch command
# Database Path
DB=/home/preprod/preprodnet/db
# Socket Path
SOCKET=/home/preprod/preprodnet/socket/node.socket
# Configuration File
CONFIG=/home/preprod/preprodnet/config/config.json
# Topology File
TOPOLOGY=/home/preprod/preprodnet/config/topology.json
# Host Address. We will set this to 'listen' for incoming connections
HOST=0.0.0.0
# Please change <your port> to the port for either your block producing node or relay
PORT=<your port>
#
# Command to run the node
#
/home/preprod/preprodnet/bin/cardano-node run --topology $TOPOLOGY --database-path $DB --socket-path $SOCKET --port $PORT --config $CONFIG --host-addr $HOST

ctrl+o to save and ctrl+x to exit. Make the script executable.

Test and execute your script.

Once again you should see output similar to this if everything was done correctly.

ctrl+c to stop the node.

Next we will create the service file for systemd.

Add the following text to the file you are creating with nano.

ctrl+o to save, ctrl+x to exit. Let's copy the file where it needs to go and give it the right permissions.

Start the service.

Check to ensure the service is active.

Now we will enable the service so it runs everytime the system boots.

Now let's run our first cardano-cli command and query the tip.

Note: If the node is still starting up or syncing, the cardano-cli command may fail if the node socket cannot be found.

The query command displays our block-height, epoch, era, sync progress, hash, etc.

Last updated