Author

Topic: Automate Your miners setup for ur S9 farm | Beta (Read 1710 times)

newbie
Activity: 1
Merit: 0
September 21, 2018, 08:22:55 AM
#11
I've used a similar script for the last couple of years but have abandoned it because I found a tool that will do all of this for you.  If you go to antpool.com > tools.  It's called APMinerTool.  the current version is V1.0.7. 

Open the program and click on the IP configuration tab.  Enter the ip info you want to use, then hit the "listening" button.  Next go to your first S9 and hold down the button on the front for 3-5 seconds then let go.  It normally takes a few seconds for the program to respond.  Then repeat for all new miners.  Now you have all your miners ip addresses in the exact order you want.  Be careful not to hold the button for too long as it will cause a reset.  I think its something like 10 seconds.

If you want to set all your pools go to settings>ip editor and setup the ip block of the miners you want to setup.  Then go back to the miner manager tab, enter your pool information, and hit start scan.  once the scan finishes, hit config to change the pool settings.  It also remembers your pool settings after you reopen the program so that's a nice feature.
newbie
Activity: 5
Merit: 0
so here is my first script.

The first problem with the pastebin is it is looking for bash, which is not available on the control board.

Code:
#!/bin/sh

# https://bitcointalk.org/index.php?topic=2799605.msg

# NOTE: You need to set your DNS server address below.
# Don't just hammer Google's servers when your ISP has
# already provided the infrastructure.
DNS=""

[ $# -lt 5 ] && {
  echo "Usage: $0 workername1 workername2 workername3 hostname ip"
  exit 1
}

mv /config/bmminer.conf /config/bmminer.conf.backup
mv /config/network.conf /config/network.conf.backup

cat </config/bmminer.conf
{
"pools" : [ {
  "url" : "stratum.antpool.com:3333",
  "user" : "test.$1",
  "pass" : "123"
},
{
  "url" : "stratum.antpool.com:3333",
  "user" : "test.$2",
  "pass" : "123"
},
{
  "url" : "stratum.antpool.com:3333",
  "user" : "test.$3",
  "pass" : "123"
} ],
"api-listen" : "true",
"api-network" : "true",
"api-groups" : "A:stats:pools:devs:summary:version",
"api-allow" : "A:0/0,W:*",
"bitmain-use-vil" : "true",
"bitmain-freq" : "550",
"bitmain-voltage" : "0706",
"multi-version" : "1"
}
EOF

chmod 400 /config/bmminer.conf

cat < /config/network.conf
hostname=miner$4
ipaddress=10.0.0.$5
netmask=255.255.255.0
gateway=10.0.0.138
dnsservers="$DNS"
EOF

chmod 400 /config/network.conf

#/etc/init.d/bmminer.sh restart >/dev/null 2>&1
#/etc/init.d/network.sh
#/etc/init.d/avahi restart > /dev/null
#echo "root:antMiner Configuration:23c2a2d78c0d20ec069097d7d20c4392" >> /config/lighttpd-htdigest.user

exit 0
https://pastebin.com/LZwdxATT

I tidied it up and removed Google's servers – you shouldn't be using them unless you need to. In fact: if you have a large number of miners you really should be using your own caching DNS server to improve performance. A Raspberry Pi is overkill for such an application so anything would do.

This could be improved dramatically but I simply couldn't be bothered. Please note that there is no automation here at all, it's simply a setup script. A better script wouldn't need to run on the miner itself. I might look at this later, but probably not.

Automating this whole process would be an entirely different script, but that's for another day.
newbie
Activity: 20
Merit: 0
Many thanks, SkyLakeMine!

I now need to find out what port in the switch that miner is plugged into. In the configuration on the miner I can see the hostname which is the port. How can get this via the API? I am getting the following but none of it gives me the hostname:

print miner.version()
print miner.stats()
print miner.summary()
print miner.pools()
print miner.config()
print miner.devs()

Any ideas? I guess worst case I can get it through the cgi interface but that seems kludgy.
member
Activity: 99
Merit: 11
I want to do the same but with Python... Possible?


I am putting everything together to be released as open source.

Here it is in python. miner and login are my classes. You can use tuples or just hard code the ip, user, pwd for testing.

The basic idea is to connect to miner using ssh, run the commands and reboot the miner. Then you can hit the api and add and switch pools.

forum wont let me post.

https://pastebin.com/15feyq1Q
newbie
Activity: 20
Merit: 0
Hi all, excellent thread. I think I am going to want to do the same thing. My issue is I want to do this using Python. I can send commands such as 'status' to a miner and get some info but what I really want to do is set the pools, assign an IP, change the root password, etc.

Any ideas on how I might do what SkyLakeMine suggests:

Code:
sed -i 's_^\("api-allow" : \).*_\1"W:your.remote.ip.address,W:192.168.0.1/16,A:0/0",_' bmminer.conf

I want to do the same but with Python... Possible?

Also, assuming I can use the API, is there any docs for it? I looked on BMMiner and I can't find anything...

Cheers,

