Automating Multichain command

+1 vote

This might be a bit out of the scope but I'm trying to run the multi chain instances on the same server and in doing so I'm trying to automate the tasks to get it started. However I am having a hard time getting anywhere with it. Would you be able to provide some insight into it?

ip=$(multichaind decibel -shortoutput=1 -miningrequirespeers=0 -discover -rpcuser=admin -rpcpassword=admin -daemon=1)

mkdir .multichain1

echo "ip address $ip"

addr=$(multichaind $ip -datadir=.multichain1)

echo "wallet $addr"

multichain-cli decibel -rpcuser=admin -rpcpassword=admin grant $addr connect,send,recieve

multichaind $ip -datadir=.multichain1 -daemon=1

The first task seems to block the other processes from being executed. Would it be possible to kill then restart later without having to reset anything?

 
asked Jan 3, 2017 by kendall

2 Answers

0 votes

Looks like you're including the multichaind command twice within a line, once from $ip as well. In any event I recommend testing the full process manually, step-by-step, before putting it into an automated script. There's no reason why you shouldn't able to do this.

answered Jan 3, 2017 by MultiChain
Not sure I follow. I'm trying to adapt an automated process based on your guide http://www.multichain.com/qa/2817/how-to-run-datadir-in-multichain?show=2822#a2822

Manually the commands work but I have to use multiple terminals in order to start multi chain. In a real world this isn't most efficient so I'm trying to automate it. Can you elaborate on your comment?
Sorry - my mistake - misinterpreted your batch script above. Will post a better answer...
0 votes

This seems to be the kind of thing that might work:

http://stackoverflow.com/questions/20017805/bash-capture-output-of-command-run-in-background

Or redirect via a file, and nohup.

answered Jan 3, 2017 by MultiChain
Well this is quite elaborate. I'm afraid I'm not too verse with bash scripts. Would you care to offer up an example. In the interest of making multichain more efficient in execution in a real world scenario being able to automate this process on a single server does make things a bit more viable to use in real world situations
Here's a bash script that we've verified to get the node address from an instance of multichaind (or a wallet address if it does not have connect permissions):

nohup multichaind chain1 -shortoutput > mc-output.txt &
ip=$(<mc-output.txt)
echo $ip
@multichain

thanks will try your solution but I've come up with this process which is more interactive in setting up a multi chain on a single server

-----bash sh-----

cd /home/multichain

echo "Enter the name of chain"

read chain

multichain-util create $chain

sed -e '/default-network/d' /home/multichain/.multichain/$chain/params.dat > /home/multichain/.multichain/$chain/params.dat.tmp

mv /home/multichain/.multichain/$chain/params.dat.tmp /home/multichain/.multichain/$chain/params.dat

echo "creating on default port 10239"

echo 'default-network-port = 10239' >> /home/multichain/.multichain/$chain/params.dat

multichaind $chain -shortoutput=1 -miningrequirespeers=0 -discover=1 -rpcuser=admin -rpcpassword=admin -daemon=1

echo "enter the ip started"

read ip

echo "ip address is $ip"

mkdir .multichain1

echo "connecting to chain $chain via $ip"

multichaind $ip -datadir=.multichain1 -shortoutput=1 -daemon=1 -listen=0 -discover=1

echo "What is the chain address"

read addr

echo "Address is $addr"

multichain-cli $chain -datadir=.multichain -rpcuser=admin -rpcpassword=admin grant $addr connect,send,receive

echo "now lets reconnect"

multichaind $ip -datadir=.multichain1 -daemon=1 -listen=0 -discover=1

echo "connected to $ip"


----bash sh-----


The problem I'm facing is that in trying to restart/ reconnect the multi chain I get

----error----
MultiChain Core Daemon build 1.0 alpha 23 protocol 10005

MultiChain server starting
Retrieving blockchain parameters from the seed node 172.17.0.3:10239 ...
Error: An error occurred while setting up the RPC address 127.0.0.1 port 2908 for listening: bind: Address already in use
------end error---

and the terminal becomes unresponsive.... is there a way to disconnect/ stop the connecting chain in order for it to be restarted/ reconnected with the permissions?
This is my final attempt....

---- BASH SHELL ---

#!/bin/bash

cd /home/multichain

echo "Enter the name of chain"

read chain

multichain-util create $chain

sed -e '/default-network/d' /home/multichain/.multichain/$chain/params.dat > /home/multichain/.multichain/$chain/params.dat.tmp

mv /home/multichain/.multichain/$chain/params.dat.tmp /home/multichain/.multichain/$chain/params.dat

echo "creating chain $chain on default port 10239"

echo 'default-network-port = 10239' >> /home/multichain/.multichain/$chain/params.dat

multichaind $chain -shortoutput=1 -miningrequirespeers=0 -discover=1 -listen=0 -rpcuser=admin -rpcpassword=admin -daemon=1

echo "enter the ip"

read ip

echo "ip address is $ip"

mkdir .multichain1

#echo 'rpcport=10240' >> /home/multichain/.multichain1/multichain.conf

echo "connecting to chain $chain via $ip"

multichaind -datadir=.multichain1 -listen=0 -discover=1 $ip

echo "What is the chain address"

read addr

echo "Address is $addr"

multichain-cli $chain -rpcuser=admin -rpcpassword=admin grant $addr connect,send,receive

echo "now lets reconnect"

multichaind -datadir=.multichain1 -listen=0 -discover=1 $chain

echo "connected to $chain on $ip"

___ END____

doesn't seem to work
Why not try the code I posted, as part of a longer script?
I will,

I was just looking at options. I think the "setup" part of multi chain is way elaborate. Being able to make it a more intuitive automated process might have sufficient benefits
...