Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

yuneta_agent22

A minimal second agent — a redundant remote entry point for the control center. Every node runs it next to the primary yuneta_agent. The init scripts deliberately leave agent22 alive when stopping the node, so a remote operator is never stranded if the primary agent is down or being upgraded (the two agents upgrade each other, never both at once).

It runs in its own systemd unit, yuneta_agent22.service: sudo systemctl restart yuneta_agent22 (or sudo service yuneta_agent22 restart) restarts it alone. How the two units are started, stopped and deployed is in yuneta_agent: starting and stopping it.

Like the primary agent, agent22 dials the control center when the node has an owner, but on its own endpoint — __output_url__ defaults to yunetacontrol.ovh:1989 (port 1989, vs the primary agent’s …com:1988):

tcps://<machine>.<node_owner>.yunetacontrol.ovh:1989

It trusts only the control center’s own certificate, as the primary agent does (see controlcenter). Up to 7.30.3 the port was 1995.

Remote consoles (PTY)

agent22’s distinctive feature is a remote console facility built on a PTY (C_PTY, forkpty). The control center can open an interactive console on the node and stream keystrokes/output to it:

CommandParametersDescription
open-consolename, …Open a PTY console
write-ttyname, content64Write (base64) data to a console’s tty
list-consoles—List open consoles
close-consolenameClose a console
upgrade-agentcontent64Replace the binary of the main agent and restart it (Upgrading the main agent)
install-packageurl, sha256Install a yuneta-agent package on a package node (Installing a package)
install-package-statuslinesHow the last install-package went
help—Command help

A write-tty that cannot be written is refused, and the link to the control center stays up:

write-tty name=nosuch content64=YQ==      -> EV_TTY_CLOSE {"name": "nosuch"}
write-tty name=__yuno__ content64=YQ==    -> EV_TTY_CLOSE {"name": "__yuno__"}

Up to 7.30.26 a console not found and a missing content64 were an ERROR and an EV_DROP of the whole link to the control center. A service that is no console was sent the write: __yuno__ answered “Event NOT DEFINED in state” with a stack, and agent22 wrote to itself. The primary agent does the same since this version (see yuneta_agent).

A control center that does not read

A console has flow control, as the primary agent’s (see yuneta_agent, Consoles). When the link to the control center has console_pause_tx_queue messages or more waiting (default 256, and a message carries up to 1 KB of output, about 2 KB on the wire), or console_pause_tx_bytes bytes or more (default 1048576, the link’s cur_tx_bytes), the console stops reading its terminal: its process waits on its write, and nothing is lost. It reads again when the link has sent everything, or when the link drops its connection (what it had waiting goes with it). The link is the only route of agent22’s consoles, and the one that opened them, so it freezes nobody else: a console waits for it as long as the control center is away, with no deadline.

console_max_tx_queue (default 8192) and console_max_tx_bytes (default 33554432, 32 MB) stay as a hard bound whatever paused the console (they matter only with flow control off): over either the console is closed, with ONE WARNING “console output not taken by its session, console closed for it” (with tx_queue and tx_bytes). 0 turns any of the four attributes off:

{
    "global": {
        "agent22.console_pause_tx_queue": 256,
        "agent22.console_pause_tx_bytes": 1048576,
        "agent22.console_max_tx_queue": 8192,
        "agent22.console_max_tx_bytes": 33554432
    }
}

The route of a console keeps only what routes its events back of the request that opened it: the stack of its hops (ievent_gate_stack) and its __msg_type__. Any other key of the request’s __md_iev__ (a marker of the control center) does not return with the console’s events. Before the fix the whole __md_iev__ was kept and copied into every chunk of output, and the bounds counted messages only: a request padded with 1 MB made every chunk of 1 KB a message of 1 MB, and 256 of them took agent22 from 11 to 264 MB.

Up to 7.30.26 there was neither: a control center that did not read its link grew agent22 with all the output of its consoles (some 50 MB/s with yes) until it aborted. Test: tests/c/c_agent22_write_tty (8 s of yes with the link not read: agent22 stays flat, and the console goes on when the link is read again. The same with the request padded with 1 MB: under +25 MB, and frames of output of 2 KB when the padding is not in a hop).

Upgrading the main agent

agent22 replaces the binary of the main agent and restarts it (7.31.27+). Send the command through the control center to the agent22 of the node:

ycommand --url=wss://<control center>:1997 <login options> -w 120 \
  -c 'command-agent agent_id=<node> cmd2agent="upgrade-agent content64=$$(/yuneta/agent/yuneta_agent)"'

ycommand reads the file and sends it in base64. Give -w enough seconds for the binary to arrive, or the answer is lost. A 36 MB binary takes some 20 seconds.

ParameterTypeDescription
content64stringThe new yuneta_agent binary in base64.

The command does these steps:

  1. It writes the binary as /yuneta/agent/upgrade/yuneta_agent.

  2. It runs the binary with --print-role. If the role is not yuneta_agent, it deletes the binary and refuses the command.

  3. It copies the binary that runs from /proc/<MainPID>/exe of yuneta_agent.service to /yuneta/agent/upgrade/running/yuneta_agent. It reads the old version from that copy (7.31.28+).

  4. It keeps that copy as yuneta_agent.bak-pre-<new version>. If that backup is already there, it stays as it is.

  5. It renames the new binary over /yuneta/agent/yuneta_agent.

  6. It restarts yuneta_agent.service with sudo -n systemctl restart --no-block.

The answer comes before the main agent is back:

yuneta_agent22^deploycenter: yuneta_agent 7.31.26 -> 7.31.27, the one that
runs kept as /yuneta/agent/yuneta_agent.bak-pre-7.31.27; restart of
yuneta_agent.service queued

The data of the answer has old_version, old_from (running or disk), new_version, backup, backup_was_there and restart.

A build on the node replaces /yuneta/agent/yuneta_agent while the agent runs. So the file on disk can be the new binary already, and only /proc/<MainPID>/exe is the binary that runs. Up to 7.31.27 the command kept the file on disk and read the old version from it. After a build, the backup was the new binary, and the answer said 7.31.27 -> 7.31.27.

If the main agent runs outside its unit, or the copy fails, the command keeps the file on disk as before (a hard link). It logs a WARNING, and the answer says the one on disk (NOT the one that runs: see the log).

The yunos of the node do not restart. The unit stops only the main agent.

Each step has a reason:

The command refuses a node that runs from a package. It uses the test of the preinst of the package: /yuneta/development/yunetas has kernel/ and .git. On a package node, the agent comes in the package. Then the package database tells the truth about the node.

The permission is upgrade-agent. The role root of the configuration of agent22 has every permission.

Before 7.31.27, the answer to a large content64 did not arrive. Each answer carried the whole command line back, and the control center dropped the client (see msg_iev_stack_command_line()).

Installing a package

On a package node, the agent comes in the yuneta-agent package. agent22 downloads the package and installs it (7.31.27+). Send the commands through the control center to the agent22 of the node:

# 1. Read the sha256 of the package from the SHA256SUMS of its release:
#    the line of that file name (a release can hold -1 and -2 of a package).
curl -fsSL https://github.com/artgins/yunetas/releases/download/7.31.27/SHA256SUMS \
  | awk -v f=yuneta-agent-7.31.27-1-amd64.deb '$2 == f {print $1}'

# 2. Start the install.
ycommand --url=wss://<control center>:1997 <login options> -w 20 \
  -c 'command-agent agent_id=<node> cmd2agent="install-package url=https://github.com/artgins/yunetas/releases/download/7.31.27/yuneta-agent-7.31.27-1-amd64.deb sha256=<sha256>"'

# 3. When agent22 is back in list-agents, read the result.
ycommand --url=wss://<control center>:1997 <login options> -w 20 \
  -c 'command-agent agent_id=<node> cmd2agent="install-package-status"'

A node on Rocky or Red Hat takes the .rpm asset of the same release, and the line of SHA256SUMS for that .rpm file. Take the line by its whole file name, not by its end: after a repackage, the release has a -1 and a -2 of each package, and SHA256SUMS has a line for each. Each release from 7.31.27 on has SHA256SUMS. For an older release, download the package and run sha256sum on it.

ParameterTypeDescription
urlstringThe https:// URL of the .deb or .rpm of yuneta-agent.
sha256stringThe sha256 of the package, 64 hex digits.
linesintegerinstall-package-status only: the lines of the journal to show (default 40).

The answer of install-package comes at once, with the name of the unit that installs the package:

yuneta_agent22^<node>: installing yuneta-agent-7.31.27-1-amd64.deb in the unit
yuneta-install-package-20261120211600. Its postinst restarts the main agent
and then this one: ask install-package-status when this agent is back

install-package-status gives four things:

The root part of the install is a program of the package, /usr/libexec/yuneta/install-package. Root owns it, so yuneta cannot change it. The install has these steps:

  1. agent22 writes the URL and the sha256 in /yuneta/agent/install-package/. It writes only data.

  2. agent22 runs sudo -n /usr/libexec/yuneta/install-package start.

  3. The program checks the data again. It refuses a file that is a link. It copies the data to /var/lib/yuneta/install-package/, a directory of root, and starts the transient unit yuneta-install-package-<UTC time> with systemd-run. It tells agent22 the name of the unit.

  4. The unit runs /usr/libexec/yuneta/install-package run. It downloads the package into /var/lib/yuneta/install-package/download.<random>/ with curl, https only, also on each redirect. The download stops at 1 GiB, and also when the server sends less than 1 KB/s for 2 minutes. After a transient error (a timeout, an HTTP 5xx), curl tries 3 more times.

  5. If the sha256 of the download is not the one given, the unit deletes the download and stops. Nothing is installed.

  6. If the download is not the package yuneta-agent (dpkg-deb -f or rpm -qp), the unit deletes it and stops.

  7. On Debian, the unit runs apt-get update. Then it installs the package with apt-get install -y (and --force-confold, so the configurations of the node stay). On Red Hat, it runs dnf install -y. Then it deletes the download and writes result in /var/lib/yuneta/install-package/.

  8. The postinst of the package restarts the main agent and then agent22.

Each step has a reason:

install-package refuses these cases. Nothing is written and nothing is started:

The permission of both commands is install-package. It is equivalent to root: the package is the one of the URL and the sha256 that the operator gives, and the scripts of the package run as root. The permission upgrade-agent is equivalent to root too, where yuneta has sudo.

Variant

The same sources also build yuneta_agent44 (main44.c), a second flavour of the minimal agent.