AT the end of this tutorial, I'll make it quick and sweet for those who don't care about the whys and just want the hows!
What will you learn?
You will learn here how to set up a couple of cron jobs per user, so that if the server is restarted or the dashd daemon crashes, it will automatically restart.
Why?
People have discussed this on the forums, but when I wanted to find the information, I simply couldn't or else it didn't work for me. Many thanks to everyone who has ever written tutorials on such things, or on the BCT forums because that's how I got the idea, how I learned how this works, and finally got it to work for me. Special thanks to GermanRed+ who gave me the final script which I just changed minorly (I simply put in the full path to my dashd program as it wasn't working otherwise)
Anyway, what we're going to do here is add two items to your cron jobs, per user.
Why per user?
You see, I have two users on one server (and two IP address if you're wondering) I like the one server setup because I only have to update dashd once for as many users I can fit on my machine (I highly suggest if you do this that you have a minimum 1 core, better 2- per masternode plus a minimum ~ 350 mb of ram - better 512.)
Another thing you need to know about my setup is that I put my dashd and dash-cli etc... into /usr/local/bin. By doing so, I can execute dashd from any user and it's run in a separate instance (that is, run it locally for each user)
Even if you only have one user per server, you can still use this bash script to restart your masternodes in case of a reboot/restart or crash.
So here we go!
First log on to a user account, lets say user1
Next we're going to open user1's crontab. Please type in:
crontab -e
the -e stands for edit. The first time you use crontab, you will be asked which editor you would like to use, I use nano, others like vi. Either one will do, and probably others that I'm not familiar with. Instructions here will be for nano. Please simply look up how to save in vi if you're using that editor. I think I remember nano was choice 2, so just enter 2 in the window and you will get a screen that looks like this:
use your arrow keys to get to the bottom of the file, and add these two lines:
@reboot /usr/local/bin/dashd
*/10 * * * * /home/user1/mn_watch.sh >/dev/null 2>&1
of course, replacing user1 with your user's name.
Finally,
"write" to file ctrl o
"exit and reset" ctrl x
Explaination:
The first line is pretty obvious. @reboot tells the computer at startup, that it is to start dashd, which is in the location /usr/local/bin/The -shrinkdebugfile hasn't worked for me, but it's supposed to clean out the debug.log file which tends to get huge over time and cause issues. If anyone knows what isn't right there, please let me know and I'll fix it in this tutorial. -shrinkdebugfile is unnecessary and happens automatically for logs over 10mb as noted below by UdjinM6 Thanks!
The second line is saying that once every ten minutes */10 ( = 60/10 and could also be written with commas between them but still in first position, separated by a space when finished like so: 0,10,20,30,40,50 ) the stated action should be performed. The way to read the 5 spots separated by a space is minutes, hours, weekdays, months and years. You can read more on how this works here: https://help.ubuntu.com/community/CronHowto .
In the illustration above, I had it set to 1 minute intervals so I could test it without waiting so long.
There is one issue:
When updating your daemon to a new version, your daemon may start up after you've shut it down.
However, the 10 minute intervals should be fine since we have 70 minutes before we're knocked down to the bottom of the masternode winners list. Also, when updating from a previous version, if you stop your dashd, you should have more than enough time to update before it's automatically turned back on. Just start your work after a 10th of the hour. This is set to the server's clock. So, start your work at say 12:10 or 1:20, or something like that and you shouldn't find your daemon started while you're working on updating it.
Finally, for non-protocol updates, which is the majority of updates, I don't even bother turning dashd off until I'm ready to restart it. It has no effect (that is, my new dashd isn't overwritten at shutdown). So I just do my updates and then restart dashd when I'm ready, never bothering to stop it before hand.
If you should need more time, you can always comment out the line in your crontab and put it back afterwords. Just comment it out with a #
And the rest:
The rest of the restart line is simply telling the computer to run the script located at /home/user1/mn_watch.sh
And finally, this >/dev/null 2>&1 is weird code that says "don't email any notifications, just dump it in this hole of no return". Because cronjobs want to send out email notifications, and frankly, I don't need no stinkin' notifications, I get enough spam.
Finally, after pasting in the two lines with the correct user's name, hit CTRL o to write it to the file and CTRL x to save it. Both vi and nano have the keyboard shortcuts written at the bottom of the screen.
What will you learn?
You will learn here how to set up a couple of cron jobs per user, so that if the server is restarted or the dashd daemon crashes, it will automatically restart.
Why?
People have discussed this on the forums, but when I wanted to find the information, I simply couldn't or else it didn't work for me. Many thanks to everyone who has ever written tutorials on such things, or on the BCT forums because that's how I got the idea, how I learned how this works, and finally got it to work for me. Special thanks to GermanRed+ who gave me the final script which I just changed minorly (I simply put in the full path to my dashd program as it wasn't working otherwise)
Anyway, what we're going to do here is add two items to your cron jobs, per user.
Why per user?
You see, I have two users on one server (and two IP address if you're wondering) I like the one server setup because I only have to update dashd once for as many users I can fit on my machine (I highly suggest if you do this that you have a minimum 1 core, better 2- per masternode plus a minimum ~ 350 mb of ram - better 512.)
Another thing you need to know about my setup is that I put my dashd and dash-cli etc... into /usr/local/bin. By doing so, I can execute dashd from any user and it's run in a separate instance (that is, run it locally for each user)
Even if you only have one user per server, you can still use this bash script to restart your masternodes in case of a reboot/restart or crash.
So here we go!
First log on to a user account, lets say user1
Next we're going to open user1's crontab. Please type in:
crontab -e
the -e stands for edit. The first time you use crontab, you will be asked which editor you would like to use, I use nano, others like vi. Either one will do, and probably others that I'm not familiar with. Instructions here will be for nano. Please simply look up how to save in vi if you're using that editor. I think I remember nano was choice 2, so just enter 2 in the window and you will get a screen that looks like this:
use your arrow keys to get to the bottom of the file, and add these two lines:
@reboot /usr/local/bin/dashd
*/10 * * * * /home/user1/mn_watch.sh >/dev/null 2>&1
of course, replacing user1 with your user's name.
Finally,
"write" to file ctrl o
"exit and reset" ctrl x
Explaination:
The first line is pretty obvious. @reboot tells the computer at startup, that it is to start dashd, which is in the location /usr/local/bin/
The second line is saying that once every ten minutes */10 ( = 60/10 and could also be written with commas between them but still in first position, separated by a space when finished like so: 0,10,20,30,40,50 ) the stated action should be performed. The way to read the 5 spots separated by a space is minutes, hours, weekdays, months and years. You can read more on how this works here: https://help.ubuntu.com/community/CronHowto .
In the illustration above, I had it set to 1 minute intervals so I could test it without waiting so long.
There is one issue:
When updating your daemon to a new version, your daemon may start up after you've shut it down.
However, the 10 minute intervals should be fine since we have 70 minutes before we're knocked down to the bottom of the masternode winners list. Also, when updating from a previous version, if you stop your dashd, you should have more than enough time to update before it's automatically turned back on. Just start your work after a 10th of the hour. This is set to the server's clock. So, start your work at say 12:10 or 1:20, or something like that and you shouldn't find your daemon started while you're working on updating it.
Finally, for non-protocol updates, which is the majority of updates, I don't even bother turning dashd off until I'm ready to restart it. It has no effect (that is, my new dashd isn't overwritten at shutdown). So I just do my updates and then restart dashd when I'm ready, never bothering to stop it before hand.
If you should need more time, you can always comment out the line in your crontab and put it back afterwords. Just comment it out with a #
And the rest:
The rest of the restart line is simply telling the computer to run the script located at /home/user1/mn_watch.sh
And finally, this >/dev/null 2>&1 is weird code that says "don't email any notifications, just dump it in this hole of no return". Because cronjobs want to send out email notifications, and frankly, I don't need no stinkin' notifications, I get enough spam.
Finally, after pasting in the two lines with the correct user's name, hit CTRL o to write it to the file and CTRL x to save it. Both vi and nano have the keyboard shortcuts written at the bottom of the screen.
Last edited by a moderator: