Skip to content

Daily

Restart a Railway service every night

Your service gets a fresh restart at a quiet hour, and you only hear about it if the restart fails.

Runs
Daily
Apps
Railway
AI
Not needed
Access
workspace or project token (read+write)

Send this to your assistant

Create a ClickRuntime automation: every night at 4am, restart the latest successful deployment of my Railway service 'worker' and email me if it fails.

Paste it into your assistant. It tells you what it will send or change before it runs live.

First time? Adding ClickRuntime to your assistant takes about two minutes.

Why use it

Why teams use this automation

Some services need a regular reset: a Node worker that leaks memory slowly, a scraper that gets stuck after a day, or an app that caches too aggressively. Developers end up restarting them by hand in the Railway dashboard whenever someone complains, and a restart that should happen quietly at night is done in the middle of the afternoon.

Every night at 4am, ClickRuntime finds the service's latest successful deployment on Railway and restarts it. If the restart fails or the service cannot be found, you get an email with the error, so a missed restart does not go unnoticed. On a normal night, nothing is sent and the service simply comes back fresh.

It is a practical fix for long-running processes while the underlying leak or bug is still being tracked down.

What you get out of it

  • Memory is reclaimed before it matters

    A nightly restart resets the slow growth that leads to out-of-memory kills. The service starts each day clean, so peak hours are no longer when it chooses to fall over.

  • Restarts happen when nobody is using it

    Choosing 4am keeps the short downtime away from customers. The same restart done by hand at noon is a visible interruption that someone has to coordinate. Fewer people ever notice it happened.

  • A band-aid that buys time

    Finding a leak can take weeks. A scheduled restart keeps the service healthy meanwhile, so engineers can work on the real cause without firefighting every few days. The pressure comes off while you investigate.

  • Failures are not silent

    If the restart does not work because the deployment is missing or Railway returns an error, you are emailed. A job that quietly stops working is worse than none, so the error path matters.

  • No one has to remember

    Manual restarts depend on whoever notices the symptoms. Making it a nightly routine removes that dependency, and it works through holidays and weekends without a human. The restart is dependable.

How it works

What happens, step by step

  1. Every night at the quiet hour you choose, ClickRuntime finds the latest successful deployment of your Railway service.

  2. It asks Railway to restart that deployment.

  3. If the restart works, you hear nothing. If Railway refuses, you get an email with the service name and the error.

Before it runs live

  • Connect Railway

What you get

RunsDaily
Restart a Railway service every nighttoday, 9:00Succeeded
Email · Railway restart failedRailway restart of 'worker' failed [{'message': 'Deployment not found'}]

Build your own

Need it to work differently?

This template is a starting point. Copy the prompt and change it, or describe a different automation from scratch, with your own conditions, more apps or an AI step. Your assistant writes it, tests it and runs it on ClickRuntime.
  • Your own rules

    Conditions, thresholds, filters and exceptions, written the way you'd explain them to a colleague.

  • Any number of apps

    One automation can read from one app and update several others. Over 248 apps are ready, and anything with an API works too.

  • AI where it helps

    Summaries, classification, extraction and drafts use ClickRuntime's built-in AI, with no extra key.

  • On a schedule or on each event

    Runs as often as every 5 minutes, or the moment an app sends an event, and keeps track of what it already handled.

Changes you can ask for

  • Run it at a different time, more or less often, or only on weekdays
  • Add an AI step, for example to summarize, sort or draft a reply
  • Add another app, for example also send it to Slack
  • Combine it with other Railway steps into one automation

Under the hood

The code that runs this automation

This is the Python script that runs each time the automation starts. Your AI assistant writes it for you when you send the prompt, and you allow each step in your assistant. To change how the automation works, describe the change to your assistant and it updates the script for you. For every function it can use, see the script reference.
restart_a_service_on_a_schedule.pyexample
from clickruntime import on_trigger, credentials, http, notify, log

GQL = "https://backboard.railway.com/graphql/v2"
PROJECT_ID, ENV_ID, SERVICE_ID = "proj-id", "env-id", "worker-service-id"

@on_trigger
def run(event):
    headers = {"Authorization": f"Bearer {credentials.secret('RAILWAY_TOKEN')}"}
    find = ('{ deployments(first: 1, input: {projectId: "%s", environmentId: "%s", serviceId: "%s", '
            'status: {successfulOnly: true}}) { edges { node { id } } } }') % (PROJECT_ID, ENV_ID, SERVICE_ID)
    edges = http.post(GQL, json={"query": find}, headers=headers).json()["data"]["deployments"]["edges"]
    if not edges:
        notify.email_me("Railway restart skipped", "No successful deployment of 'worker' found.")
        return {"restarted": False}
    dep_id = edges[0]["node"]["id"]
    resp = http.post(GQL, json={"query": 'mutation { deploymentRestart(id: "%s") }' % dep_id}, headers=headers)
    errors = resp.json().get("errors")
    if resp.status_code != 200 or errors:
        notify.email_me("Railway restart of 'worker' failed", str(errors or resp.text)[:2000])
        return {"restarted": False}
    log.info("restarted", {"deployment": dep_id})
    return {"restarted": True}

FAQ

Common questions

Does restarting cause downtime?
A restart briefly stops and starts the service, so there may be a few seconds to a minute of unavailability depending on startup time. Railway can overlap deployments for services with health checks, which reduces the gap. A 4am window keeps any interruption away from most users.
Does it redeploy my code or only restart the process?
It restarts the latest successful deployment, so the same build runs again. No new build is created and no code changes. If you want a fresh build from the latest commit, a redeploy is a different action that can be scheduled instead.
Can I pick a different time or restart several services?
Yes. Any time of day works, and the schedule can include more than one service, each restarted in turn. Staggering them by a few minutes avoids restarting an app and its database at the same moment.
What permissions does it need?
workspace or project token (read+write). Nothing else in your accounts is used.
Does it need AI?
No. It runs without AI, so it doesn't use your plan's AI allowance.
How many runs does it use?
One run each time it runs (daily). Checks that find nothing to do and stop right away aren't counted.
Can I change how it works?
Yes. Describe the change to your AI assistant, for example a different schedule, channel or filter. It updates the automation, tests it and tells you what changed.

Set up “Restart a Railway service every night” from your assistant

Copy the prompt above, or connect your assistant first. Free plan, no credit card.