Auto-Starting a Node
Configure your server to start your node on system boot-up
There are a few methods that can be used to start up a node on system boot-up. Automating the node to start when the server starts will help minimize downtime, allow the program to run in the background, and aid in making updates to the node software.
In this tutorial it's assumed that your node was installed at
/usr/local/bin. Please ensure the directories you use match your install. For example, programs in
/usr/local/bincan be run without specifying the directory. But for the script to run programs located in other directories you'll need to specify the location explicitly, like
For nodes installed with Docker, you'll simply need the location of the Docker shell script file (
Making a shell script with logging is a good place to start. You'll be able to use this script to start up the node.
First make a log file to store the outputs of the
sudo touch /var/log/peerplays.log
Find a good place to store the script file. For this tutorial, let's give it it's own directory. Then create a file named
Use the text editor of your choice (nano comes with Ubuntu) to create the
start.shfile as follows (please select the method which you used to install the node):
Manual or GitLab Installed Nodes
Docker Installed Nodes
witness_node &> /var/log/peerplays.log
Depending on where the programs were installed, you might have to specify the file location explicitly. For example:
./programs/witness_node/witness_node &> /var/log/peerplays.log
sudo ./run.sh start
In the case of Docker, we don't have to output the logs to another file because we're already maintaining the logs. You can view them with:
sudo ./run.sh logs
Save and exit the file. Now you'll set the file permissions.
chmod 744 /home/ubuntu/node_scripts/start.sh
You'll only need to use one method to ensure your node starts at system boot. This tutorial will cover two options you can use:
- Using a system service with
- Using a cron job with
Setting up a service using
Systemdon Ubuntu is the preferred method of auto-starting your node. It allows for greater visibility of the status of the service. We'll make a service file that uses the shell script.
Now that you have the shell file good to go you'll create a service file. Navigate to
/etc/systemd/systemand create a file named
peerplays.servicefile you'll enter:
Save the file and quit.
sudo systemctl enable peerplays.service
Make sure you don't get any errors.
sudo systemctl status peerplays.service
If your node is running, stop it with
ctrl + c, then start it back up with the service.
sudo systemctl start peerplays.service
Lastly, check the log file to ensure the node is running properly.
tail -f /var/log/peerplays.log
You're all done if you've chosen to auto-start your node with systemd. No need for cron!
Cron jobs are simple to set up. If all you need is to ensure that your node starts when your system boots, a cron job is good enough.
If this is the first time you've used crontab on your machine, you'll be prompted to pick a text editor.
Crontab will open a file with some comments which explain how to configure a cron job. All you'll need to do is to specify the following at the end of the file:
Save and quit the file. Now your script will execute whenever your system boots.
In some cases, the crond service needs to be enabled on boot for the configuration to function.
- To check if the crond service is enabled, use:
sudo systemctl status cron.service
- To enable this service, use:
sudo systemctl enable cron.service
You're all done if you've chosen to auto-start your node with cron. No need for systemd!
Investigation & Logs
Node: The general term for the software that an independent server operator runs to perform some service for the network to which it belongs. In the case of Peerplays, that means validating network transactions, facilitating sidechain asset transfers, providing a gateway to on-chain data, or supplying / validating external data for dapps.
System service (Systemd): On Linux based systems (Peerplays nodes require Ubuntu), systemd is a system and service manager. In essence, it's an init system used to bootstrap user space and manage user processes. Systemd is the name of the program.
Cron job (crontab): A time-based job scheduler in Unix-like operating systems. Users who set up and maintain software environments use cron to schedule jobs (commands or shell scripts) to run periodically at fixed times, dates, or intervals. Crontab (cron table) is the file that cron uses to schedule tasks.