hostinger-governor

Keeps a Hostinger VPS from running out of CPU credits while spending every credi

This is a fork of olmezsoy/hostinger-governor, kept for reference and contributions. It is not an original project.

hostinger-governor

Hostinger gives each VPS a CPU credit bank and limits the VM when it is empty, but publishes no
balance. The governor estimates the balance from Hostinger's own CPU readings and caps user.slice
so the bank does not run out. If Hostinger limits the VM anyway, the governor backs off until the
limit lifts.

Hostinger referral discount

Tip

Get 20% off your first Hostinger plan

When I researched my own Hostinger plan, the influencer codes I found on YouTube gave 10% off.
This referral link gives you 20% instead. It's free to use, and I may earn a commission if you buy
through it.

Open the full link; the code ASNVARDA3ZHG on its own won't apply the referral. Before paying,
check that your cart shows the 20% REF_REFERRALDISCOUNT discount.

It's for new customers who haven't already been referred. Eligible services include hosting, VPS,
AI automation apps, email and AI Builder plans. Domain-related services aren't eligible. The
discount is for your first eligible purchase, not renewals.

How it works

Hostinger meters VPS CPU in credits
(How CPU credits work on Hostinger VPS).
A plan earns a baseline of 60% of its vCPUs, spends what it uses, and holds at most three hours of
full use. At zero the whole VPS drops to a fraction of its CPU (30% on KVM 2, 4 and 8) until the
balance rebuilds, and while work keeps pressing on that limit, nothing is earned. A busy server can
stay limited for as long as the load lasts.

Diagram of how hostinger-governor works. Hostinger holds the CPU credit bank, and the VPS cannot read its balance. Every 30 seconds by default, governor.service reads CPU and steal from the kernel, updates its estimate of the bank, and sets one shared CPU quota on user.slice: every login, governor exec jobs, and services or Docker you enroll. Everything else is measured, not capped. Every 30 minutes it fetches Hostinger's CPU readings in the background. Settled readings are replayed through Hostinger's rules and move the estimate up or down. The guest's own count, 1.05 × use + 0.04 vCPU or more, covers the 30 to 100 minutes no settled reading reaches yet. After two hours without a reading, or with no token, the estimate runs on the own count alone. Spending: every vCPU while the estimate is high, then a glide onto the 10% spending floor; with no governor, the same load empties the bank and Hostinger limits the VPS. When steal follows demand during a 20-second probe at 0.2 vCPU, which runs only while user.slice has work to cut (at least 0.4 vCPU on KVM 4 and up, 0.3 on KVM 1 and 2), and burners then find the VPS held at the plan's limit, or steal reaches 60% of demand and a quarter of the host limit, or burners find the VPS held at the plan's limit while work outside an idle user.slice presses on it, the governor treats the VPS as limited: it sets the estimate to 0 and holds user.slice below the host limit, down to 0.2 vCPU, until a lift test passes. At the lift, a limit whose first failed lift test found the VPS held at the plan's limit raises the pad billed on top of every reading and starts a quiet window before probing again. After any limit the estimate carries on from the guest's own count since the limit began. If the probe or cap check does not confirm a limit, the governor stays in Spending and retries in 10 minutes, doubling to 1 hour. A saved limit resumes on start. A restart keeps the estimate; after a reboot the time down counts at the most the VPS could have spent, or the estimate restarts at 0 without recent readings. While the daemon is not running, systemd holds user.slice, SSH included, at 0.2 vCPU by default.

The governor measures the whole machine and caps workloads placed under user.slice:

The plan uses configured vcpus, or the kernel's CPU count when unset, with Hostinger's KVM rules.
Startup and CPU control never wait for the provider. Use governor check-hostinger to verify the
provider's VM details and addresses separately.

The estimate has no modes and no settings. With a Hostinger token or broker configured, it follows
the readings. Without one it runs on the guest's own count. The calibration, readings and
recovery blocks of a v0.3 config still load; the daemon ignores them and logs one line naming
them. sudo governor calibrate --reset puts the pad and the addition learned from readings back to
their start.

Install

On the VPS, as root (systemd with cgroup v2; Ubuntu 22.04+ and Debian 12+ have it):

curl -fsSL https://github.com/olmezsoy/hostinger-governor/releases/latest/download/install.sh |
  sudo bash -s -- --vm-id <id> --token-file <path> --timezone Europe/Istanbul

The installer verifies the release checksum and installs:

Release binaries and deno task compile embed V8's --jitless flag, so they run without allocating
executable memory at runtime. A service that directly runs governor status or governor report
can set MemoryDenyWriteExecute=yes. For a one-shot report:

sudo systemd-run --wait --pipe -p MemoryDenyWriteExecute=yes /usr/local/bin/governor report 1

The installer leaves daemon hardening opt-in because governor.service needs sudo for CPU ceilings
and optional broker requests. The daemon opt-in requires systemd v255 or later. Before v255,
including Ubuntu 22.04 and Debian 12, systemd implies NoNewPrivileges=yes for User= services
with this setting, which prevents sudo. CI tests the opt-in on Linux 6.8 and later.

Check systemctl --version, then create a dedicated drop-in:

sudo systemctl edit governor.service --drop-in=80-memory-deny-write-execute.conf

Add:

[Service]
MemoryDenyWriteExecute=yes

Restart without the previous daemon's public state, then check that the new daemon accepts work
after setting its CPU ceiling. A plain restart could pass on the state the old daemon wrote while
stopping. This removes only the runtime snapshot; credit estimates in /var/lib/governor are kept.

sudo systemctl stop governor.service
sudo rm -f /run/governor/state.json
sudo systemctl start governor.service
sudo governor exec --wait 60 -- /usr/bin/true
grep NoNewPrivs "/proc/$(systemctl show governor.service --property=MainPID --value)/status"

The last command must print NoNewPrivs: 0.

Hooks and other processes the daemon starts, including its sudo helpers, inherit the restriction.
Jobs started with governor exec run under their caller's settings instead. Hooks that start JIT
runtimes such as Node.js or Java will fail unless those runtimes use a compatible execution mode.
Remove this drop-in before installing or rolling back to a binary built with JIT enabled:

sudo rm /etc/systemd/system/governor.service.d/80-memory-deny-write-execute.conf
sudo systemctl daemon-reload
sudo systemctl restart governor.service

Running the installer again updates the governor and revokes the old consumer group's request
access. Before it stops the running daemon, it checks the existing config with the new binary and
stops the upgrade if that fails, for example on a key the new version doesn't know. It also gives
back to the governor user any of its state files a root run created, which the service couldn't
read otherwise. The first v1.0.0 start carries a v0.3 estimate over and starts from zero on anything
older; the changelog lists what carries over. --uninstall removes the daemon and
its boot quota and lifts the ceiling. Workload routing configured separately is kept; remove those
service drop-ins or restore Docker's backup if you want to undo that routing.

For guided operation-only API setup after installing Governor, run
bash tools/setup-hostinger-broker.sh <SSH-destination> from a checkout of the matching release. It
verifies the VPS, hides token input, asks before changing the server and restores the original
configuration if setup fails. See
the setup requirements and migration notes.

Use it

Who How
Scripts and other services governor status --json, or read /run/governor/state.json (world-readable). Before starting heavy work, check accepting; it is false while Hostinger limits the machine.
People governor report [hours]: CPU, credits, Hostinger's readings, steal, each user's share, memory, swap, load, disk.
Owners sudo governor limit off when Hostinger support lifts a limit, sudo governor limit on to start one by hand (a limit already detected goes on), sudo governor seed <core-seconds> to set the balance.
Events Executables in /etc/governor/hooks.d run as the governor user on limit and calibration events, with the event in GOVERNOR_EVENT and the state on stdin. See examples/hooks.d.

