Skip to content

Lightweight CLI tool to programmatically rescale your Hetzner virtual server daily to optimize your budget spending

License

Notifications You must be signed in to change notification settings

jonamat/hetzner-rescaler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hetzner rescaler

Release Docker Image Size (tag) GitHub go.mod Go version GitHub Workflow Status

Lightweight CLI tool to programmatically rescale your Hetzner virtual server daily to optimize your budget spending, scaling to a cheaper machine when you don't need or need few resources, and scaling to a more performant one when you know the load will be higher.

Usage

First, you need to generate an Hetzner API Token.

Next you need to create your configuration file or export the required environment variables for the tool.
The config command helps you generate a valid configuration, warning you if there are any logic errors and validating your input.

hetzner-rescaler config

Keep in mind if env vars are defined, they will take priority.
After setting the configuration, you can start the tool by running

hetzner-rescaler start

Use with environmental variables

Export these env vars to override or completely bypass the generated configuration:

Variable Description
HCLOUD_TOKEN A valid Hetzner API Token
SERVER_ID The ID of the target server
BASE_SERVER_NAME The code of the cheap server type
TOP_SERVER_NAME The code of the high performance server type
HOUR_START 24h format, colon separated hour when the server should be upgraded
HOUR_STOP 24h format, colon separated hour when the server should be downgraded
TZ If defined, change the timezone of the timer

Use with Docker

Pull the image from dockerhub

docker pull jonamat/hetzner-rescaler

Opt A: Create a config file inside the container & start immediately beta

docker run -ti jonamat/hetzner-rescaler hetzner-rescaler plug

Opt B: Mounting a configuration file

docker run -v ~/.hetzner-rescaler.yaml:/.hetzner-rescaler.yaml jonamat/hetzner-rescaler

Opt C: Passing config as env vars

docker run \
-e HCLOUD_TOKEN=abc123 \
-e SERVER_ID=4567 \
-e BASE_SERVER_NAME=cpx11 \
-e TOP_SERVER_NAME=cpx21 \
-e HOUR_START=09:00 \
-e HOUR_STOP=20:00 \
jonamat/hetzner-rescaler

You can also pass a partial configuration file and define the missing vars as env vars (useful eg to hide the API key)

Use with compose/swarm stacks

version: '3.7'

services:
  hetzner-rescaler:
    image: jonamat/hetzner-rescaler

    // Provide the env vars
    environment:
      HCLOUD_TOKEN: abc123
      SERVER_ID: 4567
      BASE_SERVER_NAME: cpx11
      TOP_SERVER_NAME: cpx21
      HOUR_START: "09:00"
      HOUR_STOP: "20:00"
    
    // ...or mount the config file
    volumes:
      - /var/hetzner/config-file.yaml:/.hetzner-rescaler.yaml

The configuration file

The default path for the config file is ~/.hetzner-rescaler.yaml.
You can provide (and create) a custom config path passing the --config /custom/path/config.yml flag.

Config yaml file example

hcloud_token: abc123
server_id: 15393230
base_server_name: cx11
top_server_name: cx21
hour_start: "09:00"
hour_stop: "20:00"

Commands

Usage:
  hetzner-rescaler [command]

Available Commands:
  config      Create the configuration file
  help        Help about any command
  plug        Configure and start immediately
  start       Start rescale timers
  try         Try a complete rescale cycle

Flags:
      --config string   config file (default is $HOME/.hetzner-rescaler.yaml)
  -h, --help            help for hetzner-rescaler

Use "hetzner-rescaler [command] --help" for more information about a command.

Use cases

This tool was developed for a my specific use case: I use an Hetzner server for remote development, using the Remote SSH extension to simplify my cross-device development workflow. This machine also serve some personal services, which require very little resources but cannot be stopped for a long time.
It could be useful for all servers running applications related to a company's opening hours, such as booking, delivery or management software.

License

MIT