Pages:
Author

Topic: Is there a tutorial for using screen to auto start cgminer? (Read 29286 times)

legendary
Activity: 4634
Merit: 1851
Linux since 1997 RedHat 4
./cgminer   2> log.$now.$$.txt
newbie
Activity: 50
Merit: 0
For BTC Keeper

At the outset I dont know shit about Linux but the following works for me. It basically came from this post Topic but it took me a while to get it sorted out. Everybody who posts seems to assume that every one else reading has the same skill levels as they do and they leave little "Important" bits out. I will try not to do that so if it is all a bit basic I aplogise!

Use these two scripts, the first named "stminer.sh" the second named "cgmlaunch.sh" As you can see both these are .sh files. You need to create those .sh files with the posted text inside. And make them executable
----------------------------------------------
#!/bin/sh
screen -dmS 051 ./cgmlaunch.sh
------------------------------------------------
and
------------------------------------------------
#!/bin/sh
sleep 60
export DISPLAY=:0
xhost +
now="`date +%Y%m%d%H%M%S`"
cd /home/miner/cgminer-2.3.2
./cgminer   2>log.$now$$.10151.txt
------------------------------------------------
If you look at the second script you will see the line "cd /home/miner/cgminer-2.3.2"
That shows you the directory where both scripts need to be put ie your equivalent of /home/miner. Where miner is your "named" directory. You need to give both scripts execution rights by chmod or the easy way just use the properties box/permissions and check "allow execution". You need to change "cgminer-2.3.2" to whatever you have called your installed version of cgminer and it must be in that "/miner" directory

The first script starts Screen, names it .051 and then it starts the second script, which waits 60 seconds then starts cgminer and creates a log file called 10151.txt in your cgminer directory. If you dont want the log file delete "2>log.$now$$.10151.txt" from the last line of the second script
(Use the cgminer.config file in  /home/miner/.cgminer for your GPU parameters.)

To get the first script to run at start-up you need to use the Startup Applications in Ubuntu, go to System/Preferences/Startup Applications click Add, put in a description eg "Start CGMiner" then browse to find the first script, in my case called "stminer.sh" select it, make sure the box is ticked and exit.

If all has gone according to plan and I have not left any important little bits out. When you reboot you machine will eventually start and run your cgminer. BUT it will start in "Headless Mode"
You can ssh into the machine and use Screen to view the CGMiner data.
I am guessing but I think, if you dont want Screen to run then maybe if you were to select the second script ie "cgmlaunch.sh" instead of the first in the Startup Application then maybe it will start cgminer directly.

Hope this ease's the pain.

I am sure there are more elegant and sophisticated ways of doing the above. However this has worked flawlessly for me on two machines for more than 6 months. Both on USB boot and HDD boot and its Newbie do-able!


Edit:- corrected last line of the second script to read as per the correction in Kano's post below.

This is cut and paste of the last line of the second script from one of my running miners:-  ./cgminer 2>run.$now.$$.log10151.txt




full member
Activity: 195
Merit: 100
Finally got this working bump  Smiley

I know these are old post but please do Noob a favour and explain how

I am using Xubuntu 11.04 (on HDD) and CGMiner 2.3.2

I have followed the instructions in post #14 to the letter. (I think?)

 I can start the Miner from a terminal e.g “ Miner-launcher.sh” Everything works fine. Have Screen, SSH etc etc.
However I cannot get the thing to “auto start” via the /etc/rc.local
 (done  chmod +x  /etc/rc.local)

I have in /etc/rc.local as below, I have tried commenting out “rc.local” and “exit 0“ and “-e" with chmod +x after any changes
-------------------------------------------------------------------------------------
#!/bin/bash -e
/usr/local/bin/miner-launcher.sh 60 &


I notice you have a capital "M" there as in Miner-launcher.sh where the script has it not capitalized. I am not sure that you named the script Miner-launcher.sh, but if you did it would not launch from rc.local unless it matches case.
newbie
Activity: 50
Merit: 0
Finally got this working bump  Smiley

I know these are old post but please do Noob a favour and explain how

I am using Xubuntu 11.04 (on HDD) and CGMiner 2.3.2

I have followed the instructions in post #14 to the letter. (I think?)

 I can start the Miner from a terminal e.g “ Miner-launcher.sh” Everything works fine. Have Screen, SSH etc etc.
However I cannot get the thing to “auto start” via the /etc/rc.local
 (done  chmod +x  /etc/rc.local)

I have in /etc/rc.local as below, I have tried commenting out “rc.local” and “exit 0“ and “-e" with chmod +x after any changes
-------------------------------------------------------------------------------------
#!/bin/bash -e
/usr/local/bin/miner-launcher.sh 60 &
#
# rc.local
#
# 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.



exit 0
-----------------------------------------------------------------------------------------

For someone who knows Linux this is probably ridiculously easy!

Thanks
legendary
Activity: 1666
Merit: 1000
Finally got this working bump  Smiley
full member
Activity: 195
Merit: 100
Bump - yes i know it's old...
Is this still the best method?
Which part? There is no substituting the command like screen -dmS miner startminer.sh


What can be changed, is the manner in which the above command is invoked - on my Debian-based machines, rather than launch cgminer via /etc/rc.local and call it a day I've set it up to start as a system service. With some scripting this allows me to do control it like any other OS daemon, e.g.
Code:
/etc/init.d/bcm0 start - invokes the time-honored [i]screen -dmS bcm-0 bcm-start.sh cgminer[/i] command[sup](1)[/sup]
/etc/init.d/bcm0 stop
/etc/init.d/bcm0 restart
/etc/init.d/bcm0 getstatus - prints whether or not cgminer is up and running, returns an exit status 1 if it isn't
/etc/init.d/bcm0 getpid - prints the PID of the active cgminer executable or returns an exit status 1 if cgminer isn't running

The service can be trivially disabled via the daemon control tool [i]update-rc.d[/i]:
update-rc.d bcm0 disable

Cgminer is only invoked via an intermediary script, /usr/local/bin/bcm-start.sh, which can launch a whole array of miners (the other ones being phoenix, diabloMiner, and ufasoft's cpuminer)
This way, whatever miner I want to launch, I don't have to mess with the /etc/init.d files.

The X.org server - a prerequisite - is being launched the same exact way.

The logging module is also tightly integrated into the system, logging some pertinent parameters of the mining rig with a 6 minute interval.
Cgminer output is being kept on-record as well so that it is easily accessible should errors crop up and need to be trouble-shot.


To ensure update flexibility and safety, I have been using the following set up:
Four concurrent versions of cgminer can coexist; they are labeled cgminer-stable, -testing, -oldstable, and -oldtesting and reside in their own respective directories.
Upon being installed, a new cgminer compilation is assigned the testing status by default.
Its status can be changed, e.g. to stable at any given time.

All cgminer calls are processed via a symlink named cgminer-current which always links to one of the four directories.

To make sense of four cgminer executables which can in some cases have the same version number but are based on different git commits, I needed to create an automatic cgminer installer (cgminer-update.sh) which creates the version.info file (containing the git version) in the installation directory.
A fresh copy of cgminer source will be downloaded from git, compiled and automatically installed into /opt/bcm/cgminer-testing.


I find it that such a tight integration with the OS is the right approach to take in machines as purpose-built as mining rigs are.
I tried hard to fit miners and miner control into the OS as snugly as possible, to stay true to the "Debian way" - whatever is might be Wink


If anyone's interested, I might write a guide and share some code... just give me some time to do that, a week or two(2) as I do have a day job and other real-life commitments...

Does anyone want this?

Notes:
(1) actually, the user is also being changed with su bcminer so that cgminer doesn't run as root which would be a horribly wrong idea from the system security standpoint.
(2) ummm... how does a "4 to 6 weeks" timeframe sound to you, guys? Tongue
    

count me in. thanks.
donator
Activity: 1218
Merit: 1079
Gerald Davis
I tried your method jake and I can call miner-launcher manually and it starts cgminer however despite having the above line in etc/rc.local "nothing" happens on boot.  Any ideas?
I'll get to debugging it when I'm done with my work for today, it's gotta be some minor quirk as the code looks fine.
For the record, I came up with this three-file approach when JWU42 asked for advice.
I launch my miners in an even more convoluted way Smiley


It may not be a bug in your code maybe just by Linux noobishness showing (for a MS SQL database architect this is way outside my comfort zone Smiley ).  It seems like /etc/rc.local isn't even executing?  Is that possible?

On edit:  Don't have time to test it but I think it was just that I forgot to chmod +x rc.local ...
full member
Activity: 210
Merit: 100
I tried your method jake and I can call miner-launcher manually and it starts cgminer however despite having the above line in etc/rc.local "nothing" happens on boot.  Any ideas?
I'll get to debugging it when I'm done with my work for today, it's gotta be some minor quirk as the code looks fine.
For the record, I came up with this three-file approach when JWU42 asked for advice.
I launch my miners in an even more convoluted way Smiley
donator
Activity: 1218
Merit: 1079
Gerald Davis

/etc/rc.local should include this line, let's keep it clean:
Code:
/usr/local/bin/miner-launcher.sh 60 &
That 60 is passed as a parameter to miner-launcher. It will be used for specifying how long miner-launcher should wait before starting the miner.
The ampersand returns control to rc.local at once, without waiting for the whole minute until miner-launcher is done with its work.

I tried your method jake and I can call miner-launcher manually and it starts cgminer however despite having the above line in etc/rc.local "nothing" happens on boot.  Any ideas?
full member
Activity: 210
Merit: 100
For instance, when I install Ubuntu it always runs bluetooth as it boots up. Since I don't have anything bluetooth I resort to 'apt-get remove 'package' ' but some things are tied to network manager and audio so must be selective when on a usable desktop.
Forget apt-get, use aptitude. It has an awesomely useful parameter why to help you sort out the dependencies:

# aptitude why python
i   python-pyopencl Depends python (>= 2.5)


# aptitude why openssl
i   cups     Depends ssl-cert (>= 1.0.11)
i A ssl-cert Depends openssl (>= 0.9.8g-9)



You can also put any package (it does not have to be installed) on hold which will prevent installation, removal, or upgrade:
aptitude remove gnome-bluetooth && aptitude gnome-bluetooth= should do the job
full member
Activity: 196
Merit: 100
Web Dev, Db Admin, Computer Technician
...
with a compile cgminer from source section with suggestions on methods to locate dependancies.
To locate dpendencies I use 'apt-cache search' and 'apt-cache show', but they're not useful for things outside the repo's like libpcap or poclbm.
...
It's in the README already ...
I checked the libpcap README and there were no dependencies listed.
But 'poclbm' Huh Eh?
My bad, brain fade, I was thinking of p2pool when I wrote that. For compiling, I wanted one example that lists dependencies and one that didn't.
Quote
Dependencies for running from source:
Bitcoin 0.5.0 or higher
Python 2.5 or higher
python-argparse for Python 2.6 and lower
Twisted (Ubuntu package python-twisted)
legendary
Activity: 4634
Merit: 1851
Linux since 1997 RedHat 4
...
with a compile cgminer from source section with suggestions on methods to locate dependancies.
To locate dpendencies I use 'apt-cache search' and 'apt-cache show', but they're not useful for things outside the repo's like libpcap or poclbm.
...
It's in the README already ...
But 'poclbm' Huh Eh?
full member
Activity: 196
Merit: 100
Web Dev, Db Admin, Computer Technician
It's a good thing that jake262144 is n00b friendly... Cheesy

A Debian install guide would be excellent with a compile cgminer from source section with suggestions on methods to locate dependancies.
To locate dpendencies I use 'apt-cache search' and 'apt-cache show', but they're not useful for things outside the repo's like libpcap or poclbm p2pool.
A minimal install including only absolutely necessary services. For instance, when I install Ubuntu it always runs bluetooth as it boots up. Since I don't have anything bluetooth I resort to 'apt-get remove 'package' ' but some things are tied to network manager and audio so must be selective when on a usable desktop.

Code:
dpkg --get-selections | grep blue
bluez      install
gnome-bluetooth install
libbluetooth3 install
libgnome-bluetooth8 install

So far, this bash session has been great. Thanks.
full member
Activity: 210
Merit: 100
Why the sad face? Do you think I didn't read the man page?
I was just faster with man screen | grep Reattach  Cheesy
legendary
Activity: 1666
Merit: 1000
Reading manpage I see you are correct...  Embarrassed
full member
Activity: 210
Merit: 100
Is there a way to reattatch but if it is already attached, detach and then reattach.  Sometimes I check on rigs from multiple locations so it becomes
I mean I am lazy that is a LOT of typing.  
alias rbcm='screen -d -r cgm'

You don't want to go the '-d -R' way because -R would even create an empty screen session which won't help.
If there's no screen session that means cgminer must have died so we need to run the miner-launcher.sh

If for whatever reason the miner software gets unstable and keeps dying every now and then defining
alias nrbcm='screen -d -r cgm || miner-launcher.sh'
might be useful (n as in necro rbcm - raise from the dead if necessary Grin)
legendary
Activity: 1666
Merit: 1000
To re-attach to an attached session do...

Code:
screen -dR cgminer
donator
Activity: 1218
Merit: 1079
Gerald Davis
Oh, one other thing.
If having to constantly type screen -r cgm is bugging you, a good solution might be creating an alias in your .bashrc file.
You need to append the following line to ~/.bashrc:
Code:
alias rbcm='screen -r cgm'
Your system just learned a new command: rbcm (as in reattach bitcoin miner) will be translated to screen -r cgm.
Nifty.

Just keep in mind that when you su as root, you use root's home directory instead of your own so you need to update /root/.bashrc with that alias as well.

Is there a way to reattatch but if it is already attached, detach and then reattach.  Sometimes I check on rigs from multiple locations so it becomes
screen -r cgminer
"there is no session to attach"
screen -d cgminer
screen -r cgminer

I mean I am lazy that is a LOT of typing.   
legendary
Activity: 1666
Merit: 1000
Jake,

Thanks for this - let me get it working and will happily tip you for the efforts!
full member
Activity: 210
Merit: 100
Oh, one other thing.
If having to constantly type screen -r cgm is bugging you, a good solution might be creating an alias in your .bashrc file.
You need to append the following line to ~/.bashrc:
Code:
alias rbcm='screen -r cgm'
Your system just learned a new command: rbcm (as in reattach bitcoin miner) will be translated to screen -r cgm.
Nifty.

Just keep in mind that when you su as root, you use root's home directory instead of your own so you need to update /root/.bashrc with that alias as well.
Pages:
Jump to: