Manually Configuring/Deploying Corda 4 on Network — The AWS Way


September 18, 2019
Webmob
Blockchain

As promised earlier, It’s time to show the world how we setup Corda 4. The prerequisites are same. In fact, setting up Corda 4 is the same as Corda 3 plus bit code and stuff. So for Corda 3 setup, follow my previous post and let’s head for bit code and stuff. Just so we are clear, whenever I say earlier or previous, I’m referring to my previous post here.

Let’s edit some configurations!

Before that, please tell me you have AWS instances ready in accordance with my previous tutorial. Done? cool!

Alright, so the goal here is, what you run locally should run on server and should be able to discover other nodes and communicate with them which were deployed and bootstrapped in same way. After we did exact same setup as mentioned in previous post, you need to change wee bit of configurations in clients/build.gradle. Wherever you see --config.rpc.host=localhost, config.rpc.port=PORT_NUMBER and config.server.port=PORT_NUMBER; replace rpc.host=localhost with rpc.host=0.0.0.0and rpc.port to corresponding RPC port of your node which you configured in build.gradle of your PROJECT_ROOT and finally the server.port. Don’t forget to change Client’s host as well.

The node configuration part is now over. Now let’s do some bashing!

The missing Webserver

You might have noticed that corda-webserver.jar file is missing. Remember that message they used to flash back in Corda 3? The node webserver is for testing purposes only and will be removed soon. Well, they just did so. No worries though. Some tweaks and it’ll work just fine. Apparently, Corda now uses Tomcat Server embedded as RPC client to the nodes. I’ll leave that to you as how to connect with webserver of your choice. For this how-to guide however, I’ll use the one which everybody gets out of the box(Tomcat Server).

So help me, how do you run server for you node? By running task, right? say ./gradlew runBankAServer. For the ones who are wondering, the server tasks are defined in clients/build.gradle. Now, you might have been successful in running corda.jar as a system service. But must have been searching for a way to do so for webserver. How do we do that when we don’t have a runnable jar at the first place?

Here’s little recipe to run your gradle tasks as a service. Let’s go back old school(init.d).

  1. Put builds and gradle scripts on the server. Basically everything minus code, in simple terms.
  2. Create a init.d script like this
#!/bin/bashcd /project/root/directory/;
case "$1" in
start)
   ./gradlew RUNNER_TASK &
   echo $!>/var/run/webserver.pid
   ;;
stop)
   kill `cat /var/run/webserver.pid`
   rm /var/run/webserver.pid
   ;;
restart)
   $0 stop
   $0 start
   ;;
status)
   if [ -e /var/run/webserver.pid ]; then
      echo webserver is running, pid=`cat /var/run/webserver.pid`
   else
      echo webserver is NOT running
      exit 1
   fi
   ;;
*)
   echo "Usage: $0 {start|stop|status|restart}"
esacexit 0;

Replace RUNNER_TASK with the task name corresponding to your node. e.g. ./gradlew runBankAServer. Then save it as /etc/init.d/corda-webserver

3. sudo systemctl daemon-reload then sudo systemctl enable --now corda-webserver

4. sudo systemctl start corda-webserver

Boom! 🔥 Easy, right?

Let me know if you have corrections/suggestions/comments. Give me thousand claps if I’ve helped you somehow. Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *