prdatur / phpminer

PHPMiner is a web interface for cgminer on linux machines
Other
35 stars 15 forks source link

Support for multiple miner apps on a rig #4

Closed DanielNagy closed 10 years ago

DanielNagy commented 10 years ago

So, with the advent of multiple hashing types, it will be a need to be able to switch between them seamlessly from the web interface

ie, cgminer --scrypt, or --keccak. or even between cgminer and sgminer.

conceptually i foresee the following setup on a miner rig..

2 copies of cgminer, installed as following /opt/cgminer-scrypt /opt/cgminer-keccak both contain cgminer.conf files.

phpminer_rpcclient would be configured with multiple miner applications, and know the paths / config file locations.

I think it would be important that each mining software has its on cgminer.conf file as each could require different settings for performance tuning.

when adding pools to phpminer, we would need to specify the hash type for this to work correctly.

The role of phpminer_rpcclient would be to quit/kill cgminer-scrypt, and start up cgminer-keccak, if a pool switch requires a change in hashing.

Of course this shouldn't be limited to only 2 mining applications, but potentially many.

I think sgminer is possibly the future for gpu mining anyways, and it wouldn't surprise me if they bring out a build which also supports keccak natively, and be simplier to switch, ie, pool configuration contains details of hash type, rather than having to restart the miner with scrypt or keccak support enabled.

prdatur commented 10 years ago

Please check the forum entry for additional infos about your self developing :)

DanielNagy commented 10 years ago

Christian said he was working on something, so to open a issue about it for him :+1:

prdatur commented 10 years ago

Who you mean with "Christian" ? sheinsha ? Because my name is also Christian :)

nicoschtein commented 10 years ago

? I'm not Christian lol, im Nicolas btw

prdatur commented 10 years ago

So just to make it clear, in the forum "prdatur" = me :)

DanielNagy commented 10 years ago

much confusion! lol

Nicolas, you said you were working on it, and to create a new issue for you from issue#2 https://github.com/prdatur/phpminer/issues/2

prdatur commented 10 years ago

Daniel could tell me how you referenced this? didn't found away by my self to do this. :)

DanielNagy commented 10 years ago

I just paste the URL of the issue i want to reference.

DanielNagy commented 10 years ago

I'm implemented this feature using the custom commands feature.

Basic configuration as follows

I have 3x config.php files, named config-scrypt.php, config-sha3.php and config-vert.php and each one is configured to suit the miner software used.

Previously i have manually copied config-scrypt.php to config.php if i wanted to use scrypt, and restarted the miner / phpminer_rpcclient

in the bottom of each config file, i have the following code for custom commands.

$config['custom_commands'] = array( 'scrypt' => array( 'title' => 'Switch to Scrypt', 'command' => '/path/to/phpminer_rpcclient/switchto.sh scrypt', 'confirmation_required' => false, 'has_response' => false, ), 'sha3' => array( 'title' => 'Switch to SHA-3/Keccak', 'command' => '/path/to/phpminer_rpcclient/switchto.sh sha3', 'confirmation_required' => false, 'has_response' => false, ), 'vert' => array( 'title' => 'Switch to Vert', 'command' => '/path/to/phpminer_rpcclient/switchto.sh vert', 'confirmation_required' => false, 'has_response' => false, ) );

I only have 2 commands per php file, I remove the "switch to" command for the selected command, no point switching to the same algo already running.

The contents of switchto.sh is as follows


killall -s 9 cgminer
killall -s 9 vertminer

if [ $# -eq 0 ]; then
        echo "No Arguements supplied"
        echo
        echo "$0 <alg to switch to>"
        exit 1
fi

case $1 in
        "scrypt")
                cp /path/to/phpminer_rpcclient/config-scrypt.php /path/to/phpminer_rpcclient/config.php
                echo "Copied config for scrypt"
        ;;

        "sha3")
                cp /path/to/phpminer_rpcclient/config-sha3.php /path/to/phpminer_rpcclient/config.php
                echo "Copied config for sha3/keccak"
        ;;

        "vert")
                cp /path/to/phpminer_rpcclient/config-vert.php /path/to/phpminer_rpcclient/config.php
                echo "Copied config for vert"
        ;;
        *)
                echo "$1 Algo does not exist"
                exit 1
        ;;
esac

sudo /etc/init.d/phpminer_rpcclient restart```

As you can see, it issues a killall command for ALL miners (simpler than doing pidof searches of running processes). If you use sgminer, add that as well.

It then copies the appropriate config file to config.php.

It then restarts the phpminer_rpcclient.

Because starting/stopping/restarting the command phpminer_rpcclient needs root, i've added the "user" to sudoers as following so it can be called without password (sudo visudo)
```%username ALL=(root) NOPASSWD: /etc/init.d/phpminer_rpcclient```

One issue i have, is even though the custom command 'has_response = false', when you switch, phpminer complains about loosing connection to rpc client. Press ok, and wait (The miner should restart upto 1 minute when the cron job tries to restart the miner again, if configured.. Otherwise press the stop/start button).
neurocis commented 10 years ago

Insert shameless plug to coinvert here ... :)

DanielNagy commented 10 years ago

I did see your coinvert code, but since custom commands were available, i implemented mine that way. i also don't use BAMT

neurocis commented 10 years ago

No worries Daniel, it was meant in good humor. Writing your own is all in all the better way to go as then you understand the mechanics (like I am still trying to figure out all the phpminer php so I can actually enhance it for pull request). I've gotten so rusty at php in the last few years living in a MS world and Chris has been so active its hard to keep pace and decipher his code at the same time (in a grateful way)!

Cheers!

DanielNagy commented 10 years ago

my php skills are not that good either.. My implementation above is a "hack" given that custom commands were available.

I'm sure christian could make this far more elegant and build into phpminer and the rpcclient (hint hint)

But for now, this serves my purpose :)

prdatur commented 10 years ago

For your hack i would recommend to do the killall commands after checking for valid arguments, else it would be just killed when no args are provided.

@neurocis Thx for the flowers :P Hope you like my code. In the first time i just didn't documented all things. But if you look at the new init.js within the view/main i think this will be a good start :) So others like you can get rid of what i am cooking.

prdatur commented 10 years ago

Does anybody has an idea how the rpc client can detect which miner is currently running? I will add a config file where the "current miner" is stored, so i can use this for the api commands. But for example when you just update to the new commit with this feature it does not know which miner is currently running. Another example is when a user just start a different miner, how could rpc client can detect the correct one?

prdatur commented 10 years ago

Hi there, could you please test how it works?

A hint how to configure multi miner apps. rpc client => config.php

// Holds all available miners for this rig.
$config['miners'] = array(

    // First miner named "SGMiner"
    'SGMiner' => array(

        // The ip to the miner api (which is configured at miner.conf as api-allow (This needs W: prefix for priviledge access)
        'ip' => '127.0.0.1',

        // The miner api port.
        'port' => 4028,

        // Miner, can be cgminer or sgminer
        'miner' => 'sgminer',

        // Miner binary, this can be left empty if the binary is the same as the miner. For example miner = cgminer, miner_binary = cgminer or on windows cgminer.exe
        'miner_binary' => '',

        // The path + file where the cgminer.conf is.
        // Please make sure that the user which run's this script has the permission to edit this file.
        'cgminer_config_path' => '/opt/cgminer/cgminer.conf',

        // The path where the cgminer executable is.
        // Please make sure that the user which run's this script has the permission to start cgminer.
        'cgminer_path' => '/opt/miners/sgminer',

        // Path to AMD SDK if available (Normally this is only needed within Linux and can be ommited also on linux)
        'amd_sdk' => '',
    ),

    'CGMiner' => array(
        'ip' => '127.0.0.1',
        'port' => 4028,
        'miner' => 'cgminer',
        'miner_binary' => '',
        'cgminer_config_path' => '/opt/cgminer/cgminer.conf',
        'cgminer_path' => '/opt/cgminer',
        'amd_sdk' => '',
    ),
);

Restart rpc client. Go to pool -> edit the pool group and set the miner app.

prdatur commented 10 years ago

ah and please make sure the user which runs rpc client has access to write files within the rpc client directory. this is needed to create the config.json for remember the current miner app.

DanielNagy commented 10 years ago

Sorry, the kill all should be after the arg check, your right..

As for seeing which miner is running... Good one. With cgminer it has scrypt and Keccak, which is defined in the configuration. So identifying which is running won't be possible.

Maybe create a lock file on the rig showing which algo /miner instance was started, with the same pid # of the mining process when it's started.

prdatur commented 10 years ago

Yes that mostly what the config.json does, without the pid thing. But when it has changed it would be nice to also recognize the miner. for example all things done with phpminer. lock file written also maybe with the current pid and so on. Then the user goes to rig. kill the miner and start miner b. How can now rpc client detect which miner is running? That's my problem :P Currently i fallback to the first configured miner app.

DanielNagy commented 10 years ago

If it's manageable from phpminer, and the user kills the miner process, they should start it again with phpminer.

However, the pools would be a recognisable way to know what miner is running. Since the pools are tagged with the miner too, maybe that's how you can detect which miner..

Unless of course they manually edit the cgminer.conf file and add a new pool unknown to phpminer..

prdatur commented 10 years ago

hmm it would work with pool check, the only problem is i need to recognize it from the rpc client which does know nothing of configured phpminer groups :)

DanielNagy commented 10 years ago

also.. in linux you can see which algo is running by the path to the cgminer.conf path 8152 ? Ss 0:04 SCREEN -d -m -S cgminer ./cgminer -c /home/danny/miners/keccak/cgminer.conf

8153 pts/3 Ssl+ 98:32 ./cgminer -c /home/danny/miners/keccak/cgminer.conf

And you can match it to the correct miners config file entry

however, this again, wont work if its manually started. If manually started..

prdatur commented 10 years ago

yeah i think this is the way how i will do it, with the miner binary + config path.

DanielNagy commented 10 years ago

ok. first issue,

rpcclient only listens on 127.0.0.1, i cannot define 0.0.0.0.

Here is my config.php file

$config['miners'] = array(

    'Scrypt' => array(
        'ip' => '0.0.0.0',
        'port' => 4028,
        'miner' => 'cgminer',
        'miner_binary' => 'cgminer',
        'rpc_key' => 'miner01',
        'cgminer_config_path' => '/home/danny/miners/scrypt/cgminer.conf',
        'cgminer_path' => '/home/danny/miners/scrypt',
        'amd_sdk' => '',
    ),

    'SHA3' => array(
        'ip' => '0.0.0.0',
        'port' => 4028,
        'miner' => 'cgminer',
        'miner_binary' => 'cgminer',
        'rpc_key' => 'miner01',
        'cgminer_config_path' => '/home/danny/miners/keccak/cgminer.conf',
        'cgminer_path' => '/home/danny/miners/keccak',
        'amd_sdk' => '',
    ),

    'Vert' => array(
        'ip' => '0.0.0.0',
        'port' => 4028,
        'miner' => 'cgminer',
        'miner_binary' => 'vertminer',
        'rpc_key' => 'miner01',
        'cgminer_config_path' => '/home/danny/miners/vert/cgminer.conf',
        'cgminer_path' => '/home/danny/miners/vert',
        'amd_sdk' => '',
    )

);
DanielNagy commented 10 years ago

seems its falling back to config.dist.php

can you give me a indication on how i should configure these files based on what i just pasted?

prdatur commented 10 years ago

tomorrow, need to go to sleep :P

DanielNagy commented 10 years ago

well one of my rigs are broken now :/

prdatur commented 10 years ago

You provided 0.0.0.0 which is miss configured, the ip in the miner app is always the ip of the api of the miner. you have a normal ip config to listen ( $config['ip'] = listen and can be 0.0.0.0, within miners it is always the ip of the miner api)

prdatur commented 10 years ago

The fallback to config.dist.php is normal. When a configuration key is not set within config.php it uses the config.dist.php value. This is required to ensure new configurations work well for users which updates.

DanielNagy commented 10 years ago

Ok. Well the config I pasted earlier was my entire config.php.

Have you updated the original config to show how we need to config multiple miners, ie which of the normal config settings do we keep? Vs which get moved into the miners array?

prdatur commented 10 years ago

i have told my git to assume config.php is always unchanged, this is required because normally i provide the config.dist.php with all required infos. the config.php is my personal :)

DanielNagy commented 10 years ago

Yeh but has dist been updated with details for multiple miners? Easier copy and replace fields that way

DanielNagy commented 10 years ago

Ok. its working good so far, switches nicely too. I will let you know if there is any issues.

prdatur commented 10 years ago

k when it is open a new issue please :)