Morton.
copper member
Activity: 117
Merit: 17
as more i think of it.
its even easier to download the file (script) to ur antminer.
u can ssh to it, and instead of copy pasting or sharing it with wincp
u can either open a localhost web which will host the script that u want for example SimpleHTTPServer (python) or putting ur script in pastbin (register allowed so u can edit the file online) or github.
then what u have to do is just wget link.com/file
member
Activity: 99
Merit: 11
I am building a similar utility and will incorporate some of the ideas on this thread.

I agree with use of sed command to update the conf file.

For example the following command sets up miner to privileged mode so it can be controlled through api

sed -i 's_^\("api-allow" : \).*_\1"W:your.remote.ip.address,W:192.168.0.1/16,A:0/0",_' bmminer.conf


The general idea of something I would like to do is to
    - scan local subnet addresses to find ip addresses that respond on port 4028
    - check if the miner has already been "provisioned" with my custom settings
    - run the setup batch file if needed

I don't have all of these steps automated yet but I have a few steps ready.

https://github.com/dfoderick/Mining/blob/master/Antminer/antminerS9api_privileged.sh
hero member
Activity: 756
Merit: 560
An alternate way to get around the location issue would be to power the miners up 1 by 1 so they grab sequential DHCP IPs before staticing. Theres always multiple ways to do things and in the end most of them work. Good job on the script!
copper member
Activity: 117
Merit: 17
This is something I am sure people will find value in.

I do have a few small suggestions. Using a combination of Ansible and sed, you can make this more efficient and batch program many miners at once. You can use sed to replace individual lines rather than deleting, creating, and then modifying a new file. With ansible, you can batch them and auto generate worker names and batch program multiple miners at once and restart all the services in one shot.

thanks alot! for ur comment Smiley i was looking for a good compliment ^.^

i did decide to backup the file and deleting it than creating it from scratch to avoid any miss writing into the file.
its safer this way.

about doing that multiple miners at ones im not yet sure how to do so. the reason for this script is to be organized .
what i mean by that is if u have 10 20 30 miners on shelf u want to know where is each miner .
me myself i wouldn't plug them all at ones and try to discover which miner is which and configuring them all at ones.

my thought is more like this, if u want to plug them all at ones, bitmain as a tool which called IP reporter. https://shop.bitmain.com/support.htm?pid=00720160906053730999PVD2K0vz0693
what u can do is press the button on the miner for 5 second (open their program before), and then u will get the miner ip , so u know which one to ssh to
lets say
u press on shelf 2 miner 6, u will get a dhcp ip lets say 10.0.0.51 , u just ssh to 10.0.0.51 and move over the script and run it sh script.sh 6 6 6 6 6 so the miner will be on ip 10.0.0.6

i guess u understand that already when reading the first post.


hero member
Activity: 756
Merit: 560
This is something I am sure people will find value in.

I do have a few small suggestions. Using a combination of Ansible and sed, you can make this more efficient and batch program many miners at once. You can use sed to replace individual lines rather than deleting, creating, and then modifying a new file. With ansible, you can batch them and auto generate worker names and batch program multiple miners at once and restart all the services in one shot.
copper member
Activity: 117
Merit: 17
moved from there https://bitcointalksearch.org/topic/m.28619062
tips are welcome BTC/BCH: 1JpmzRLXErkhVU11TUe9Ee4nS1zv77tF7b  ETH: 0x6d8fc552f832f69D1EBf236A56F196C176aD5cf5


happen to u that u got tired to setup each miner in ur small/medium farm ? if yes this script is for u.
in short u wont need to enter the web application of each miner and configure them one by one. its tiring and not so fun when u have 10 20 30 50 miners.
i made a little script that will save u A lot of time.
u configure the script ones as u wish , and then run it, it take 5 seconds to configure ur miner (really only 5 sec)




so here is my first script. explanation below
https://pastebin.com/SeMJwsRP
Code:
#!/bin/sh

#https://bitcointalk.org/index.php?topic=2799605.msg

cp /config/bmminer.conf /config/bmminer.conf.backup
cp /config/network.conf /config/network.conf.backup

rm /config/bmminer.conf
rm /config/network.conf

touch /config/bmminer.conf
touch /config/network.conf

echo "{"                                                            >> /config/bmminer.conf
echo "\"pools\" : ["                                                            >> /config/bmminer.conf
echo "{"                                                            >> /config/bmminer.conf
echo "\"url\" : \"stratum.antpool.com:3333\","                                                            >> /config/bmminer.conf
echo "\"user\" : \"test.$1\","                                                            >> /config/bmminer.conf
echo "\"pass\" : \"123\""                                                            >> /config/bmminer.conf
echo "},"                                                            >> /config/bmminer.conf
echo "{"                                                            >> /config/bmminer.conf
echo "\"url\" : \"stratum.antpool.com:3333\","                                                            >> /config/bmminer.conf
echo "\"user\" : \"test.$2\","                                                            >> /config/bmminer.conf
echo "\"pass\" : \"123\""                                                            >> /config/bmminer.conf
echo "},"                                                            >> /config/bmminer.conf
echo "{"                                                            >> /config/bmminer.conf
echo "\"url\" : \"stratum.antpool.com:3333\","                                                            >> /config/bmminer.conf
echo "\"user\" : \"test.$3\","                                                            >> /config/bmminer.conf
echo "\"pass\" : \"123\""                                                            >> /config/bmminer.conf
echo "}"                                                            >> /config/bmminer.conf
echo "]"                                                            >> /config/bmminer.conf
echo ","                                                            >> /config/bmminer.conf
echo "\"api-listen\" : "true","                                                            >> /config/bmminer.conf
echo "\"api-network\" : "true","                                                            >> /config/bmminer.conf
echo "\"api-groups\" : \"A:stats:pools:devs:summary:version\","                                                            >> /config/bmminer.conf
echo "\"api-allow\" : \"A:0/0,W:*\","                                                            >> /config/bmminer.conf
echo "\"bitmain-use-vil\" : "true","                                                            >> /config/bmminer.conf
echo "\"bitmain-freq\" : \"550\","                                                            >> /config/bmminer.conf
echo "\"bitmain-voltage\" : \"0706\","                                                            >> /config/bmminer.conf
echo "\"multi-version\" : \"1\""                                                            >> /config/bmminer.conf
echo "}"                                                            >> /config/bmminer.conf


chmod 400 /config/bmminer.conf

echo "hostname=miner$4"                    >>  /config/network.conf
echo "ipaddress=10.0.0.$5"                  >> /config/network.conf
echo "netmask=255.255.255.0"                              >> /config/network.conf
echo "gateway=10.0.0.138"                              >> /config/network.conf
echo "dnsservers=\"8.8.8.8"\"    >> /config/network.conf

chmod 400 /config/network.conf

#/etc/init.d/bmminer.sh restart >/dev/null 2>&1
#/etc/init.d/network.sh
#/etc/init.d/avahi restart > /dev/null
#echo "root:antMiner Configuration:23c2a2d78c0d20ec069097d7d20c4392" >> /config/lighttpd-htdigest.user


ssh into ur miner
create a bash file and put the script inside or move it with scp/winscp

give it root permission to edit the files. with chmod 7777 filename.sh

u will need to do some manual modification at start.
u should manual change everything that static that should not change.
for example , pools,netmask,getway,dnsserver, the start of the miner name(hostname) and the start of the ip and the workername.
make sure u have backed up ur settings before if anything goes bad. and u can factory reset https://enforum.bitmain.com/bbs/topics/3957

running the script will be

sh filename.sh 1 2 3 4 5

1, is the first worker name
2, is the second worker name
3, is the third worker name
4, hostname
5, ip address.

please notice that the workername will be only the end of it. which mean useraccount.workernamehere, in the script its test.$1 (test = useraccount $1=workername)
if u want to change the password just uncomment the last line and put ur password instead. u can use http://www.md5.cz/ to generate a hash "password" for u.
root:antMiner Configuration:passwordhere = dad8edbc0681a4c03057417c19239983 = root:antMiner Configuration:dad8edbc0681a4c03057417c19239983 < u put this in the script

before uncomment

#/etc/init.d/bmminer.sh restart >/dev/null 2>&1
#/etc/init.d/network.sh
#/etc/init.d/avahi restart > /dev/null

please DO check the files if they are ok.
it should look like this.
/config/bmminer.conf
Code:
{
"pools" : [
{
"url" : "solo.antpool.com:3333",
"user" : "test.1",
"pass" : "123"
},
{
"url" : "stratum.antpool.com:443",
"user" : "test.1",
"pass" : "123"
},
{
"url" : "stratum+tcp://cn.ss.btc.com:3333",
"user" : "test",
"pass" : "123"
}
]
,
"api-listen" : true,
"api-network" : true,
"api-groups" : "A:stats:pools:devs:summary:version",
"api-allow" : "A:0/0,W:*",
"bitmain-use-vil" : true,
"bitmain-freq" : "550",
"bitmain-voltage" : "0706",
"multi-version" : "1"
}

/config/network.conf
Code:
hostname=miner1
ipaddress=10.0.0.1
netmask=255.255.255.0
gateway=10.0.0.200
dnsservers="8.8.8.8"

after checking the files is right. uncomment these 3 commands

will apply the pools settings
/etc/init.d/bmminer.sh restart >/dev/null 2>&1

and this will apply hostname and ip settings.
/etc/init.d/network.sh
/etc/init.d/avahi restart > /dev/null



for a real example that will be
sh script.sh m1 m1 m1 1 1
the result will be
first pool   second pool   third pool     hostname   IP
test.m1    test.m1         test.m1        miner1       10.0.0.1

if u need any help, or u want to report a bug please tell me.
or want to help to make it better welcome ur self to edit and share it



tips are welcome BTC/BCH: 1JpmzRLXErkhVU11TUe9Ee4nS1zv77tF7b  ETH: 0x6d8fc552f832f69D1EBf236A56F196C176aD5cf5
Jump to: