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.
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
Every night at the quiet hour you choose, ClickRuntime finds the latest successful deployment of your Railway service.
It asks Railway to restart that deployment.
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
Build your own
Need it to work differently?
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
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?
Does it redeploy my code or only restart the process?
Can I pick a different time or restart several services?
What permissions does it need?
Does it need AI?
How many runs does it use?
Can I change how it works?
Related
You might also like
See your estimated Railway spend each week
Every Monday you get an email with each project's estimated usage so far this month.
See how it worksGet a Friday log of this week's deployments
At the end of the week you see every deployment in the project with its status, plus a count of how many succeeded and failed.
See how it worksGet an email when a Railway deploy fails or crashes
As soon as a deployment in your project fails or crashes, an email tells you which service and what happened.
See how it worksKeep exploring
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.