18

Currently I initialise the firebase emulators with:

$ firebase emulators:start

After some time working on it I want to stop it. How can I then stop the emulators?

user1447414
  • 906
  • 1
  • 7
  • 24

5 Answers5

32
  1. Check which process is occupying the port sudo lsof -i tcp:<port>
  2. Kill the process kill -9 <process id>
xmkevinchen
  • 1,098
  • 11
  • 16
7

If you don't want to have to check the port every time, you can stop command with below

kill -9 (lsof -t -i:5002 -i:5001)

(-i:xxxx are your running emulator ports in firebase.json.)

Moreover, I don't want to memorize this long command. So I made package.json script below.

"scripts": {
   ...
   "stop": "lsof -t -i :5001 -i:5002 | xargs kill -9",
   ...
}
Matsumoto Kazuya
  • 942
  • 10
  • 15
3

I've tried all the answers above, and none does what I was expecting: to gracefully end the emulator suite as a whole without having to ctrl+c, leaving no ports occupied. Here is how I've solved it.

TLDR: lsof -ti :4400 | xargs --no-run-if-empty kill

The port being 4400, as it's the default port for the Emulator Hub. Although with this command you'll end the emulator regardless of the process you kill.

The"-9" flag used in the other answers does not send the SIGTERM signal to the process, but forcefully kills it instead. This prevents the emulator from ending gracefully.

ppicom
  • 318
  • 2
  • 11
1

according to this: https://github.com/firebase/firebase-tools/issues/1367 Ctrl+C kills the emulators

0

An alternative is to use firebase emulators:exec, which, according to the CLI documentation, does this:

start the local Firebase emulators, run a test script, then shut down the emulators

Since I put my test running command in a Makefile, I use the following command to test firestore from a Python firebase_admin SDK:

firebase emulators:exec "make test" --only firestore

The set-up and tear-down of the port is handled by firebase directly.

Fanchen Bao
  • 1,131
  • 8
  • 19