On a schedule
Shut down staging Machines overnight
Staging Machines stop in the evening and start again before work, and you only get an email if one refuses.
- Runs
- On a schedule
- Apps
- Fly.io
- AI
- Not needed
- Access
- org or deploy token (read+write)
Send this to your assistant
Create a ClickRuntime automation: on weekdays, stop every Machine in my Fly app 'staging' at 8pm and start them again at 8am. Email me if any stop or start fails.
First time? Adding ClickRuntime to your assistant takes about two minutes.
Why use it
Why teams use this automation
A staging environment on Fly.io usually runs around the clock, though the people who use it work eight or ten hours a day and sleep for the rest. Each Machine is billed for the time it runs, so a staging stack with a web app, a worker and a database costs the same at 3 a.m. on Sunday as at noon on Tuesday. Teams know this and mean to shut things down, but nobody remembers to do it each evening, and nobody wants to be the person who starts it each morning.
On the schedule you set, ClickRuntime lists the Machines in your staging app and stops each one in the evening, then starts them again before the team arrives. If any Machine refuses to stop or start, you get an email naming it, so a failed morning start never surprises anyone.
It suits dev and demo environments rather than production, where Machines should stay up.
What you get out of it
Pay only for the hours you use
Stopped Machines stop accruing compute charges. Running staging for ten hours instead of twenty-four cuts that part of the bill by more than half, every month, with no change to how the team works.
Make the saving automatic
Shutting down by hand depends on someone remembering at six o'clock every day. A schedule does not forget on Fridays or holidays, so the saving shows up in the invoice without anyone doing anything.
Have staging ready each morning
Machines start before people arrive, so the first person in does not wait for a cold start or ask who turned staging off. Work begins when the day does, not after a round of chat messages.
Learn about failed starts immediately
If a Machine does not come back, an email names it. Fixing that at 8 a.m. is better than a developer finding a broken environment at 10 a.m. during a demo.
Reduce idle attack surface
Services that are off cannot be probed overnight. A staging stack with real-looking data and weaker settings is a tempting target, and being offline for fourteen hours a day removes much of that exposure.
How it works
What happens, step by step
Each evening, ClickRuntime lists the Machines in your Fly.io staging app and stops them. Each morning before work, it starts them again.
It handles each Machine one by one and notes any that refuse.
If everything goes through, you hear nothing. If a Machine won't stop or start, you get an email naming it and the reason Fly gave.
Before it runs live
- Connect Fly.io
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 Fly.io steps into one automation
Under the hood
The code that runs this automation
from datetime import datetime
from zoneinfo import ZoneInfo
from clickruntime import on_trigger, credentials, http, notify
APP = "staging"
API = f"https://api.machines.dev/v1/apps/{APP}/machines"
@on_trigger
def run(event):
# Scheduled at 8am and 8pm on weekdays: morning starts, evening stops.
hour = datetime.now(ZoneInfo("Europe/London")).hour
action = "start" if hour < 12 else "stop"
headers = {"Authorization": f"Bearer {credentials.secret('FLY_API_TOKEN')}"}
failed = []
for m in http.get(API, headers=headers).json():
resp = http.post(f"{API}/{m['id']}/{action}", headers=headers)
if resp.status_code != 200:
failed.append(f"{m['name']} ({m['id']}): {resp.status_code} {resp.text[:200]}")
if failed:
notify.email_me(f"Fly {action} failed for {len(failed)} Machines in {APP}", "\n".join(failed))
return {"action": action, "failed": len(failed)}FAQ
Common questions
Will stopping Machines lose data?
Can weekends be handled differently?
Does Fly not already stop idle Machines?
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
Get a weekly list of your Fly.io apps
Each Monday you get every app in your organization with how many Machines it runs, where, and in what state.
See how it worksCheck that your Fly volumes have recent snapshots
Once a week you see the newest snapshot date for each volume, with any that are falling behind flagged.
See how it worksHear in Slack when a Fly Machine stops or fails
If a Machine in your app leaves the started state, your channel gets one message naming it and its region.
See how it worksKeep exploring
Set up “Shut down staging Machines overnight” from your assistant
Copy the prompt above, or connect your assistant first. Free plan, no credit card.