DEV Community

Mohammed Samgan Khan
Mohammed Samgan Khan

Posted on • Originally published at codebysamgan.com

2 1

Python script to run multiple servers simultaneously on a local machine on Mac.

There are a number of times we have a bunch of servers we need to run to fully run an application, yes i am talking about the microservice arch. It's annoying to go to each repo and get the server running. Below is the script for making it automated.


#!/usr/bin/python3

"""
Script that starts the servers from the "services" array.
services = [
  {
    "name": "service_name",
    "path": "path_to_service",
    "command": "command_to_run",
  },
  ...
]
for a single server, please pass the name of the service to start...
author: msamgan
created at: 2022-05-01
updated at: 2022-07-22
version: 1.1.0
signature: ./server | ./server <service_name>
"""

import os
import sys

services = [

]

# uncomment if on mac os..
# os.system("say 'booting shopini servers'")
os.system("sleep 1")

n = len(sys.argv)

serverCommand = ""
for service in services:
    if n > 1:
        if service["name"] != sys.argv[1]:
            continue

    # say = "say 'booting " + service["name"] + " server'"
    # os.system(say)
    os.system(
        "ttab.sh -w -t '"
        + service["name"]
        + "' -d "
        + service["path"]
        + " "
        + service["command"]
    )

# os.system(
#     "say 'all shopini servers are running at there full potentials, have a nice day!'"
# )
# kill command: kill -9 $(lsof -ti:5100)

Enter fullscreen mode Exit fullscreen mode

The ttab.sh library you will need

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay