Force Glitch to restart regularly


I’m creating a python Discord bot that needs to be restarted at least every day automatically. Is it possible to do in Glitch?


Here’s the solution I came up with to solve your problem.

  1. Install cron, this is like cron jobs, but using timeouts
  2. Setup a cron to execute this line every 24 hours in your server process.exit(1);
  3. The cron will run, the app will shutdown and Glitch will bring it up again automatically

I tested it using a route in express and worked like a charm:


app.get("/shutdown", function (req, res) {


Except I’m using Python, not JSON or JS. Can this be done in the watch.json file?


I don’t think so, but you can try for a similar solution in python using python-crontab and sys.exit().


Hi Trainmaster2!

Glitch automatically restarts your app when it closes. So you just need to call sys.exit() somehow every 24 hours.

@kinduff why did you need forever? Glitch should be restarting your app when it dies.


Looks like I’m less patient when it comes to restarts :sweat_smile: I tested too fast. That explains a thing or two. Gonna edit my answer above to avoid confusions.


Figured out that if ends it will restart. Made the python code run in the background and made wait until midnight to terminate.

My looks like:


# Exit early on errors
set -eu

# Python buffers stdout. Without this, you won't see what you "print" in the Activity Logs

# Install Python 3 virtual env

if [ ! -d $VIRTUALENV ]; then
  python3 -m venv $VIRTUALENV

if [ ! -f $VIRTUALENV/bin/pip ]; then
  curl --silent --show-error --retry 5 | $VIRTUALENV/bin/python

# Install the requirements
$VIRTUALENV/bin/pip install -r requirements.txt

# Run a glorious Python 3 server
$VIRTUALENV/bin/python3 &
while [ $(date +%H:%M) != "00:00" ]; do sleep 1; done