A fresh install starts the estimate at zero because the real balance is unknown. It grows from
observed CPU use, and with a Hostinger token or broker the readings move it from the first pass on.
Readings from before the install are not replayed. Root can state a known balance with
governor seed. initial_balance in the config does the same for the very first start only: once a
daemon has run on the box, missing state is lost state and starts from zero.

To run one control pass immediately, as root:

sudo governor tick

The command talks to the running daemon over its private /run/governor/tick.sock Unix socket. It
processes queued limit, seed and calibrate --reset requests, runs the same control pass as a
timed tick, and returns successfully only after /var/lib/governor/persist.json and
/run/governor/state.json are written. Calls run in sequence. Timed ticks keep their configured
interval; an on-demand pass does not restart the timer. A pass less than
min(5 seconds, tick_seconds / 2) after the last measured pass reuses its measurements while
applying queued commands, setting the quota and writing state. Its CPU use accumulates into the next
sample. This prevents tiny, noisy intervals from tightening a recovery quota or triggering a limit
probe. Limit probes run when a fresh sample is available and can take time. Readings fetches and
hooks continue in the background without delaying the pass.

Verification scripts can check a limit without sleeping until the next tick:

sudo governor limit on
sudo governor tick
governor status --json
sudo governor limit off
sudo governor tick
governor status --json

tick exits nonzero if the daemon is unavailable, control or state writing fails, or no reply
arrives within 120 seconds. A timeout does not cancel an already requested pass. Both the CLI and
daemon must support tick; restart the daemon after upgrading the binary.

If the control socket cannot start or stops accepting connections, the daemon logs the failure and
continues its timed passes. Fix the socket problem and restart the daemon to restore on-demand
ticks.

Public /run/governor/state.json and governor status --json include "schemaVersion": 1. Hook
snapshots use the same version. This describes the public format, not the persisted credit estimate
or the resource report's separate schema field. Consumers should reject unsupported versions and
tolerate additional fields within a supported version. Older releases omit the field; the built-in
reader accepts that legacy format during upgrades.

v1.0.0 keeps schemaVersion: 1 and changes three fields under credits:

credits.margin still holds what the guest's own count charges, mul × busy cores + add, and
credits.law.floor is now 0.1.

Choose a fallback quota

The default fallback_cpu_percent is 20, meaning 0.2 of one vCPU, not 20% of the whole VPS.
On an eight-vCPU box, 150 means 1.5 cores shared by everyone in user.slice, including SSH and
enrolled services. A larger fallback can keep those services responsive while Governor is stopped.
It also gives up some credit protection.

Add the setting to the existing /etc/governor/config.json, keeping its other fields:

{ "fallback_cpu_percent": 150 }

Validate and restart Governor:

sudo governor validate-config
sudo systemctl restart governor.service

Runtime fallback calls read the current configuration. Re-run the matching-version installer to copy
the setting into the early-boot quota too; installation and upgrades keep existing configuration.
Missing fields use the default. Values must be whole numbers from 20 to the VM's vCPU count
times 100. Invalid or unreadable configuration uses the emergency default of 20 when applying a
fallback.

Choose the value from the verified baseline, the CPU available while Hostinger limits the VM,
and the peak CPU used by services outside user.slice. Under an aggregate host limit, leave enough
room that:

fallback cores + peak outside cores + headroom < min(baseline cores, host-limit cores)

For example, with the configured KVM 8 baseline of 4.8 cores, an aggregate limit of 2.4 cores, 0.4
cores outside the slice and 0.2 cores of headroom, a 150% fallback totals 2.1 cores. That fits those
assumptions. It is not a guarantee if Hostinger applies per-vCPU limits, the baseline differs,
outside usage spikes, or billing overhead exceeds the allowance. Keep 20 if those assumptions are
unknown. Outside services alone can prevent recovery; the slice quota cannot constrain them.

This setting applies during service startup and after stopping or crashing. A stale status file
alone does not activate a watchdog or change the cap. It also does not change the 20% quota used
for detection probes or the governor's recovery floor.

