Search code examples
unixcreate-react-applerna

Interrupt all lerna --parallel tasks at once


I have a lerna script (lerna dev) that boots up several package's dev servers with the --parallel option (if I didn't use that option, only the first service would start, but not the others). These servers serve their respective apps in dev mode on different ports, with hot reload. Basically, this allows smooth development, as we only have to enter one command to start working on several packages.

The problem I've noticed is that when I interrupt this lerna task, servers don't get shut down. When I run my lerna dev command, it prints messages explaining servers are already running on the ports they use. What this means is, when I shutdown the lerna dev command (with CTRL+C), it doesn't kill all of those running processes (some are killed, some aren't).

Interestingly enough, those that don't shutdown are create-react-app projects.

So here's my question: how do I make sure processes started via the lerna run command with the --parallel option are all killed alongside the main process?

PS: this happens on Unix systems, we don't use Windows.


Solution

  • I would suggest that you don't use ctrl+c for this. Take a look at killing the process through the pid (process ID) using kill or pkill -f.

    First, take a look at which lerna processes are running. My guess is that ps aux | grep lerna should display what you want there (tweak grep if needed). You may see a master process (I do when using Nginx, I've never used lerna) if so take the PID and type kill PID where the PID is your master PID. If this does not kill all the processes use pkill -f lerna to kill all processes that match the lerna search term (again tweak if needed).

    For more information on how to kill the processes based on a search term see How to kill all processes matching a name