How can I run a python script in the Droplet A from Droplet B?

March 9, 2019 491 views
Python Ubuntu 16.04

I currently have two Droplets that run Ubuntu 16. The first one, Droplet A, is the $5,00 super standard one where my website is built on. While Droplet B is the 80$ a month and has all the databases ready to be queried.

In both the droplets I have created a python backend. What I need is to be able to run a python script on the Droplet B from Droplet A.

How can I do that? This will be so helpful also in the future since we are planning to have many droplets communicating with each other.

1 Answer

Greetings!

There are many paths to doing this, but I’m happy to share mine. I’m a big bash fan, so this is far less fancy of a solution than others might use.

I created a bash script that I use to run commands across all of my servers, and it looks like this:

#!/bin/bash
ssh root@otherserver $@

Let’s say I placed this script in /root named run.sh. To run a command on “otherserver” I might just do this:

sh /root/run.sh commandhere

The “$@” takes everything that follows and shoves it into the command, executed remotely over SSH.

A more professional way might be to expose your application to a network interface and then code in some form of authentication, or firewall it off, then make remote requests that are returned.

Jarland

Have another answer? Share your knowledge.