Hook delivery

Place notification executables in /etc/governor/hooks.d. Hooks run as the governor user, with
GOVERNOR_EVENT naming limit-start, limit-end or calibration, and the captured public state
on stdin. CPU quota control happens first. Delivery runs in the background, preserving event order
and alphabetical hook order, so a slow notification destination cannot delay the control loop.

limit-start fires when the governor detects a limit and limit-end when a lift test passes.
governor limit on and governor limit off fire neither. calibration fires when a credit limit
raises the pad. limit-classified, rules-mismatch and readings-invalid no longer fire. Stale
readings have no hook; watch credits.staleSince in the public state. See
the credit estimate.

Each hook has its own deadline. hook_timeout_seconds defaults to 60 and accepts 1 to 300 seconds.
It includes startup and writing stdin, even if the hook never reads it or ignores SIGTERM. Governor
kills the hook's ordinary process group at the deadline, cleans up children left behind when the
hook exits, and cancels active and queued work on shutdown. Hooks should finish their own children
before exiting, not launch detached background jobs.

Delivery is best-effort, not durable: at most 16 events wait behind the active event and each
payload is limited to 1 MiB. Full queues or oversized payloads are dropped with a log message. Hook
failures are logged without copying their stdout or stderr into the daemon's logs. Notification
failure never changes credit accounting or job admission. Use a separate durable delivery process if
you need guaranteed notifications. See examples/hooks.d for a starting point.

Govern service workloads

All login sessions inherit the shared quota. Docker containers and system services need explicit
placement. coverage.outsideCores in governor status --json shows measured CPU outside the slice;
coverage.recoveryBlocked warns when those workloads alone prevent recovery. The estimate includes
that consumption, but the governor cannot reduce an unrelated cgroup's demand.

For an individual cron job, including root's cron, run:

governor exec -- /path/to/job arg1 arg2

This checks that the governor is accepting work and starts a systemd scope under the managed quota.
It exits 3 without running the command if work is not accepted. For cron jobs that should wait
instead of skipping an attempt, use a bounded wait, up to 86400 seconds:

governor exec --wait 3600 -- /path/to/job arg1 arg2

Waiting does not reserve credits or guarantee a later run. Check exit codes and use a queue or retry
policy if every job must eventually run. The wait uses a monotonic deadline.

Root uses the system manager; other users use their user manager, which must be available. Scopes
use CPUWeight=1 so batch competes at low priority with sibling services. For an agent with its own
login user, the containing user slice still competes with web services under user.slice. Set its
weight explicitly, replacing <uid> with that user's numeric UID:

sudo systemctl set-property user-<uid>.slice CPUWeight=1

Weights affect siblings under contention; they are not CPU reservations. Enrollment alone does not
prioritize services over every login. Keep latency-sensitive services outside the slice if they must
avoid probe cuts, but account for their uncapped CPU use. For a service or the service activated by
a systemd timer:

sudo governor enroll-service heavy-job.service
sudo systemctl restart heavy-job.service

Enrollment writes a Slice=user.slice drop-in and reloads systemd. The explicit restart applies it.
To place every cron child under the quota, enroll cron.service the same way. Existing processes
keep their placement until restarted. Check it with
systemctl show heavy-job.service -p ControlGroup.

For rootful Docker:

sudo governor configure-docker
sudo systemctl restart docker

The command preserves other daemon settings, validates the proposed config with dockerd, saves the
original in /etc/docker/daemon.json.governor-backup, and sets the default cgroup parent to
user.slice with the systemd cgroup driver. Existing containers must be recreated. Per-container or
Compose cgroup_parent overrides must also point to user.slice; daemon flags must not conflict
with the JSON settings. Check a running container's /proc/<pid>/cgroup to verify placement. These
settings follow
Docker's cgroup-parent documentation.

Resource reports

