Created
January 30, 2025 08:12
-
-
Save armamini/e392a08d7fba2deeaa38842f3792f76f to your computer and use it in GitHub Desktop.
Microservices Management Script - This script helps to start and stop multiple microservices using tmux and Docker Compose for running backing services.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # @armamini | |
| SESSION="microservices" | |
| function start_services() { | |
| echo -e "⌛️ Starting all microservices in tmux session '$SESSION'...\n" | |
| docker compose -f ./compose.yml up -d > /dev/null 2>&1 | |
| echo "✅ Docker compose services started." | |
| tmux new-session -d -s $SESSION | |
| tmux send-keys "cd ~/projects/microservices/first-service && pnpm start" C-m | |
| tmux rename-window "Auth" | |
| tmux new-window -d -n "Exchange" "cd ~/projects/microservices/second-service && pnpm start" | |
| tmux new-window -d -n "Gateway" "cd ~/projects/microservices/third-service && pnpm start" | |
| tmux new-window -d -n "Message" "cd ~/projects/microservices/fourth-service && pnpm start" | |
| echo "✅ All microservices started. Attach to the session using: tmux a -t $SESSION" | |
| } | |
| function stop_services() { | |
| echo -e "⌛️ Stopping all microservices...\n" | |
| docker compose -f ./compose.yml down > /dev/null 2>&1 | |
| echo "✅ Docker compose services stopped." | |
| tmux kill-session -t $SESSION > /dev/null 2>&1 | |
| echo "✅ All microservices stopped." | |
| } | |
| if [ "$1" == "up" ]; then | |
| start_services | |
| elif [ "$1" == "down" ]; then | |
| stop_services | |
| else | |
| echo "Usage: $0 {up|down}" | |
| exit 1 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment