How to run cardano-node as service

Hi,

I’m setting up cardano pool following Cardano Course.below. So far all set up is working. However when I tried to run as service it is not working.
https://cardano-foundation.gitbook.io/stake-pool-course/lessons/lesson-1/config-files-run-node

I am using AWS Linux AMI version same as the one on the course. My login user is ec2-user.
Appreciate if you can share how you run cardano-node as service

here my cardano-node.service file

Blockquote
[Unit]
Description=Lion Pool
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
ExecStart= /usr/local/bin/cardano-node run
–topology testnet-topology.json
–database-path db
–socket-path socket
–host-addr 172.31.41.88
–port 3005
–config testnet-config.json
User=$USER
[Install]
WantedBy=multi-user.target

error status:

Hello,

Check if the binary files are located here /usr/local/bin/

You might be missing WorkingDirectory=[your working directory]. How else is cardano-node supposed to know where to find your configuration and topology? :slight_smile:

1 Like

Hi Alex,

Yes, my cardano-node is in /usr/local/bin

Yes, I have put WorkingDirectory.

Blockquote
[Service]
Type=simple
WorkingDirectory=$HOME/relay
User=$USER
ExecStart= /usr/local/bin/cardano-node run
–topology testnet-topology.json
–database-path db
–socket-path socket
–host-addr 172.31.41.88
–port 3005
–config testnet-config.json

Here the error

[Unit]
Description=Cardano Node
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
Restart=always
RestartSec=5
User=X
LimitNOFILE=1048576
WorkingDirectory=/opt/cardano/cnode/scripts
ExecStart=/bin/bash -l -c “exec /opt/cardano/cnode/scripts/cnode.sh”
ExecStop=/bin/bash -l -c “exec kill -2 $(ps -ef | grep [c]ardano-node.*./opt/cardano/cnode/ | tr -s ’ ’ | cut -d ’ ’ -f2) &>/dev/null”
KillSignal=SIGINT
SuccessExitStatus=143
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=cnode
TimeoutStopSec=5
KillMode=mixed

[Install]
WantedBy=multi-user.target

Hi Alex,

Thanks for sharing your service file. I will try it out.

step 7

https://www.coincashew.com/coins/overview-ada/guide-how-to-build-a-haskell-stakepool-node

same outcome. I have adjusted your script as follow

Blockquote
[Unit]
Description=Cardano Node
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
Restart=always
RestartSec=5
User=ec2-user
LimitNOFILE=1048576
WorkingDirectory=/home/ec2-user/relay
ExecStart=/bin/bash -l -c “exec /home/ec2-user/relay/start_relay_node.sh”
ExecStop=/bin/bash -l -c “exec kill -2 $(ps -ef | grep [c]ardano-node.*./home/ec2-user/relay/ | tr -s ’ ’ | cut -d ’ ’ -f2) &>/dev/null”
KillSignal=SIGINT
SuccessExitStatus=143
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=cnode
TimeoutStopSec=5
KillMode=mixed
[Install]
WantedBy=multi-user.target

I sent u above the guide… follow step 12 (assuming u are not using cntools right?)

When in doub, please never use variables like $USER or $HOME. Use absolute (pre-existing) paths with correct accress rights set and proper, existing usernames (which are in groups that allow to perform the requested action). Once you figured everything out, you still can revert to variables. In the beginning it’s just one more “variable” which might potentially cause problems.

I tried to reinstall using ubuntu and get the following error now.
I have chmod 644 to cardano-node.service and start_relay_node.sh.

cardano-node.service

Blockquote
[Unit]
Description=Lion Pool
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
WorkingDirectory=/home/ubuntu/relay
User=ubuntu
Group=ubuntu
ExecStart= /bin/bash -c ‘/home/ubuntu/relay/start_relay_node.sh’
[Install]
WantedBy=multi-user.target

Error status

Blockquote
cardano-node.service - Lion Pool
Loaded: loaded (/etc/systemd/system/cardano-node.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2021-04-18 13:18:59 UTC; 2min 27s ago
Main PID: 61918 (code=exited, status=126)
Apr 18 13:18:59 ip-172-31-24-217 systemd[1]: Started Lion Pool.
Apr 18 13:18:59 ip-172-31-24-217 bash[61918]: /bin/bash: /home/ubuntu/relay/start_relay_node.sh: Permission denied
Apr 18 13:18:59 ip-172-31-24-217 systemd[1]: cardano-node.service: Main process exited, code=exited, status=126/n/a
Apr 18 13:18:59 ip-172-31-24-217 systemd[1]: cardano-node.service: Failed with result ‘exit-code’.

bash cannot execute your /home/ubuntu/relay/start_relay_node.sh. Does ist have executable permissions?

chmod +x /home/ubuntu/relay/start_relay_node.sh

Thanks hanswurst.

Finally it solved. Such a relieve after trying a week. :blush:

1 Like