How do I run the Ubuntu node as a service?

The first thing you’ll want to do is create a systemd service file - in this example we will call our service “frog”

cd /etc/systemd/system/

sudo vi frog.service


[Unit]
Description=Cardano Core Node - FROG
After=syslog.target
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=5
User=[user]
LimitNOFILE=131072
WorkingDirectory=/home/[user]/
EnvironmentFile=/home/[user]/files/env/frog.environment
ExecStart=/home/[user]/.cabal/bin/cardano-node
+RTS -N2 -RTS run
–topology {TOPOLOGY} \ --database-path {DATABASE}
–socket-path {SOCKET} \ --host-addr {HOST}
–port {PORT} \ --config {CONFIG}
–shelley-kes-key {KES_KEY} \ --shelley-vrf-key {VRF_KEY}
–shelley-operational-certificate ${OPCERT}
KillSignal=SIGINT
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=frog-pool

[Install]
WantedBy=multi-user.target


*notes

replace “[user]” above with to a user that has no login permissions, and ideally dynamically created that ceases to exist when the service is stopped

ExecStart=/home/[user]/.cabal/bin/cardano-node
may be
ExecStart=/home/[user]/.local/bin/cardano-node

*-N2 refers to the number of cores your node will use on your system / vm (a quad core node would be represented by -N4)

*save and exit

sudo chmod 644 /etc/systemd/system/frog.service

Now you will want to create your environment file:

cd files
mkdir env
cd env
vi frog.environment


TOPOLOGY="/home/[user]/files/mainnet/mainnet-topology.json"
CONFIG="/home/[user]/files/mainnet/mainnet-config.json"
DATABASE="/home/[user]/cardano-node/db"
HOST=[host-ip]
PORT=[port]
SOCKET="/home/[user]/cardano-node/db/node.socket"
KES_KEY="/home/[user]/files/mainnet/kes.skey"
VRF_KEY="/home/[user]/files/mainnet/vrf.skey"
OPCERT="/home/[user]/files/mainnet/opcert"


*notes - change “[user]”, “[host-ip]” and “[port]” above accordingly

*save and exit

to start the node:
sudo systemctl start frog

to force the node to start on system boot:
sudo systemctl enable frog

to stop the node:
sudo systemctl stop frog

The above configuration is for a block producing core node. You will want to remove the following from the systemd service file on your relay nodes (remember to remove the trailing slash after the --config param too):

–shelley-kes-key ${KES_KEY} \

–shelley-vrf-key ${VRF_KEY} \

–shelley-operational-certificate ${OPCERT}

You will need to do more to be able to access LiveView while running as a systemd service, and this is not something I am familiar with

8 Likes