DarthSim / overmind

Process manager for Procfile-based applications and tmux
MIT License
2.89k stars 82 forks source link

Start if not started #158

Closed schonert closed 1 month ago

schonert commented 1 year ago

Is there a way to tame the error when starting overmind while the session is already running?

Command failed with exit code 1: overmind s
overmind: it looks like Overmind is already running. If it's not, remove ./.overmind.sock and try again
system  | Tmux socket name: overmind-web-k7XQbWNx9lLLwrGRuJuFB
system  | Tmux session ID: web
system  | Listening at ./.overmind.sock
schonert commented 1 year ago

This is my current solution. wondering if there's a built in

[ ! -S .overmind.sock ] && overmind s || echo 'overmind already running'
DarthSim commented 1 year ago

./.overmind.sock is a Unix socket used by Overmind to receive commands like restart, connect, etc. It's safe to remove it if you're sure that you don't have Overmind running. Otherwise running Overmind won't be able to receive commands.

I've just thought that this would be useful to check if the socket is actually in use rather than it just exists 🤔

goulvench commented 7 months ago

FWIW, I put rm -f ".overmind.sock" in my bin/dev so that Overmind starts even after the IDE crashes or was restarted. Here's the whole file:

#!/usr/bin/env sh

# Setup ENV vars from .env.local
if [ -f .env.local ]
then
  while read -r LINE; do
    if [[ $LINE == *'='* ]] && [[ $LINE != '#'* ]]; then
      ENV_VAR="$(echo $LINE | envsubst)"
      eval "declare $ENV_VAR"
    fi
  done < .env.local
fi

# Ensure default port ENV is set
PORT="${PORT:-3000}"
export PORT

# Ensure required dependencies are present, useful when switching branches
bundle check &> /dev/null || bundle install
yarn check &> /dev/null || yarn install

# Try starting Overmind
if command -v overmind &> /dev/null; then
  # Remove dangling socks from overmind
  rm -f ".overmind.sock"
  exec overmind start -f Procfile.dev --no-port "$@"
else # Fallback to Foreman
  exec foreman start -f Procfile.dev --no-port "$@"
fi