Help! The Debug.log on my Smartnode is using all my disk space
So you have got your shiny Smartnode up and running, all has been well, then suddenly it keeps crashing, or the status is changing to NEW START REQUIRED. It's been diagnosed that debug.log is taking all the space. Some folks are suggest using cron scripts to clean the logs.
Well, there is another, smarter way. This article guides through an elegant approach to keep those logs for eating all your disk space, so your smartnode can stay on, so you can earn those smarts.
1. Logrotate
Logrotate is a small tool designed to rotate logs on a linux system. It's perfect to use for that wretched debug.log which is causing you pain. This configuration will compress each hour of logs generated, and save 8 hours only, then overwrite the oldest one.
2. Caution
This tutorial assumes that you are not using any other method to manage your logs eg cronscripts. If you are you, it's advisable to disable them first before continuing.
3. Logon to your Smartnode
Using your SSH client (eg Bitvise, PuttY) on your PC or Terminal on your Mac, logon to your smartnode. Logon using your smartadmin user - do not use root to perform these actions
4. Check the version
We need to check we have the latest version of logrotate, so type the following
logrotate --version
smartadmin@nyc-sn2:~$ logrotate --version
logrotate 3.8.7
The current version is 3.8.7. Ensure you also have the same version.
5. Create a Logrotate Configuration
We will create a logrotate configuration file to allow logrotate to manage the debug.log for your smartnode. There are number of editors available on linux (vim, nano and pico) so use the one that suits, and type the following
VIM
vi logrotate.conf
Nano
nano logrotate.conf
Pico
pico logrotate.conf
Whichever editor you use the file should be edited to include the following
/home/smartadmin/.smartcash/debug.log {
hourly
missingok
rotate 8
compress
create
}
(Note this assumes your username is smartadmin. If you are using a different user name, please change as required)
Save the file.
Now check the file is correct, by typing:
cat logrotate.conf
It will display the contents of the file
smartadmin@nyc-sn2:~$ cat logrotate.conf
/home/smartadmin/.smartcash/debug.log {
hourly
missingok
rotate 8
compress
create
}
6. Testing Logrotate
Now it's configured, let's test if it works.
Type in the following
logrotate /home/smartadmin/logrotate.conf --state /home/smartadmin/logrotate-state --verbose
(Note: replace smartadmin with your username if it is different)
smartadmin@nyc-sn2:~$ logrotate /home/smartadmin/logrotate.conf --state /home/smartadmin/logrotate-state --verbose
reading config file /home/smartadmin/logrotate.conf
Handling 1 logs
rotating pattern: /home/smartadmin/.smartcash/debug.log hourly (8 rotations)
empty log files are rotated, old logs are removed
considering log /home/smartadmin/.smartcash/debug.log
log does not need rotating
If the output is as above we can move to next step.
7. Enabling Logrotate
To ensure logrotate is always running we must make an entry in the crontab. To do show please type:
crontab -e
Edit this file and include the following line:
20 * * * * /usr/sbin/logrotate /home/smartadmin/logrotate.conf --state /home/smartadmin/logrotate-state
Save the file.
This will save the logs every 20 mins past the hour.
8. Restart Cron Service
The final step is to restart the cron service. To do this please type the following:
sudo service cron reload
Ok, now we are ready. Every hour the debug.log will be compressed and only 8 hours of log will be saved. Hopefully, this will resolve the debug.log issues smartnode users are facing in a much more elegant manner. Happy days!
9. Donations
If you found this article useful please feel free to donate smarts to SkbXDz8FDc6L9kGv6o4f96EAibrrGmZktu