Setting Up Cardano service to start and stop the nodes
Now that we know that our node is functioning properly we need to start it using the service so it will always run in the background
Create file cardano--node.service in /home/cardano and paste the following text after running the command line
[Unit] Description=Shelley Pioneer Pool
[Service] Type=simple EnvironmentFile=/home/cardano/cnode/config/cardano-node.environment ExecStart=/home/cardano/.local/bin/cardano-node run --config $CONFIG --topology $TOPOLOGY --database-path $DBPATH --socket-path $SOCKETPATH --host-addr $HOSTADDR --port $PORT KillSignal = SIGINT RestartKillSignal = SIGINT StandardOutput=syslog StandardError=syslog SyslogIdentifier=trgt_event LimitNOFILE=32768
Restart=on-failure RestartSec=15s WorkingDirectory=~ User=cardano Group=users
nano ~/cardano-node.service
We created the file in a temporary location because Cardano user does not have rights to create a file where we want it, so Now we need to copy it in its permanent place using sudo command.
sudo cp ~/cardano-node.service /usr/lib/systemd/system
Now we need to create a second file. and paste this text with your cardano port number instead of 1234 (insert this text)
CONFIG="/home/cardano/cnode/config/mainnet-config.json" TOPOLOGY="/home/cardano/cnode/config/mainnet-topology.json" DBPATH="/home/cardano/cnode/db/" SOCKETPATH="/home/cardano/cnode/sockets/node.socket" HOSTADDR="" PORT="1234"
nano ~/cnode/config/cardano-node.environment
Now we need to enable the cardano node
sudo systemctl enable cardano-node
Now we need to start the node. ( to stop the node you will replace "start" with "stop") in the command line
sudo systemctl start cardano-node
Now we need to check the status. If everything is working correctly you will see green text "Active Running"
sudo systemctl status cardano-node
Copy link