Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Add flag for starting ganache in detached mode #1001

Closed
fvictorio opened this issue Sep 9, 2019 · 3 comments · Fixed by #3568
Closed

Add flag for starting ganache in detached mode #1001

fvictorio opened this issue Sep 9, 2019 · 3 comments · Fixed by #3568

Comments

@fvictorio
Copy link

Expected Behavior

I would like to run ganache-cli in such a way that it runs in the background but the command returns when the startup is done. Right now to do that you have to do something like:

ganache-cli &
sleep 5
# interact with localhost:8545 somehow

because ganache isn't immediately ready. With a proper flag, this would become:

ganache-cli --detach
# interact with localhost:8545 somehow

Current Behavior

As explained in the previous section, right now you have to start the process in the background (using &) and then you have to wait a while (how much changes a lot from machine to machine) until it's ready.

Possible Solution

A flag like --detach should do the trick. In docker, this flag has the -d shortcut, but that's already reserved in ganache. Besides, it's likely that most people won't need this, so having just a long flag should be OK.

I'm not really sure about detach though, since it might imply "it will continue to work if the terminal is closed", which might not be the case.

Context

Having something like this would be specially useful for scripts and CIs. I've seen a lot of scripts and CI configurations that start ganache in the background and then sleep for 3-5 seconds.

Something to take into account is that the user will probably want to have the PID of the process. This could be the only thing that is printed, so you can use it like this:

PID=`ganache-cli --detach`
# do some stuff
kill $PID
@anthanh
Copy link

anthanh commented Jul 26, 2021

As workaround you can use something like this in your package.json:

    "scripts": {
        "start:ganache": "npx ganache-cli ${ARGS} &", // run in background
        "stop:ganache": "kill -9 $(lsof -t -i:8545)", // kill process that uses default ganache-cli port
        "pretest": "npm run start:ganache",
        "test": "your-tests-command",
        "posttest": "yarn stop:ganache",
        ...
    }

@parthlaw
Copy link

Is this issue still available?

@jeffsmale90
Copy link
Contributor

Hi @parthlaw, I had been hacking on this locally but hadn't pushed anything until yesterday. Sorry for the collision there!

Let me know if you'd like some suggestions on some other issues that align with your interests.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

6 participants