How to setup your Raspberry Pi to re-start Timekoin from a unexpected power failure.
If you are like me, your Pi sits in a corner somewhere just humming along. But what happens if the power goes out while you are away. Well, when it finally comes back on, your Pi will boot up. First it will run a disk check (on the SD card) which can take a while if it was in the middle of some activity when the power failed. Next after the OS boots, MariaDB will run it's own database integrity check upon starting, which can take a little longer, maybe almost 10 minutes sometimes. Finally, the device is up and ready, but unless you log back in and actually start the process, it won't do anything else.
The extra step to have it start after all these checks finish can be setup with one permission setting in Timekoin and one script file modification.
- First, login to your Timekoin Server and head over to the Options tab. Click on the Manage Hash Code Access button at the bottom.
- Next will create a permission to allow our script to start Timekoin. To do this, simply pick an empty field and start with a name. The Name is just descriptive, can be anything you like. For these instructions will call it "Start Timekoin".
- Next is the Hashcode, which is really just another name for the password. This is the password it will take to start the Timekoin Server. I would suggest picking something a little more creative than 12345 for security reasons.
- Next is the permissions allowed. To the right is a bunch of check boxes, we only need a check mark in the tk_start_stop box. Click the "Save Settings" button at the bottom and wait for the "Hashcode Settings Saved!" confirmation.
- Now, the next step requires editing one script file. The file is located at /etc/cron.hourly/start-timekoin
Code: Select all
# Start Timekoin Server script written by KnightMB (2014)
# Start Timekoin Process
# Start Watchdog
- Inside this file, both commands to start Timekoin + Watchdog are currently disabled with the # in front of them. To enable, simply delete the # in front of the command.
- But wait! You are not done. See the last part of the command &hash=12345" The hash=12345 is where the password goes that you just created earlier. The 12345 is just an example. Set this to your password, example &hash=mypasswordhere" Then you can save the file and exit.
You are finished. You might ask, "Isn't this going to keep starting it over and over?" Nope, the command only starts the process. If it is already running, it will simply be ignored.
Next you might ask "Why the hourly cron job?" Mainly because if the system has the unexpected power failure, it is going to spend time doing disk and database checks. If you try to start Timekoin in the middle of these straight from boot up, it just simply won't work or could miss. So to avoid that, a job that runs over and over will eventually get the system up and running again. Because the Pi system boots and has to reset it's own clock, the hourly cron job is usually run last once the system is finished doing other task and if it is too busy, at least it will try the command in the next hour just in case, every hour until the Timekoin is running again. So while it is not an instant start from power failure process, works more like a eventually start from power failure process.
Of course, it is not 100% bullet proof process because if the SD card becomes damaged for any reason (power surge, power brown out, power flipping), it won't do much good if the system can't boot.