The DualMiner site has instructions for configuring cgminer to autostart. I think that those instructions are geared towards logging in as a specific user and outputting cgminer to the screen automatically.
Since my rig is running completely headless, my needs are a bit different. I want cgminer to run at start up, have a rotating log for trouble shooting, and I want it relaunched when it crashes. So rather than follow the DualMiner instructions, I decided to use the awesome daemontools from D. J. Bernstein.
If anyone is interested in going this route, here are the steps that I took:
Install daemontools:
sudo apt-get install daemontools-run daemontools
Create the directories for the run and log scripts:
sudo mkdir /etc/service/cgminer
sudo mkdir /etc/service/cgminer/log
Put the following script in a file called "run" in the /etc/service/cgminer directory:
#!/bin/sh
# cgminer/run
# run script for cgminer daemon
# Minimal environment
PATH=/usr/local/bin:/usr/bin:/bin:/
# Redirect stderr to std out so that our log will pick it up
exec 2>&1
echo "*** Starting service cgminer..."
# Exec cgminer, which preserves the same process. Change the path and options as needed.
# Note that you have to run cgminer in text-only, non-terminal mode. I opted to force that
# option here rather than rely on it being set correctly in the conf file.
exec /usr/local/bin/cgminer --config /home/pi/config/cgminer.conf.ltc --text-only
Note that you may have to change the path to the cgminer executable and your conf file above.
If you want logging enabled, then you need to put this script in a file called "run" in the /etc/service/cgminer/log directory:
#!/bin/sh
# cgminer/log
# log script for cgminer daemon
# Minimal environment
PATH=/usr/local/bin:/usr/bin:/bin:/
# Define the path to the log folder
logFolder=/var/log/cgminer
# Make a folder fo the cgminer log files
mkdir -p ${logFolder}
chmod 755 ${logFolder}
# Set up multilog to handle logging the output from cgminer. It will rotate after 10 meg and
# keep five copies.
exec multilog s10485760 n5 ${logFolder}
The above script will put the log files in the /var/log/cgminer directory. The current log file will be called "current". The parameters to multilog above indicate that it should limit the log file size to 10 meg, and that it should keep the most recent 5 log files. This way old log data is deleted and you won't run out of disk space.
You have to also make sure that both scripts are executable:
sudo chmod 755 /etc/service/cgminer/log/run
sudo chmod 755 /etc/service/cgminer/run
If you've done everything right, then cgminer should be running. If you reboot, cgminer will be auto started. If cgminer crashes, then daemontools will restart it automatically.
You can use the following command to check on the status of cgminer running under daemontools:
sudo svstat /etc/service/cgminer
And you can see what's happening in the log with a tail command like this:
tail -500f /var/log/cgminer/current
If you need to stop cgminer, maybe because you want to change the config file or other maintenance, this command will stop the cgminer service:
sudo svc -d /etc/service/cgminer
This command will start the service back up again:
sudo svc -u /etc/service/cgminer
A couple of thoughts regarding logging. First, I'm not sure how safe it is to run a Rasperry Pi from an SD card with lots of log churn. I'm not an expert, but I'd be concerned that at some point lots of log writes might wear out the flash. Again, I must stress that I don't know if this is a real problem or one that I've imagined.
In any case, my system is generating around 4 meg of log data a day. Since my rig is new, I want to review this log data. But at some point if my system is stable, I might disable logging in order to conserve flash write cycles.
Second, when I first set up logging, I could not get it to work. Apparently there's an issue with daemontools where if you create the service "run" script first, then you create the "log/run" script, the daemontools service scanner doesn't see the change and does not enable logging.
To work around this, I rebooted my system after configuring logging. After that, logging worked like a charm. There's probably a more elegant way to work around this issue, but I didn't look into it further.
Lastly, if you're interested in more information regarding daemontools, here are some links that I used to get my feet wet:
http://lgallardo.com/en/2013/05/06/daemontools-o-como-relanzar-un-proceso-si-muere/
http://blog.teksol.info/pages/daemontools/tutorial
http://thedjbway.b0llix.net/daemontools/overview.html
Hopefully someone finds the above info helpful.
EDIT: I decided to leave logging on indefinitely. It's just too useful for debugging miner problems. So I did go ahead and install a package called ramlog that keeps the log files in ram, committing them to disk only on reboot. This should save on flash wear and tear. Instructions for installing ramlog follow here.
First, you need to figure out how big to make the ramlog partition.
So how big is my log folder now?
sudo du -sh /var/log
9.9M /var/log
How much of that is the miner log?
sudo du -sh /var/log/cgminer
5.9M /var/log/cgminer
So the regular log files amount to about 4M on my Pi. I've set the miner logging to only keep 3 copies and limit them to 10 meg. I think that means it can grow to 30 meg (including the "current" log).
How much ram do I have left?
free -m
total used free shared buffers cached
Mem: 437 180 256 0 15 82
But I've seen it a lot lower (like 160M).
So I think 50 meg for the ramlog is probably enough and won't impact the system too bad. Once I knew how big to make my ramlog mount point, I followed these ramlog installation instructions:
https://raw.github.com/swirepe/personalscripts/master/pi/setup-ramlog.sh
In case the above URL goes away, here's the steps I took:
sudo apt-get install lsof
mkdir ~/packages
cd ~/packages/
wget https://raw.github.com/swirepe/personalscripts/master/pi/ramlog_2.0.0_all.deb
sudo dpkg -i ramlog_2.0.0_all.deb
echo "TMPFS_RAMFS_SIZE=50m" | sudo tee /etc/default/ramlog
sudo reboot
So now all log files are written to a RAM disk based mount point and have no ongoing impact on the flash. When the system is rebooted, the log files are committed to flash, and then read out on the other side, so they aren't lost. But that's a lot less wear and tear than continuously writing log file data.