First, lets talk about rebooting.. Under Linux, normal users can't issue a reboot command without sudo and entering a password. While this won't be an issue for some as they already installed as root, for those that are running without root privileges it presents a problem as the user might not be there when the script wants a password entered.. The way to allow a user to use the reboot command without a password is to do the following:
sudo visudo
username ALL=NOPASSWD: /sbin/reboot
jondecker76 ALL=NOPASSWD: /sbin/reboot
(press ctrl + x when finished editing the file)
This will allow a normal user to run the reboot command WITHOUT having to use a password (though the command must still be prepended by 'sudo')
Ok, now that you can reboot from the cli without a password, lets make a simple lockup script:
1) Create a file, lockup.sh in the smartcoin directory
2) Lets give it some contents:
#!/bin/bash
# Reboot the computer because of the lockup condition
sudo reboot
3) We need to make sure the script is executable
chmod +x ~/smartcoin/lockup.sh
Thats it! When a lockup is found, the computer will now reboot its self. Assuming that you have smartcoin setup to start automatically on startup, then the computer will reboot, and smartcoin will continue on its merry way.
Perhaps you only want the computer to reboot after 2 lockups. We just need to change lockup.sh to something like:
#!/bin/bash
if [[ -f "/tmp/failed_once" ]]; then
# We created /tmp/failed_once so we must have already failed once. Lets reboot!
sudo reboot
else
# /tmp/failed_once has not been created yet. Lets create it now so that if another lockup happens, we will know its the 2nd time!
touch /tmp/failed_once
fi
Perhaps you want to send yourself an email or text message when this happens so you can investigate. There are many ways to send an email, but I'll use sendemail for the example. (Most cellular carries have special email addresses for your account that will forward them to your phone as a text message, this allows you to send text messages via commandline email programs!) For this example, I'm also using the gmail smtp relay (you need a gmail account to use their smtp relay, though you can use your ISP's smtp relay if you wish)
first, install the sendemail program and some dependencies:
sudo apt-get install sendemail libnet-ssleay-perl libio-socket-ssl-perl
Now, we just need to add some email stuff to the script:
#!/bin/bash
if [[ -f "/tmp/failed_once" ]]; then
# Lets email ourselves!
sendemail -f "[email protected]" -t "[email protected]" -u "Lockup Detected!" -m "A lockup event was detected! Machine is automatically rebooting!" -s "smtp.gmail.com" -o tls=yes -xu your_gmail_username -xp your_gmail_password
# We created /tmp/failed_once so we must have already failed once. Lets reboot!
sudo reboot
else
# Lets email ourselves
sendemail -f "[email protected]" -t "[email protected]" -u "Lockup Detected!" -m "A lockup event was detected! Smartcoin is going to restart the miners now, but if another lockup happens we will reboot!" -s "smtp.gmail.com" -o tls=yes -xu your_gmail_username -xp your_gmail_password
# /tmp/failed_once has not been created yet. Lets create it now so that if another lockup happens, we will know its the 2nd time!
touch /tmp/failed_once
fi
- Replace '[email protected]' with the email address you wish to receive the message.
- the from (-f) parameter can contain any email address, even your own. Of course, [email protected] is just an example - its doesn't exist, but it will work
- If you use a different smtp server than google, you may or may not need the "-o tls=yes" part, depending on what smtp server you use.
One last thing.. I mentioned text messages. Here is a brief list of carriers and what email address you need to send to for you to receive a text on your cell phone:
AT&T [email protected]
Example: [email protected]
Cingular [email protected]
Metrocall [email protected]
Nextel [email protected]
Sprint PCS [email protected]
T-Mobile [email protected]
Verizon [email protected]
ALLTEL [email protected]