governor report exposes credits, reserve-aware burst runway, earning rate, quota and recovery,
per-user CPU, and CPU, steal, memory and load charts. Choose readable text, an HTML table-and-chart
layout, or structured JSON for your own integration:

governor report
governor report 24 --format html
governor report --format json

All formats are built in and read-only. No extra runtime, messaging account or Hostinger token is
needed. Connect the output to Slack, Telegram, a web dashboard, or whatever you use. Delivery and
command handling stay in your integration. The report guide covers the
data format and editable layout, including a browser preview template.

For development, use the Deno version in .tool-versions, which CI and release builds install.
deno task check runs formatting, lint, type checks and tests, and stops under any other Deno
version. Installer migration tests also run with
python3 -m unittest discover -s test -p '*_test.py'. Release binaries need neither runtime
installed to produce resource reports.

Baseline verification

The directly fetched Hostinger article states a 60% baseline and matching capacities, but still
contains a 30% formula. Search-index copies have also shown different per-plan tables. The default
follows the directly fetched main table; it has not been confirmed against your VPS's billing. Ask
support to confirm your plan's rules. Under a truly idle workload, the published model predicts
recovery in 24 minutes at 60%, or 84 minutes at 30%. Each completed episode logs a
recovery observation with elapsed time, the configured idle minimum, a recovery prediction based
on observed charged CPU and conservative earning pauses, the baseline share, and whether a lift test
confirmed the limit. Read it with journalctl -u governor.service. While a limit lasts,
governor report shows how long it has run, the earliest idle recovery under the configured
baseline and the estimated earning pauses. Compare repeated real episodes with support's answer; the
guest cannot prove the host's earning pauses, billing, or exact lift time. Lift-test backoff can
also delay noticing a lift. The governor does not change the baseline automatically. Do not
intentionally exhaust a production VPS to measure it.

If support or measurements establish a 30% baseline, set "baseline_share": 0.3 in
/etc/governor/config.json, run sudo governor validate-config, then restart governor.service.
Changing the baseline resets the estimate. Capacity and recovery thresholds use the configured
baseline too.

The governor keeps:

v0.3 also kept history.json and history.log there. v1.0.0 neither reads nor writes them, and you
can delete them.

Rule changes

Hostinger can change its CPU credit rules. The watcher compares article content, not the relative
"Updated ... ago" label, which can be stale in cached HTML. It records an absolute modification
timestamp when one is available.

rules/hostinger-cpu-credits.json records the version this code was reviewed against: a fingerprint
of the article text, the numbers the code depends on, and the sentences they come from. It does not
copy the article.

The Rules watch workflow fetches the article every four hours. When the text differs from the
record, it opens an issue labelled hostinger-rules with the reviewed and live numbers, numbers it
can no longer find, contradictions inside the article, the new or changed lines, and whether the
code still agrees. Each version is reported once: a version counts as reported only when its exact
marker appears in an issue or comment from the workflow or someone with verified write access, so an
outside comment cannot silence an alert. Closing an issue without accepting it silences that
version. The page is read in one step without the GitHub token, and the issue is written in another
that never sees the page. Until a record exists, the first run opens an issue showing what the
watcher reads from the live page.

To accept a version, update src/plans.ts if the rules changed, then record the article and commit:

deno task rules:accept
git diff rules/

rules:accept refuses a record missing any essential number (baseline, capacity formula, lift and
earning-pause thresholds, and the table row and limit for each plan) or one the code disagrees with.
deno task check enforces the same on the committed record. It covers the plan parameters in
src/plans.ts and EARNING_PAUSE_SHARE, which the simulator models; the rest of the article,
including the leftover 0.30 earning formula and the FAQ's 20% limit, is reported for review but not
enforced. deno task rules:check compares without writing.

The daemon never reads the article. A help-center page is not a billing API: it contradicts itself
today, it can lag or lead real billing changes, and a governor that obeyed it would let anyone who
can edit or spoof that page decide how hard your VPS runs. Rule changes reach the governor as
reviewed releases; recovery observations are supporting evidence, not a trigger.

GitHub can delay or skip scheduled runs, and disables schedules in public repositories after 60 days
without activity. To hear about a watcher that stopped, create a check with a dead man's switch such
as healthchecks.io (period 4 hours, grace 12 hours) and save its ping URL
as the repository secret RULES_WATCH_HEARTBEAT_URL. Every run pings it. Failed runs, unreadable
pages and missing essential numbers ping /fail, even if an issue was successfully posted. The
service also alerts when pings stop. Without the secret, no heartbeat requests are sent.

Emergency access

The default fallback is a shared 20% quota of one CPU; fallback_cpu_percent can change it.
Repeated crashes can leave SSH sessions and enrolled services with very little CPU. From a root
shell or the provider console:

sudo systemctl stop governor.service
sudo systemctl set-property --runtime user.slice CPUQuota=

This removes credit protection until the daemon restarts. Fix the configuration or service failure,
then run sudo systemctl start governor.service to reapply protection. Raising the fallback is not
universally safe when the host limits individual vCPUs.

Simulations

Run repository checks with the Deno version in .tool-versions, which CI installs. Every task
except the rules watcher's stops under any other version:

deno task check
python3 -m unittest discover -s test -p '*_test.py'

The test task needs unrestricted --allow-run because Deno requires that permission to signal
negative PIDs for hook process-group cleanup. Tests also invoke Bash and the Deno CLI. This does not
widen the daemon's sudo grants. Child CLI tests use explicit permissions, not unrestricted
deno eval. Writable test data stays in ignored test/.tmp directories and each test removes its
own directory. Tracked test/fixtures remains read-only. The Linux smoke test only runs on
disposable GitHub-hosted runners. deno task smoke:linux <binary> builds a JIT-enabled copy of the
current source in its own temporary directory and removes it on exit. This fixture verifies
installation and CPU control, then must abort under MDWE as a negative control. The jitless binary
must run version, status --json and report 1 under MDWE as root and a regular user. On systemd
255+, the smoke test also applies the daemon drop-in and checks work admission before broker tests.

Runner Architecture Broker coverage
Ubuntu 22.04 x86_64 Skipped; systemd 249 lacks encrypted credentials.
Ubuntu 24.04 x86_64 and ARM64 Full localhost SSH, sudo I/O logging, credential and systemd flow with an offline API fixture and dummy token.
Ubuntu 26.04 x86_64 Production sudo grant with sudo-rs; full broker integration is not run.

The release workflow also runs on pull requests. It builds both Linux packages and runs the full
Ubuntu 24.04 x86_64 smoke test before publication. Only a v* tag can execute the publish step; the
other CI matrix jobs are separate checks.

The supplied second-by-second simulator runs the real governor against seeded workloads:

deno task sim                                 # 15 week-long scenarios, seed 1
deno task sim "hidden overhead" 5 --episodes  # scenarios by name, seeds 1 to 5
deno task sim --detection                     # 25 limit-detection scenarios
deno task sim --studies S3                    # one eight-week study
deno task sim:check                           # all 23 studies against docs/study-results.json
deno task sim:record                          # rewrite that record

The week-long scenarios model neighbour steal, billing overhead, stops, outside workloads, alternate
baselines, and aggregate or per-vCPU limits. Scheduling and host earning windows are assumptions.
The original model freezes a growing bank while pressing; the paused earning debits CPU scenarios
instead subtract CPU consumption during pauses. used_pct compares billed CPU with the theoretical
baseline, including paused time, not actual earned-credit utilization. The 23 studies in
test/studies.ts each change one condition over eight weeks: a billing gap, a meter jump, a broken
feed, an API outage, a hole in the readings, a reboot, lost state, a wrong clock. They run in under
two minutes in sequence.

Study results has the numbers. No model here validates live billing.

Limits

Built for my own servers and shared as is. Issues and PRs are welcome but not promised a reply. MIT
license.