Is it possible to make my project never ever restart on its own?


#1

Hello, I want to make my bot never restart by its self, I want to be the only to restart it. Is there anyway at all? Like changing the interval number in watch.json or anything else?

Thanks, murf.


#2

Hey MurfCode,

Totally. By default, the Glitch will restart if anything is changed. You can override that in watch.json by specifying include and exclude files/folders.

We do this for glitch.com itself, take a look at https://glitch.com/edit/#!/community?path=watch.json:1:0 for an example configuration.

In this example, we do a big full restart (including pnpm install) only if package.json or .env change, we deliberately don’t restart if anything inside the ‘src’ folder changes, and then we have couple other special cases.

For the stuff that Glitch isn’t restarting for us, to notice the changes we run our own watcher in the ‘prestart’ step in package.json, and that lets us monitor those other files and rebuild them as assets to be served without interruption from the main server endpoint.

Note that ‘never’ is a tall order; projects will go down for maintenance or go to sleep, etc., but you can override the behavior of “restart whenever I change it” and that will let you limit your restarts to “pretty much never.”


#3

Question @jude, If we do this, what is the option to start it? Is there any specific button, or do we have to visit the website, or…? Thank you :grin:


#4

I edit the watch.json and just set it back very fast to restart mine.


#5

Thank you, @MurfCode!


#6

Hi LeoDog896,

Yup, MurfCode has a good way about it.

For a little more detail:

The key controls are in your package.json file – the ‘start’ hook and the (not included by default) ‘prestart’ hook. These are the invocations into your code that Glitch knows to run, and watch.json is what controls when those items get invoked. If you change watch.json from its defaults, then it’s now up to you to decide what you want the behavior to be.

Personally I try to model the “continuous deployment” philosophy: You want something that’ll watch for changes and build an artifact, you’ll want something that watches for new artifacts and tests them, and you’ll want something that watches for new tested-artifacts and restarts the app to host them.

A Glitchy way to do this is to have your ‘prestart’ hook in package.json invoke your code that watches your file changes, tests, and publishes your artifact, and your ‘start’ hook run the code that hosts your server and runs the artifact.

But this starts to get tricky, and it sure is nice to keep things simple where we can, so I wouldn’t go this far unless you really can’t make things work with the default config and tips like what MurfCode has for ya :slight_smile: