Crown watchdog script
This bash script is offered as a stopgap measure until the memory issue in Crown v0.13.x is resolved. Usage is entirely optional.
It is designed to keep a masternode or systemnode running by doing 2 things:
- Check if crownd is running and start it if not.
- Check how much memory is free and pre-emptively restart the daemon if it is judged too low. The default amount is rather arbitrary and may not be appropriate for everyone.
It makes some assumptions (which can easily be changed by the user):
- the crownd executable is in /usr/local/bin.
- the datadir is called .crown in the home directory of the user running the script.
- the “safe” amount of free memory is half a gigabyte. This is very arbitrary. Personally, I restart daemons on my VPS when the total free memory goes below 1GB. I have 1GB RAM, 4GB of swap and 4 or 5 coin daemons running on each VPS. A lot of users will have 1 GB RAM and 1–2GB of swap defined and 0.5GB is a guess at what is an appropriate number in that case.
- there is only one Crown masternode or systemnode installed on the VPS (it is possible to have more than one if you have multiple IPv4 addresses on the same VPS).
- you usually start the daemon without using any command line switches.
Login to your VPS as the user which runs the daemon and run the following commands:
chmod +x crownwatch.sh
sudo mv crownwatch.sh /usr/local/bin
If you haven’t configured the editor setting for crontab it will ask you which editor you want to use and suggest you use nano. Use whichever one you are most familiar with to add the following line:
*/15 * * * * /usr/local/bin/crownwatch.sh >>~/crownwatch.log 2>&1
The script writes a handful of lines explaining what it is doing. If you don’t want to record that output then leave off the redirection part (>>~/crownwatch.log 2>&1).
If systemd is installed on your VPS (it pretty much is on anything based on Ubuntu 16 and newer) you can use it to start the daemon and automatically restart it if it stops for any reason. It won’t do pre-emptive restarts if free memory is getting low. systemd is rather like the Borg, or Marmite, and its configuration is the subject for another article.