How do I run the Ubuntu node as a service?

Is there a guide to run Ubuntu as a service? Thank you in advance

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

4 Likes

Wow that’s a perfect guide. I don’t know how to thank you enough. Will update you after implementing the code

1 Like

Hi Frog!

This is very helpful thank you :slight_smile:

Could you pls clarify 3 things, thank you

  1. What/ how to create a ‘dynamic’ user with no login permissions and that ceases to exist on stopping the service?

  2. SyslogIdentifier=frog-pool
    What is this mean? Shouldn’t we change this?

  3. Could you clarify what this means?
    LimitNOFILE=131072

Thank you!

This is so cool…running a node as a system init daemon as if it were part of the OS, built into it. I’m using coincashew’s install guide, but I don’t know to what degree their installation process facilitates the incorporation of running my ubuntu nodes (core and relays) as system services. I still need to look at FROG’s guide. Has anybody had an easy time of using coincashew’s install procedure in conjunction with running their nodes as system services?
System services are easy to start, stop, and restart…if the same could be done with a node as a service, just as easily, that would make it a real breeze running, stopping, restarting your nodes as well as having these services start automatically during boot time process.

Is this procedure for a home set up only, or does it work in the cloud as well, say on a virtual machine, like GCE VM? Cloud VMs have extra constraints that might make it more difficult for this set up, but it’s worth trying.

If you successfully followed coincashew’s guide you should have a script named startBlockProducingNode.sh and essentially you just need to have your service call that. Section 18.6 Auto-starting with systemd services of their guide steps you through setting up the service. It uses tmux so you have a session to attach to after the service starts, which is especially helpful since coincashew’s installation procedure’s viewMode is liveView.

1 Like