A common way to save money: when you finish for the day, destroy the server instead of keeping it, and launch the same setup again tomorrow. A launch file makes that one command. This tutorial takes about ten minutes and needs the CLI (see Use the CLI and API from scratch).
Destroying a server deletes its disk. Copy anything you want to keep first, or keep it on a volume (see Fine-tune or train: keep your work safe).
1. Find the server
apidly serversNote the id of the server you want to keep, for example ins_example.
2. Save its launch file
apidly servers export ins_example -f my-server.jsonYou see Wrote my-server.json. Read the lines after it:
Not in the file (send them when you launch, e.g. --env NAME=VALUE): HF_TOKENnames the secrets you send again in step 5.Not carried by a launch file: ...names what the file cannot hold, such as an attached volume.
In the console the same file comes from the server's Settings tab, Download launch file.
3. Look inside
Open my-server.json in any editor. It holds the plan, template, disk size, SSH keys, plain variables, pricing, tags and repeating automation rules, and no secret values. You can change it now, for example a larger diskGb or a new label. See Launch file for every field.
4. Destroy the server
apidly destroy ins_exampleType the server id when asked. Compute and disk charges stop. The launch file costs nothing to keep.
5. Launch it again
When you need the server again, first check the price, then launch:
apidly deploy -f my-server.json --env HF_TOKEN=hf_example --dry-run
apidly deploy -f my-server.json --env HF_TOKEN=hf_example --waitThe first command shows the hourly price and anything that would refuse the launch, such as a low balance, and creates nothing. The second asks Deploy? [y/N], then waits until the server runs. It gets a new id, new ports and a fresh disk from the template.
To avoid typing a secret each time, store it once in Secrets and change its value in the file to secret:HF_TOKEN (see Secrets). The file then stays free of secret values and needs no --env.
If something goes wrong
my-server.json is not a launch file: it needs planId and templateId: the file was cut short or is not the exported one. Export it again.- The plan is out of stock: launch with another plan, for example
--plan PLAN_SLUG(seeapidly plans), or add plans tofallbackPlanIdsin the file. - The server starts but the app complains about a missing token: a name from step 2 was not sent. Destroy it and launch again with
--env.
Next
Ready to try it?
Create a free account and add credit when you want to start a server. The smallest top-up is $10.
Was this helpful?