I am trying to mine Ether on an AWS spot instances. However I came across two problems.
- AWS spot instances aren't persistent, meaning if the instance gets terminated the data inside will be gone.
- Geth and ethminer need to be run immediately after startup because you don't want to be paying attention when an instance starts or gets terminated.
Regarding the first problem I followed the instructions from this question on serverfault and now I can make spot instances somewhat persistent, any improvement of this method is welcome.
So this question is focused on the second obstacle. How can I make Geth and ethminer run from from startup, that means every time a spot instance becomes available
What I've done so far is trying to run a shell script at startup by including this on /etc/init.d/ with the following contents:
#!/bin/sh
#NOTE: tmux is a tool similar to screen
#Create a tmux season for geth
tmux new-session -d -s Gethtest
#Create a tmux season for Ethminer
tmux new-session -d -s EthminerTest
#Execute the commands in tmux
#Geth (this starts geth)
tmux send-keys -t Gethtest 'geth --rpc console' C-m
#Make a short pause to let geth sync with the main network
sleep 90
#Ethminer (this starts ethminer)
tmux send-keys -t EthminerTest 'ethminer -G --opencl-device 0' C-m
This script was inspired by this answer posted on stackoverflow which includes more details. Typing the same commands in command line works as expected (first begin Geth and let it synchronize and then start ethminer each within a tmux session). But making it run alone at startup doesn't work as expected, and that means: the script doesn't start neither Geth nor ethminer automatically at startup.
Any help regarding how to simplify, fix and/or improve any of both problems is welcome. Suggesting alternative methods are welcome too.