Getting a script to run on every boot (bfgminer & screen))


2 posts
by sjashton » Thu Nov 21, 2013 7:53 pm
I've got a RapsberryPi, connected up all the hardware, installed, updated & upgraded all the software.
This is now much easier... after a few months refresher with Ubuntu. So before I start connecting random hardware I'm doing a concept test with the unit and some ASIC miners. Then its Cental Heating & the solar panels. Then some kitchen appliances!

Installed & compiled 'bfgminer' (coin mining) via github
Installed 'screen' (multi-window terminal tool - start disconnected/reconnect to processes) via app-get.

This is first step to wiring up a lot of things in the house.
And for me it's good practice - I only learn when it goes wrong!

This is my BFGminer_RemoteRun script - which works as I want it when I run it over my PuTTy terminal:

#!/bin/bash
# BFGMiner [xxx@xxx.com]
# Run in background
# 'Screen' installed - screen -r to reattach

cd '/home/pi/bfgminer'
screen -dmS bfgminer ./bfgminer -o http://xxxx:xxxx -u xxxx -p xxxx -S icarus:all

I then amendeded /etc/rc.local as follows:

#!/bcn/sh -e
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi

# My Custom Scripts
# start
cd '/home/pi/bfgminer/'
./BFGminer_RemoteRun

When I run

/etc/rc.local OR ./bfgminer/BFGminer_RemoteRun

from prompt it runs one instance I can connect to with

screen -r <detached session>

pgrep -f bfg

Reports only one process.

When I restart the system I know the script runs; I know it's running server connected and updating as the pool shows process.

pgrep -f bfg 3 processes running!
screen -ls No detached screens to connect to(?).

But I can't connect to it to reconfigure hardware/pools etc over ssh - whihc is the whole point of this exercise - to stop using desktops/GUI and work command line full time.

What am I missing? At this point I'm guessing either:

Init.d scripts must execute differently - and I need to modify BFGminer_RemoteRun file contents/configuration

OR

'screen' needs different options to be parsed as a startup script.
I did try to add a user onto the system and get screen to run under that profile - but it kept prompting for a password.

Learnt a lot today but brain now dead.

Suggestions or directions would be wonderful!
If I can't get 'screen' to do this then I need an alternative
Posts: 5
Joined: Thu Nov 21, 2013 7:46 pm
by sjashton » Fri Nov 22, 2013 2:22 pm
It's amazing what a difference a good nights sleep and a hearty breakfast will make.

I have a solution -added a 'sudo' not a 'su' to the beginning of the main command line.
I orginally tried using 'su' to change to pi - but it kept prompting for a password or I had to store passsword in a file! ( I qualified full path names as that seems good practise.)

sudo -u pi /usr/bin/screen -d -m -S bfgminer ./bfgminer -o http://xxxx.com -u xxxx -p xxxx -S icarus:all &

There most have been a conflict between screen and user profiles. All the versions of bfgminer running in background where all owned as root. (From being run as rc.local at startup)

Now when I log into the ssh terminal and do 'screen -ls' I see a detached session running bfgminer as I always wanted to see!
Posts: 5
Joined: Thu Nov 21, 2013 7:46 pm